Full Stack Development 1
Full Stack Development 1
UNIT - I
Web Development Basics: Web development Basics - HTML & Web servers Shell - UNIX CLI Version
control - Git & Github HTML, CSS
UNIT - II
Frontend Development: Javascript basics OOPS Aspects of JavaScript Memory usage and Functions in JS
AJAX for data exchange with server jQuery Framework jQuery events, UI components etc. JSON data
format.
UNIT - III
REACT JS: Introduction to React React Router and Single Page Applications React Forms, Flow
Architecture and Introduction to Redux More Redux and Client-Server Communication
UNIT - IV
Java Web Development: JAVA PROGRAMMING BASICS, Model View Controller (MVC) Pattern MVC
Architecture using Spring RESTful API using Spring Framework Building an application using Maven
UNIT - V
Databases & Deployment: Relational schemas and normalization Structured Query Language (SQL) Data
persistence using Spring JDBC Agile development principles and deploying application in Cloud
FULL STACK DEVELOPMENT
UNIT - I
Web Development Basics: Web development Basics - HTML & Web servers Shell -
UNIX CLI Version control - Git & Github HTML, CSS
HTML is an acronym which stands for Hyper Text Markup Language which is
used for creating web pages and web applications. Let's see what is meant
by Hypertext Markup Language, and Web page.
Hyper Text: HyperText simply means "Text within Text." A text has a link within
it, is a hypertext. Whenever you click on a link which brings you to a new
webpage, you have clicked on a hypertext. HyperText is a way to link two
or more web pages (HTML documents) with each other.
Hence, HTML is a markup language which is used for creating attractive web
pages with the help of styling, and which looks in a nice format on a web
browser. An HTML document is made of many HTML tags and each
HTML tag contains different content.
<head>
<title>Web page title</title>
</head>
<body>
<h1>Write Your First Heading</h1>
<p>Write Your First Paragraph.</p>
</body>
</html>
1 |Page
FULL STACK DEVELOPMENT
<html > :This tag informs the browser that it is an HTML document. Text
between html tag describes the web document. It is a container for all
other elements of HTML except <!DOCTYPE>
<head>: It should be the first element inside the <html> element, which
contains the metadata(information about the document). It must be closed
before the body tag opens.
<title>: As its name suggested, it is used to add title of that HTML page
which appears at the top of the browser window. It must be placed inside the
head tag and should close immediately. (Optional)
<body> : Text between body tag describes the body content of the page
that is visible to the end user. This tag contains the main content of the HTML
document.
<h1> : Text between <h1> tag describes the first level heading of the webpage.
<p> : Text between <p> tag describes the paragraph of the webpage.
HTML Tags
HTML tags are like keywords which defines that how web browser will
format and display the content. With the help of tags, a web browser can
distinguish between an HTML content and a simple content. HTML tags
contain three main parts: opening tag, content and closing tag. But some
HTML tags are unclosed tags.
When a web browser reads an HTML document, browser reads it from top to
bottom and left to right. HTML tags are used to create HTML documents
and render their properties. Each HTML tags have different properties.
o All HTML tags must enclosed within < > these brackets.
Syntax
HTML Elements
An HTML file is made of elements. These elements are responsible for
creating web pages and define content in that webpage. An element in HTML
usually consist of a start tag <tag name>, close tag </tag name> and
content inserted between them. Technically, an element is a collection of
start tag, attributes, end tag, content between them.
Example
<!DOCTYPE html>
<html>
<head>
<title>WebPage</title>
</head>
<body>
<h1>This is my first web page</h1>
<h2> How it looks?</h2>
<p>It looks Nice!!!!!</p>
</body>
</html>
CAREER ADVANCEMENT CELL 3 |Pag
e
FULL STACK DEVELOPMENT
HTML Heading
A HTML heading or HTML h tag can be defined as a title or a subtitle which
you want to display on the webpage. When you place the text within the
heading tags
<h1>.........</h1>, it is displayed on the browser in the bold format and size of the
text depends on the number of heading.
There are six different HTML headings which are defined with the <h1> to
<h6> tags, from highest level h1 (main heading) to the least level h6
(least important heading).
h1 is the largest heading tag and h6 is the smallest one. So h1 is used for
most important heading and h6 is used for least important.
Note: The main keyword of the whole content of a webpage should be display by
h1 heading tag.
Output:
Heading no. 1
Heading no. 2
Heading no. 3
Heading no. 4
Heading no. 5
Heading no. 6
Example:
<!DOCTYPE html>
<html>
<head>
<title>Heading elements</title>
</head>
<body>
<h1>This is main heading of page. </h1>
</html>
CAREER ADVANCEMENT CELL 5 |Pag
e
FULL STACK DEVELOPMENT
Output:
HTML Anchor
The HTML anchor tag defines a hyperlink that links one page to another page.
It can create hyperlink to other web page as well as files, location, or any
URL. The "href" attribute is the most important attribute of the HTML a
tag. and which links to destination page or URL.
The href attribute is used to define the address of the file to be linked. In
other words, it points out the destination page.
Example:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
Output:
HTML Image
HTML img tag is used to display image on the web page. HTML img tag is an
empty tag that contains attributes only, closing tags are not used in HTML
image element.
Output:
CAREER ADVANCEMENT CELL 7 |Pag
e
FULL STACK DEVELOPMENT
1) src
2) alt
The alt attribute defines an alternate text for the image, if it can't be
displayed. The value of the alt attribute describe the image in words. The alt
attribute is considered good for SEO prospective.
3) width
4) height
It h3 the height of the image. The HTML height attribute also supports iframe,
image and object elements. It is not recommended now. You should apply CSS
in place of height attribute.
Use of height and width attribute with img tag
You have learnt about how to insert an image in your web page, now if we
want to give some height and width to display image according to our
requirement, then we can set it with height and width attributes of image.
Example:
<img src ="[Link]" height ="180" width ="300" alt ="animal image">
Output:
Note: Always try to insert the image with height and width, else it may flicker while
displaying on webpage.
We can use alt attribute with tag. It will display an alternative text in case if
image cannot be displayed on browser. Following is the example for alt attribute:
1. <img src ="[Link]" height ="180" width ="300" alt ="animal image">
Output:
HTML Table
HTML table tag is used to display data in tabular form (row * column). There
can be many columns in a row.
We can create a table to display data in tabular form, using <table> element,
with the help of <tr> , <td>, and <th> elements.
In Each table, table row is defined by <tr> tag, table header is defined by <th>,
and table data is defined by <td> tags.
HTML tables are used to manage the layout of the page e.g. header
section, navigation bar, body content, footer section etc. But it is
recommended to use div tag over table to manage the layout of the page .
<html>
<head>
<title></title>
</head>
<body>
<table border="5">
<tr><th>First_Name</th><th>Last_Name</th><th>Marks</th></tr>
<tr><td>Sonoo</td><td>Jaiswal</td><td>60</td></tr>
<tr><td>James</td><td>William</td><td>80</td></tr>
<tr><td>Swati</td><td>Sironi</td><td>82</td></tr>
<tr><td>Chetna</td><td>Singh</td><td>72</td></tr>
</table>
</body>
</html>
Output:
HTML Lists
HTML Lists are used to specify lists of information. All lists may contain one
or more list elements. There are three different types of HTML lists:
<!DOCTYPE>
<html>
<body>
<ol>
<li>Aries</li>
<li>Bingo</li>
<li>Leo</li>
<li>Oracle</li>
</ol>
</body>
</html>
Output:
CAREER ADVANCEMENT CELL 11 | P a g
e
FULL STACK DEVELOPMENT
o disc
o circle
o square
o none
1. <ul>
2. <li>HTML</li>
3. <li>Java</li>
4. <li>JavaScript</li>
5. <li>SQL</li>
6. </ul>
Test it Now
Output:
o HTML
o Java
o JavaScript
o SQL
ul type="circle"
1. <ul type ="circle" >
2. <li>HTML</li>
3. <li>Java</li>
4. <li>JavaScript</li>
5. <li>SQL</li>
6. </ul>
Test it Now
Output:
o HTML
o Java
o JavaScript
o SQL
ul type="square"
<ul type ="square" >
<li>HTML</li>
<li>Java</li>
<li>JavaScript</li>
<li>SQL</li>
</ul>
Output:
o HTML
o Java
o JavaScript
o SQL
HTML Form
An HTML form is a section of a document which contains controls such as text
fields, password fields, checkboxes, radio buttons, submit button, menus etc.
An HTML form facilitates the user to enter data that is to be sent to the
server for processing such as name, email address, password, phone number,
etc. .
CAREER ADVANCEMENT CELL 13 | P a g
e
FULL STACK DEVELOPMENT
For example: If a user want to purchase some items on internet, he/she must
fill the form such as shipping address and credit/debit card details so that item
can be sent to the given address.
</form>
<form>
First Name: <input type ="text" name ="firstname"/> <br/>
Last Name: <input type="text" name ="lastname"/> <br/>
</form>
Example:
<!DOCTYPE html>
<html>
<head>
<title>Form in HTML</title>
</head>
<body>
<form>
Enter your address:<br>
<textarea rows ="2" cols="20"></textarea>
</form>
</body>
</html>
Output:
If you click on the label tag, it will focus on the text control. To do so, you
need to have for attribute in label tag that must be same as id attribute of input
tag.
NOTE: It is good to use <label> tag with form, although it is optional but if you will
use it, then it will provide a focus when you tap or click on label tag. It is more
worthy with touchscreens.
<form>
<label for="firstname">First Name: </label> <br/>
</form>
Output:
1. <form>
2. <label for="password">Password: </label>
4. </form>
Output:
The email field in new in HTML 5. It validates the text for correct email
address. You must use @ and . in this field.
<form>
<label for="email">Email: </label>
The radio button is used to select one option from multiple options. It is
used for selection of gender, quiz questions etc.
If you use one name for all the radio buttons, only one radio button can be
selected at a time.
Using radio buttons for multiple options, you can only choose a single option
at a time.
<form>
<label for="gender">Gender: </label>
Checkbox Control
The checkbox control is used to check multiple options from given checkboxes.
<form>
Hobby:<br>
Note: These are similar to radio button except it can choose multiple options at a
time and radio button can select one button at a time, and its display.
Output:
CAREER ADVANCEMENT CELL 18 | P a g
e
FULL STACK DEVELOPMENT
Syntax:
The value attribute can be anything which we write on button on web page.
Example:
<form>
<label for="name">Enter name</label><br>
<input type ="text" id ="name" name ="name"><br>
<label for="pass">Enter Password</label><br>
<input type ="Password" id ="pass" name ="pass"><br>
<input type ="submit" value ="submit" >
</form>
Output:
CAREER ADVANCEMENT CELL 19 | P a g
e
FULL STACK DEVELOPMENT
Example:
<form>
<fieldset>
<legend>User Information:</legend>
Output:
<!DOCTYPE html>
<html>
<head>
<title>Form in HTML</title>
</head>
<body>
<h2>Registration form</h2>
<form>
<fieldset>
<legend>User personal information</legend>
<label>Enter your full name</label><br>
<input type="text" name ="name"><br>
</html>
Output:
<tr>
<tr>
22 | P a g
FULL STACK DEVELOPMENT
="width:160px"/></td>
</tr>
<tr>
<td
><input type="email" name ="email" value="" id ="register_email" style
="width:160px"/
></td>
</tr>
<tr>
<td>
<tr>
</table>
</form>
CSS is used to apply the style in the web page which is made up of HTML
elements. It describes the look of the webpage.
o Inline CSS: Define CSS properties using style attribute in the HTML elements.
o Internal or Embedded CSS: Define CSS using <style> tag in <head> section.
o External CSS: Define all CSS property in a separate .css file, and then include
the file with HTML file using tag in section.
Inline CSS:
Inline CSS is used to apply CSS in a single element. It can apply style uniquely
in each element.
To apply inline CSS, you need to use style attribute within HTML element. We
can use as many properties as we want, but each property should be
separated by a semicolon (;).
Example:
CAREER
ADVANCEMENT
<html>
<head>
<title></title>
</head>
<body>
<h3 style="color: red;
24 | P a g
FULL STACK DEVELOPMENT
font-style: italic;
text-align: center;
font-size: 50px;
Output:
We can use internal CSS to apply a style for a single HTML page.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
p{font-size: 20px;}
/*Internal CSS using class name*/
.blue{color: blue;}
.red{color: red;}
CAREER .green{color: green;}
ADVANCEMENT
</style>
</head>
<body>
25 | P a g
FULL STACK DEVELOPMENT
External CSS:
An external CSS contains a separate CSS file which only contains style code
using the class name, id name, tag name, etc. We can use this CSS file in
any HTML file by including it in HTML file using <link> tag.
If we have multiple HTML pages for an application and which use similar
CSS, then we can use external CSS.
o Create a CSS file and save it using the .css extension (This file only will only
contain the styling code.)
o Link the CSS file in your HTML file using tag in header section of HTML document.
Example:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type ="text/css" href="[Link]">
</head>
<body>
CSS file:
body{
background-color:lavender;
text-align: center;
}
h2{
font-style: italic;
size: 30px;
color: #f08080;
}
p{
font-size: 20px;
}
.blue{
color: blue;
}
.red{
color: red;
}
.green{
color: green;
}
WEB SERVER
A web server is a computer that stores web server software and a website's component files
(for example, HTML documents, images, CSS stylesheets, and JavaScript files). A web
server connects to the Internet and supports physical data interchange with other devices
connected to the web.
A web server includes several parts that control how web users access hosted files. At a
minimum, this is an HTTP server. An HTTP server is software that understands URLs (web
addresses) and HTTP (the protocol your browser uses to view webpages). An HTTP server
can be accessed through the domain names of the websites it stores, and it delivers the
At the most basic level, whenever a browser needs a file that is hosted on a web server, the
browser requests the file via HTTP. When the request reaches the correct (hardware) web
server, the (software) HTTP server accepts the request, finds the requested document, and
sends it back to the browser, also through HTTP. (If the server doesn't find the requested
document, it returns a 404 response instead.)
A static web server, or stack, consists of a computer (hardware) with an HTTP server
(software). We call it "static" because the server sends its hosted files as-is to your browser.
A dynamic web server consists of a static web server plus extra software, most commonly an
application server and a database. We call it "dynamic" because the application server
updates the hosted files before sending content to your browser via the HTTP server.
For example, to produce the final webpages you see in the browser, the application server
might fill an HTML template with content from a database. Sites like MDN or Wikipedia
have thousands of webpages. Typically, these kinds of sites are composed of only a few
HTML templates and a giant database, rather than thousands of static HTML documents.
This setup makes it easier to maintain and deliver the content.
It is used for:
CAREER 28 | P a g
ADVANCEMENT
FULL STACK DEVELOPMENT
Github
GitHub is a code hosting platform for version control and collaboration. It
lets you and others work together on projects from anywhere.
This tutorial teaches you GitHub essentials like repositories, branches,
commits, and pull requests. You'll create your own Hello World repository
and learn GitHub's pull request workflow, a popular way to create and
review code.
In this quickstart guide, you will:
. Create and use a repository
. Start and manage a new branch
. Make changes to a file and push them to GitHub as commits
. Open and merge a pull request
To complete this tutorial, you need a GitHub account and Internet access.
You don't need to know how to code, use the command line, or install Git
(the version control software that GitHub is built on). If you have a
question about any of the expressions used in this guide, head on over to
the glossary to find out more about our terminology.
Creating a repository
A repository is usually used to organize a single project. Repositories can
contain folders and files, images, videos, spreadsheets, and data sets --
anything your project needs. Often, repositories include a README file, a
file with information about your project. README files are written in the
plain text Markdown language. You can use this cheat sheet to get started
with Markdown syntax. GitHub lets you add a README file at the same
time you create your new repository. GitHub also offers other common
options such as a license file, but you do not have to select any of them
now.
Your hello-world repository can be a place where you store ideas,
resources, or even share and discuss things with others.
1. In the upper-right corner of any page, use the drop-down menu,
and select
2. New repository.
3. In the Repository name box, enter hello-world.
4. In the Description box, write a short description.
5. Select Add a README file.
6. Select whether your repository will be Public or Private.
7. Click Create repository.
UNIT - II
Frontend Development: Javascript basics OOPS Aspects of JavaScript Memory usage and
Functions in JS AJAX for data exchange with server jQuery Framework jQuery events, UI
components etc. JSON data format.
HTML JavaScript
A Script is a small program which is used with HTML to make web pages more attractive,
dynamic and interactive, such as an alert popup window on mouse click. Currently, the most
popular scripting language is JavaScript used for websites.
Example:
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Date and Time example</h1>
<button type="button"
onclick="[Link]('demo').innerHTML = Date()">
Click me to display Date and Time.</button>
<pid="demo"></p>
</body>
</html>
<script>
function myFunction() {
[Link]("demo").[Link] = "25px";
[Link]("demo").[Link] = "brown";
[Link]("demo").[Link] = "lightgreen";
}
</script>
<button type="button" onclick="myFunction()">Click Me!</button>
</body>
</html>
3) JavaScript can change HTML attributes.
Example:
<!DOCTYPE html>
<html>
<body>
<script>
function light(sw) {
var pic;
if (sw == 0) {
pic = "pic_lightoff.png"
} else {
pic = "pic_lighton.png"
}
[Link]('myImage').src = pic;
}
</script>
<img id="myImage" src="pic_lightoff.png" width="100" height="180">
<p>
<button type="button" onclick="light(1)">Light On</button>
<button type="button" onclick="light(0)">Light Off</button>
</p>
</body>
</html>
</head>
<body>
<h2>External JavaScript Example</h2>
<form onsubmit="fun()">
<label>Enter your name:</label><br>
<input type="text" name="uname" id="frm1"><br>
<label>Enter your Email-address:</label><br>
<input type="email" name="email"><br>
<input type="submit">
</form>
</body>
</html>
JavaScript code:[Link]
function fun() {
var x = [Link]("frm1").value;
alert("Hi"+" "+x+ "you have successfully submitted the details");
}
JavaScript Objects
A javaScript object is an entity having state and behavior (properties and method). For
example: car, pen, bike,chair, glass, keyboard, monitor etc.
JavaScript is an object-based language. Everything is an object in JavaScript.
JavaScript is template based not class based. Here, we don't create class to get the object. But,
we direct create objects.
Creating Objects in JavaScript
There are 3 ways to create objects.
1. By object literal
2. By creating instance of Object directly (using new keyword)
3. By using an object constructor (using new keyword)
1) JavaScript Object by object literal
The syntax of creating object using object literal is given below:
object={property1:value1,property2:value2.....propertyN:valueN}
As you can see, property and value is separated by : (colon).
Let’s see the simple example of creating object in JavaScript.
<html>
<body>
<script>
emp={id:102,name:"Shyam Kumar",salary:40000}
[Link]([Link]+" "+[Link]+" "+[Link]);
</script>
</body>
</html>
Output
102 Shyam Kumar 40000
Class Declarations
A class can be defined by using a class declaration. A class keyword is used to declare a class
with any particular name. According to JavaScript naming conventions, the name of the class
always starts with an uppercase letter.
Class Declarations Example
Let's see a simple example of declaring the class.
<!DOCTYPE html>
<html>
<body>
<script>
//Declaring class
class Employee
{
//Initializing an object
constructor(id,name)
{
[Link]=id;
[Link]=name;
}
//Declaring method
detail()
{
[Link]([Link]+" "+[Link]+"<br>")
}
}
//passing object to a variable
vare1=new Employee(101,"Martin Roy");
vare2=new Employee(102,"Duke William");
[Link](); //calling method
[Link]();
</script>
</body>
</html>
OUTPUT:
101 Martin Roy
102 Duke William
JQuery
jQuery is a fast, small, cross-platform and feature-rich JavaScript library. It is designed to
simplify the client-side scripting of HTML. It makes things like HTML document traversal
and manipulation, animation, event handling, and AJAX very simple with an easy-to-use API
that works on a lot of different type of browsers.
The main purpose of jQuery is to provide an easy way to use JavaScript on your website to
make it more interactive and attractive. It is also used to add animation.
jQuery is a small, light-weight and fast JavaScript library. It is also referred as ?write less do
more? because it takes a lot of common tasks that requires many lines of JavaScript code to
accomplish, and binds them into methods that can be called with a single line of code
whenever needed. It is also very useful to simplify a lot of the complicated things from
JavaScript, like AJAX calls and DOM manipulation.
o jQuery is a small, fast and lightweight JavaScript library.
o jQuery is platform-independent.
o jQuery means "write less do more".
jQuery Example
File: [Link]
<!DOCTYPE html>
<html>
<head>
<title>First jQuery Example</title>
<script type="text/javascript" src="[Link]
[Link]">
</script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("p").css("background-color", "pink");
});
</script>
</head>
<body>
<p>This is first paragraph.</p>
<p>This is second paragraph.</p>
<p>This is third paragraph.</p>
</body>
</html>
jQuery is aJavaScript framework. It facilitates the readability and the manipulation of HTML DOM
elements, event handling, animations, and AJAX calls. It’s also free,open-source softwarethat
adheres to the MIT License. As a result, it is one of the most popular JavaScript libraries.
jQuery Events
jQuery events are the actions that can be detected by your web application. They are used to
create dynamic webpages. An event shows the exact moment when something happens.
These are some examples of events.
o A mouse click
o An HTML form submission
o A webpage loading
o A keystroke on the keyboard
o Scrolling of the webpage etc.
<script>
$(document).ready(function(){
$("h1,h2,h3").click(function(){
$(this).hide();
});
});
</script>
</head>
<body>
<h1>This heading will disappear if you click on this.</h1>
<h2>I will also disappear.</h2>
<h3>Me too.</h3>
</body>
</html>
jQuery focus()
The jQuery focus event occurs when an element gains focus. It is generated
by a mouse click or by navigating to it.
This event is implicitly used to limited sets of elements such as form
elements like <input>, <select> etc. and links <a href>. The focused
elements are usually highlighted in some way by the browsers.
$(selector).focus()
It triggers the focus event for selected elements.
$(selector).focus(function)
It adds afunction to the focus event.
display: none;
}
</style>
<script src="[Link]
</head>
<body>
<p><input type ="text"> <span>Focus starts.. Write your name.</span></p>
jQuery submit()
jQuery submit event is sent to the element when the user attempts to submit a
form. This event is only attached to the <form> element. Forms can be
submitted either by clicking on the submit button or by pressing the enter
button on the keyboard when that certain form elements have focus. When the
submit event occurs, the submit()
<!DOCTYPE html>
<html lang ="en" >
<head>
<meta charset ="utf-8">
<title>submit demo</title>
<style>
p{
margin: 0;
color: blue;
}
div,p {
margin-left: 10px;
}
span {
color: red;
}
</style>
<script src="[Link]
</head>
<body>
<p>Type 'MRCET' to submit this form finally.</p>
<form action ="javascript:alert( 'success!' );">
<div>
<input type ="text" >
<input type ="submit" >
</div>
</form>
<span></span>
<script>
$( "form" ).submit(function( event ) {
if ( $( "input:first" ).val() === "MRCET" ) {
</script>
</body>
</html>
jQuerymouseover()
The mouseover event is occurred when you put your mouse cursor over the
selected element .Once the mouseover event is occurred, it executes the
mouseover () method or attach a function to run.
This event is generally used with mouseout() event.
Note: Most of the people are confused between mouseenter and mouseover.
$(document).ready(function(){
$("p").mouseover(function(){
$("p").css("background-color", "lightgreen");
});
$("p").mouseout(function(){
$("p").css("background-color", "orange");
});
});
</script>
</head>
<body>
<p>Move your cursor over this paragraph.</p>
</body>
</html>
margin: 0 15px;
background-color: lightgreen;
}
[Link] {
width: 60%;
height: 60%;
background-color: red;
margin: 10px auto;
}
</style>
<script src="[Link]
</head>
<body>
<div class ="out" >
<span style ="padding:20px">move your mouse</span>
<div class ="in"></div>
</div>
<script>
$( "[Link]" )
.mouseover(function() {
$( this ).find( "span" ).text( "mouse over " );
})
.mouseout(function() {
$( this ).find( "span" ).text( "mouse out " );
});
</script>
</body>
</html>
jQuery UI Categorization
We can categorize the jQuery UI into four groups.
1. Interactions
2. Widgets
3. Effects
4. Utilities
1) Interactions: Interactions are the set of plug-ins which facilitates users to
interact with DOM elements. These are the mostly used interactions:
o Draggable
o Droppable
o Resizable
o Selectable
o Sortable
2) Widgets: Widgets are the jQuery plug-ins which makes you able to create
user interface elements like date picker, progress bar etc. These are the
mostly used widgets:
o Accordion
o Autocomplete
o Dialog
o Button
o Date Picker
o Menu
o Progress Bar
o Tabs
o Tooltip
o Slider
o Spinner
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p id="demo"></p>
function fun1()
{
var xhr=new XMLHttpRequest();
[Link]=function()
{
[Link]("demo").innerHTML=[Link]
ext; }
[Link]("GET","[Link]",true);
[Link]();
}
</script>
</body>
</html>
Output:
[Link]
hello ajax wants to interact with you
JSON Example
JSON example can be created by object and array. Each object can have
different data such as text, number, boolean etc. Let's see different JSON
examples using object and array.
A JSON object contains data in the form of key/value pair. The keys are
strings and the values are the JSON types. Keys and values are separated by
colon. Each entry (key/value pair) is separated by comma.
{
"employee": {
"name": "sonoo",
"salary": 56000,
"married": true
}
}
JavaScript automatically allocates memory when objects are created and frees
it when they are not used anymore (garbage collection). This automaticity is a
potential source of confusion: it can give developers the false impression that they
don't need to worry about memory management.
The second part is explicit in all languages. The first and last parts are explicit in low-level
languages but are mostly implicit in high-level languages like JavaScript.
Allocation in JavaScript
Value initialization
In order to not bother the programmer with allocations, JavaScript will automatically allocate
memory when values are initially declared.
consto = {
a: 1,
b: null,
}; // allocates memory for an object and contained values
function f(a) {
return a + 2;
} / / allocates a function ( which is a callable object)
const s = "azerty";
const s2 = [Link](0, 3); // s2 is a new string
// Since strings are immutable values,
// JavaScript may decide to not allocate memory,
// but just store the [0, 3] range.
Using values basically means reading and writing in allocated memory. This can be done by
reading or writing the value of a variable or an object property or even passing an argument
to a function.
The majority of memory management issues occur at this phase. The most difficult aspect of
this stage is determining when the allocated memory is no longer needed.
Low-level languages require the developer to manually determine at which point in the
program the allocated memory is no longer needed and to release it.
CAREER ADVANCEMENT CELL 46 | P a g
e
FULL STACK DEVELOPMENT
UNIT-3
REACT JS: Introduction to React React Router and Single Page Applications React Forms,
Flow Architecture and Introduction to Redux More Redux and Client-Server Communication
React Introduction
ReactJS is a declarative, efficient, and flexible JavaScript library for building
reusable UI components. It is an open-source, component-based front end
library responsible only for the view layer of the application. It was created by
Jordan Walke, who was a software engineer at Facebook. It was initially
developed and maintained by Facebook and was later used in its products
like WhatsApp & Instagram. Facebook developed ReactJS in 2011 in its
newsfeed section, but it was released to the public in the month of May 2013.
Today, most of the websites are built using MVC (model view controller)
architecture. In MVC architecture, React is the 'V' which stands for view,
whereas the architecture is provided by the Redux or Flux.
React create-react-app
Starting a new React project is very complicated, with so many build tools. It
uses many dependencies, configuration files, and other requirements such
as Babel, Webpack, ESLint before writing a single line of React code. Create
React App CLI tool removes all that complexities and makes React app
simple. For this, you need to install the package using NPM, and then run a
few simple commands to get a new React project.
The create-react-app is an excellent tool for beginners, which allows you to
create and run React project very quickly. It does not take any configuration
manually. This tool is wrapping all of the required dependencies like
Webpack, Babel for React
project itself and then you need to focus on writing React code only. This tool
sets up the development environment, provides an excellent developer
experience, and optimizes the app for production.
Requirements
The Create React App is maintained by Facebook and can works on any
platform, for example, macOS, Windows, Linux, etc. To create a React
Project using create- react-app, you need to have installed the following things
in your system.
1. Node version >= 8.10
2. NPM version >= 5.6
Let us check the current version of Node and NPM in the system.
Run the following command to check the Node version in the command prompt.
1. $ node -v
Run the following command to check the NPM version in the command prompt.
1. $ npm -v
Installation
Here, we are going to learn how we can install React using CRA tool. For
this, we need to follow the steps as given below.
Install React
We can install React using npm package manager by using the following
command. There is no need to worry about the complexity of React
installation. The create- react-app npm package manager will manage
everything, which needed for React project.
1. C:\Users\javatpoint> npm install -g create-react-app
Create a new React project
Once the React installation is successful, we can create a new React
project using create-react-app command. Here, I choose "reactproject" name
for my project.
1. C:\Users\javatpoint> create-react-app reactproject
NOTE: We can combine the above two steps in a single command using npx. The
npx is a package runner tool which comes with npm 5.2 and above version.
1. C:\Users\javatpoint> npx create-react-app reactproject
The above command will take some time to install the React and create a new
project with the name "reactproject." Now, we can see the terminal as like below.
The above screen tells that the React project is created successfully on our
system. Now, we need to start the server so that we can access the
application on the browser. Type the following command in the terminal
window.
1. $ cd Desktop
2. $ npm start
NPM is a package manager which starts the server and access the
application at default server [Link] Now, we will get the
following screen.
CAREER ADVANCEMENT CELL 49 | P a g e
FULL STACK DEVELOPMENT
Next, open the project on Code editor. Here, I am using Visual Studio Code.
Our project's default structure looks like as below image.
In React application, there are several files and folders in the root directory.
Some of them are as follows:
1. node_modules: It contains the React library and any other third party
libraries needed.
2. public: It holds the public assets of the application. It contains the [Link]
where React will mount the application by default on the <div id="root"></div>
element.
3. src: It contains the [Link], [Link], [Link], [Link], [Link], and
[Link] files. Here, the [Link] file always responsible for displaying the
output screen in React.
4. [Link]: It is generated automatically for any operations where
npm package modifies either the node_modules tree or [Link]. It
cannot be published. It will be ignored if it finds any other place rather
than the top-level package.
CAREER ADVANCEMENT CELL 50 | P a g
e
FULL STACK DEVELOPMENT
React Features
Currently, ReactJS gaining quick popularity as the best JavaScript framework
among web developers. It is playing an essential role in the front-end
ecosystem. The important features of ReactJS are as following.
o JSX
o Components
o One-way Data Binding
o Virtual DOM
o Simplicity
o Performance
JSX
JSX stands for JavaScript XML. It is a JavaScript syntax extension. Its an XML
or HTML like syntax used by ReactJS. This syntax is processed into
JavaScript calls of React Framework. It extends the ES6 so that HTML like
text can co-exist with JavaScript react code. It is not necessary to use JSX,
but it is recommended to use in ReactJS.
Components
CAREER is all about components. ReactJS application is made up of
ReactJS
ADVANCEMENT
multiple components, and each component has its own logic and controls.
These components can be reusable which help you to maintain the code when
working on larger scale projects.
One-way Data Binding
ReactJS is designed in such a manner that follows unidirectional data flow or
one- way data binding. The benefits of one-way data binding give you
better control throughout the application. If the data flow is in another
direction, then it requires additional features. It is because components are
supposed to be immutable and the data within them cannot be changed. Flux
is a pattern that helps to keep your data
51 | P a g
FULL STACK DEVELOPMENT
React JSX
As we have already seen that, all of the React components have a render
function. The render function specifies the HTML output of a React
component. JSX(JavaScript Extension), is a React extension which allows
writing JavaScript code that looks like HTML. In other words, JSX is an
HTML-like syntax used by React that extends ECMAScript so that HTML-
like syntax can co-exist with JavaScript/React code. The syntax is used by
preprocessors (i.e., transpilers like babel) to transform HTML-like syntax into
standard JavaScript objects that a JavaScript engine will parse.
the div tag, and last is the content you pass which is the "Hello JavaTpoint."
React Components
Earlier, the developers write more than thousands of lines of code for developing a single
page application. These applications follow the traditional DOM structure, and making
changes in them was a very challenging task. If any mistake found, it manually searches the
entire application and update accordingly. The component-based approach was introduced to
overcome an issue. In this approach, the entire application is divided into a small logical
group of code, which is known as components.
A Component is considered as the core building blocks of a React application. It makes the
task of building UIs much easier. Each component exists in the same space, but they work
independently from one another and merge all in a parent component, which will be the final
UI of your application.
Every React component have their own structure, methods as well as APIs. They can be
reusable as per your need. For better understanding, consider the entire UI as a tree. Here, the
root is the starting component, and each of the other pieces becomes branches, which are
further divided into sub-branches.
and returns what should be rendered. A valid functional component can be shown in the
below example.
function WelcomeMessage(props) {
return <h1>Welcome to the , {[Link]}</h1>;
}
The functional component is also known as a stateless component because they do not hold
or manage state. It can be explained in the below example.
Example
import React, { Component } from 'react';
class App extends [Link] {
render() {
return (
<div>
<First/>
<Second/>
</div>
);
}
}
class First extends [Link] {
render() {
return (
<div>
<h1>JavaTpoint</h1>
</div>
);
}
}
class Second extends [Link] {
render() {
return (
<div>
<h2>[Link]</h2>
<p>This websites contains the great CS tutorial.</p>
</div>
);
}
}
export default App;
Output:
Class Components
Class components are more complex than functional components. It requires you to extend
from React. Component and create a render function which returns a React element. You can
pass data from one class to other class components. You can create a class by defining a class
that extends Component and has a render function. Valid class component is shown in the
below example.
class MyComponent extends [Link] {
render() {
return (
<div>This is main component.</div>
);
}
}
The class component is also known as a stateful component because they can hold or manage
local state. It can be explained in the below example.
Example
In this example, we are creating the list of unordered elements, where we will dynamically
insert StudentName for every object from the data array. Here, we are using ES6 arrow
syntax (=>) which looks much cleaner than the old JavaScript syntax. It helps us to create our
elements with fewer lines of code. It is especially useful when we need to create a list with a
lot of items.
CAREER 55 | P a g
ADVANCEMENT
FULL STACK DEVELOPMENT
]
}
}
render() {
return (
<div>
<StudentName/>
<ul>
{[Link]((item) => <List data = {item} />)}
</ul>
</div>
);
}
}
class StudentName extends [Link] {
render() {
return (
<div>
<h1>Student Name Detail</h1>
</div>
);
}
}
class List extends [Link] {
render() {
return (
<ul>
<li>{[Link]}</li>
</ul>
);
}
}
export default App;
Output:
React State
The state is an updatable structure that is used to contain data or information
about the component. The state in a component can change over time. The
change in state over time can happen as a response to user action or system
event. A component with the state is known as stateful components. It
is the heart of the react component which determines the behavior of the
component and how it will render. They are also responsible for making a
component dynamic and interactive.
A state must be kept as simple as possible. It can be set
by using the setState() method and calling setState() method triggers UI
updates. A state
For example, if we have five components that need data or information from
the state, then we need to create one container component that will keep the
state for all of them.
Defining State
To define a state, you have to first declare a default set of values for
defining the component's initial state. To do this, add a class constructor
which assigns an initial state using [Link]. The '[Link]'
property can be rendered inside render() method.
Example
The below sample code shows how we can create a stateful component
using ES6 syntax.
</div>
) : null;
return (
<div>
<h1> Welcome to JavaTpoint!! </h1>
{ bio }
</div>
);
}
}
export default App;
Example
In this example, we are going to add a button to the render() method. Clicking on
this button triggers the toggleDisplayBio() method which displays the desired output.
[Link] = [Link](this);
}
toggleDisplayBio(){
[Link]({displayBio: ![Link]});
}
render() {
return (
<div>
<h1>Welcome to JavaTpoint!!</h1>
{
[Link] ? (
<div>
<p><h4>Javatpoint is one of the best Java training
institute in Noida, Delhi, Gurugram, Ghaziabad and Faridabad. We have a
team of experience d Java developers and trainers from multinational
companies to teach our campu s students. </h4></p>
<button onClick={[Link]}> Show Less
</button >
</div>
):(
<div>
<button onClick={[Link]}> Read More
</but
ton>
</div>
)
}
</div>
)
}
}
export default App;
Output:
When you click the Read More button, you will get the below output, and when you
click the Show Less button, you will get the output as shown in the above image.
React Props
Props stand for "Properties." They are read-only components. It is an object
which stores the value of attributes of a tag and work similar to the HTML
attributes. It gives a way to pass data from one component to other
components. It is similar to function arguments. Props are passed to the
component in the same way as arguments passed in a function.
Props are immutable so we cannot modify the props from inside the
component. Inside the components, we can add attributes called props.
These attributes are available in the component as [Link] and can be used
to render dynamic data in our render method.
When you need immutable data in the component, you have to add
props to [Link]() method in the [Link] file of your ReactJS project
and used it inside the component in which you need. It can be explained in the
below example.
Example
[Link]
CAREER
import React, { Component } from 'react';
ADVANCEMENT
class App extends [Link] {
render() {
return (
<div>
<h1> Welcome to { [Link] } </h1>
<p> <h4> Javatpoint is one of the best Java training institute in
Noida, De lhi, Gurugram, Ghaziabad and Faridabad. </h4> </p>
59 | P a g
FULL STACK DEVELOPMENT
</div>
);
}
}
export default App;
[Link]
import React from 'react';
Default Props
It is not necessary to always add props in the [Link]() element.
You can also set default props directly on the component constructor. It can
be explained in the below example.
Example
[Link]
</div>
);
}
}
CAREER
ADVANCEMENT
[Link] = {
name: "JavaTpoint"
}
export default App;
[Link]
import React from 'react';
60 | P a g
FULL STACK DEVELOPMENT
[Link](<App/>, [Link]('app'));
Output
constructor(props) {
super(props);
[Link] = {
name: "JavaTpoint",
}
}
render() {
return (
<div>
<JTPjtpProp = {[Link]}/>
</div>
);
}
}
class JTP extends [Link] {
render() {
return (
<div>
CAREER
ADVANCEMENT
<h1>State & Props Example</h1>
<h3>Welcome to {[Link]}</h3>
<p>Javatpoint is one of the best Java training institute in Noida,
Delhi, G urugram, Ghaziabad and Faridabad. </p>
</div>
);
}
61 | P a g
FULL STACK DEVELOPMENT
}
export default App;
[Link]
import React from 'react';
[Link](<App/>, [Link]('app'));
Output:
React Forms
Forms are an integral part of any modern web application. It allows the
users to interact with the application as well as gather information from the
users. Forms can perform many tasks that depend on the nature of your
business requirements and logic such as authentication of the user, adding
user, searching, filtering, booking, ordering, etc. A form can contain text fields,
buttons, checkbox, radio button, etc.
Creating Form
React offers a stateful, reactive approach to build a form. The component
rather than the DOM usually handles the React form. In React, the form is
usually implemented by using controlled components.
There are mainly two types of form input in React.
1. Uncontrolled component
2. Controlled component
Uncontrolled component
The uncontrolled input is similar to the traditional HTML form inputs. The DOM
itself handles the form data. Here, the HTML elements maintain their own state
that will be updated when the input value changes. To write an uncontrolled
component, you need to use a ref to get form values from the DOM. In other
words, there is no need to write an event handler for every state update. You
can use a ref to access the input field value of the form from the DOM.
Example
In this example, the code accepts a field username and company name
in an uncontrolled component.
constructor(props) {
super(props);
[Link] = [Link](this);
[Link] = [Link]();
}
updateSubmit(event) {
alert('You have entered the UserName and CompanyName
successfully.'); [Link]();
}
render() {
return (
<form onSubmit={[Link]}>
<h1>Uncontrolled Form Example</h1>
<label>Name:
</form>
);
}
}
export default App;
Output
When you execute the above code, you will see the following screen.
After filling the data in the field, you get the message that can be seen in the below
screen.
Controlled Component
In HTML, form elements typically maintain their own state and update it
according to the user input. In the controlled component, the input form
element is handled by the component rather than the DOM. Here, the
mutable state is kept in the state property and will be updated only with
setState() method.
Controlled components have functions that govern the data passing into
them on every onChange event, rather than grabbing the data only once, e.g.,
when you click
a submit button. This data is then saved to state and updated with
setState() method. This makes component have better control over the form
elements and data.
A controlled component takes its current value through props and
notifies the changes through callbacks like an onChange event. A parent
component "controls" this changes by handling the callback and managing its
own state and then passing the new values as props to the controlled
component. It is also called as a "dumb component."
Example
constructor(props) {
super(props);
[Link] = {value: ''};
[Link] = [Link](this);
[Link] = [Link](this);
}
handleChange(event) {
[Link]({value: [Link]});
}
handleSubmit(event) {
alert('You have submitted the input successfully: ' +
[Link]); [Link]();
}
render() {
return (
<form onSubmit={[Link]}>
<h1>Controlled Form Example</h1>
<label>
Name:
<input type="text" value={[Link]}
onChange={[Link]
nge} />
</label>
<input type="submit" value="Submit" />
</form>
);
}
}
export default App;
Output
When you execute the above code, you will see the following screen.
After filling the data in the field, you get the message that can be seen in the
below screen.
constructor(props) {
super(props);
[Link] = {
personGoing: true,
numberOfPersons: 5
};
[Link] =
[Link](this); }
handleInputChange(event) {
const target = [Link];
const value = [Link] === 'checkbox' ? [Link] :
[Link]; const name = [Link];
[Link]({
[name]: value
});
}
render() {
return (
<form>
CAREER
ADVANCEMENT
<h1>Multiple Input Controlled Form Example</h1>
<label>
Is Person going:
<input
name="personGoing"
type="checkbox"
65 | P a g
FULL STACK DEVELOPMENT
checked={[Link]}
onChange={[Link]} />
</label>
<br />
<label>
Number of persons:
<input
name="numberOfPersons"
type="number"
value={[Link]}
onChange={[Link]} />
</label>
</form>
);
}
}
export default App;
Output
The Example
Before we go further, take a look at the following example:
What you have here is a simple React app that uses React Router to provide
all of the navigation and view-loading goodness! Click on the various links to
load the relevant content, and feel free to open up this page in its own browser
windowto use the back and forward buttons to see them working.
Getting Started
The first thing we need to do is get our project setup. We'll use our
trusty create-react-app command to do this. From your favorite
terminal, navigate to the folder you want to create your app, and
type the following:
create-react-app react_spa
This will create our new project inside a folder called react_spa. Go
ahead and navigate into this folder:
cd react_spa
Normally, this is where we start messing around with deleting the
existing content to start from a blank slate. We will do that, but first,
we are going to install React Router. To do that, run the following
command:
Now that you've done this, it is time to clean up our project to start
from a clean slate. From inside your react_spa folder, delete
everything found inside your public and src folders. Once you've
done this, let's create our [Link] file that will serve as our app's
starting point. In your public folder, create a file
called [Link] and add the following contents into it:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>React Router Example</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
[Link](
<Main/>,
[Link]("root")
);
Our [Link] call lives here, and what we are rendering is
our Main component...which doesn't exist yet. The Main component
will be the starting point for our SPA expedition using React Router,
and we'll see how starting with the next section.
</div>
</div>
);
}
I know that this doesn't look all fancy and styled, but that's OK for
now. We will deal with that later. The important thing to call out is
that there is nothing React Router specific here. ABSOLUTELY
NOTHING!
Creating our Content Pages
Our app will have three pages of content. This content will just be a
simple component that prints out some JSX. Let's just get those
created and out of the way! First, create a file called [Link] in
our src directory and add the following content:
Next, create a file called [Link] in the same location and add in the
following:
That's the last of our content we are going to add. If you took a look
at what it is you were adding, you'll see that these components can't
get any simpler. They just returned some boilerplate JSX content.
Now, make sure to save all of your changes to these three files.
We'll look at how to make them useful shortly.
</div>
</div>
</HashRouter> );
}
}
The HashRouter component provides the foundation for the
navigation and browser history handling that routing is
made up of. What we are going to do next is define our
navigation links. We already have list elements with
the a element defined. We need to replace them with the
more specialized NavLink component, so go ahead and
make the following highlighted changes:
class Main extends Component {
render() {
return (
<HashRouter>
<div>
<h1>Simple SPA</h1>
<ul className="header">
<li><NavLink to="/">Home</NavLink></li>
<li><NavLink to="/stuff">Stuff</NavLink></li>
<li><NavLink to="/contact">Contact</NavLink></li>
</ul>
<div className="content">
</div>
</div>
</HashRouter>
);
}
}
For each link, pay attention to the URL we are telling our
router to navigate to. This URL value (defined by
the to prop) acts as an identifier to ensure the right
content gets loaded. The way we match the URL with the
content is by using a Route component. Go ahead and
add the
following highlighted lines:
class Main extends Component {
render() {
return (
<HashRouter>
<div>
<h1>Simple SPA</h1>
<ul className="header">
<li><NavLink to="/">Home</NavLink></li>
<li><NavLink to="/stuff">Stuff</NavLink></li>
<li><NavLink to="/contact">Contact</NavLink></li>
</ul>
<div className="content">
<Route path="/" component={Home}/>
<Route path="/stuff" component={Stuff}/>
<Route path="/contact" component={Contact}/>
</div>
</div>
</HashRouter>
);
}
}
As you can see, the Route component contains a path prop.
The value you specify for the path determines when this route is
going to be active. When a route is active, the component
specified by the component prop gets rendered. For example,
when we click on
the Stuff link (whose path is /stuff as set by
the NavLink component's to prop), the route whose path value
is also /stuff becomes active. This means the contents
of our Stuff component get rendered.
You can see all of this for yourself. Jump back to your browser to
see the live updates or run npm start again. Click around on the links
to see the content loading in and out. Something seems off, though,
right? The content for our home page seems to always display even
if we are clicking on the Stuff or Contact links:
That seems problematic. We'll look at how to fix that and do many
more little housekeeping tasks in the next section when we go one
level deeper into using React Router.
It's the Little Things
In the previous section, we got our SPA mostly up and running. We
just wrapped our entire routing region inside a HashRouter
component, and we separated our links and the place our links
would load by
using the NavLink and Route components respectively. Getting our
example mostly up and running and fully up and running are two
different things. In the following sections, we'll close those
differences.
Fixing our Routing
We ended the previous section by calling out that our
routing has a bug in it. The contents of
our Home component is always displaying. The reason for
it is because the path for loading our Home component is /.
Our Stuff and Contact components have the / character as
part of their paths as well. This means
our Home component always matches whatever path we
are trying to navigate to. The fix for that is simple. In
.content li {
margin-bottom: 10px;
}
After you've done this, we need to reference this style
sheet in our app. At the top of [Link], add
the import statement to do just that:
import React from "react";
import ReactDOM from "react-dom";
import Main from "./Main";
import "./[Link]"; [Link](
<Main/>,
[Link]("root")
);
Save all of your changes if you haven't done so yet. If you preview
the app now, you'll notice that it is starting to look a bit more like the
example we started out with:
We are almost done here! There is just a few more things we need
to do.
Highlighting the Active Link
Right now, it's hard to tell which link corresponds to content that is
currently loaded. It would be useful to have some sort of a visual cue
to solve this. The creators of React Router have already thought of
that! When you click on a link, a class value of active is
automatically assigned to it.
For example, this is what the HTML for clicking on the
Stuff link looks like:
<a aria-current="true" href="#/stuff" class="active">Stuff</a>
CAREER ADVANCEMENT CELL 76 | P a g
e
FULL STACK DEVELOPMENT
This means all we really have to do is add the appropriate CSS that
lights up when an element has a class value of active set on it. To
make this happen, go back to [Link] and add the following style
rule towards the bottom of your document:
.active {
background-color: #0099FF;
}
Once you have added this rule and saved your document, go back
to your browser and click around on the links in our example. You'll
see that the active link whose content is displayed from is
highlighted with a blue color. What you will also see is our Home link
always highlighted. That isn't correct. The fix for that is simple. Just
add the exact prop to our NavLink component representing our
home
content:
<li><NavLink exact to="/">Home</NavLink></li>
<li><NavLink to="/stuff">Stuff</NavLink></li>
<li><NavLink to="/contact">Contact</NavLink></li>
Once you have done that, go back to our browser. You'll
see that our Home link only gets the active color treatment
when the home content is displayed:
CAREER ADVANCEMENT CELL 77 | P a g
e
FULL STACK DEVELOPMENT
UNIT - IV
Java Web Development: JAVA PROGRAMMING BASICS, Model View Controller (MVC)
Pattern MVC Architecture using Spring RESTful API using Spring Framework Building an
application using Maven
The DispatcherServlet
The Spring Web model-view-controller (MVC) framework is designed around
a DispatcherServlet that handles all the HTTP requests and responses. The request
processing workflow of the Spring Web MVC DispatcherServlet is illustrated in the
following diagram −
Required Configuration
You need to map requests that you want the DispatcherServlet to handle, by using a
URL mapping in the [Link] file. The following is an example to show declaration
and mapping for HelloWeb DispatcherServlet example −
<servlet>
<servlet-name>HelloWeb</servlet-name>
<servlet-class>
[Link]
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>HelloWeb</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
</web-app>
The [Link] file will be kept in the WebContent/WEB-INF directory of your web
application. Upon initialization of HelloWeb DispatcherServlet, the framework will try
to load the application context from a file named [servlet-name]-[Link] located
in the application's WebContent/WEB-INF directory. In this case, our file will
be [Link].
Next, <servlet-mapping> tag indicates what URLs will be handled by which
DispatcherServlet. Here all the HTTP requests ending with .jsp will be handled by
<listener>
<listener-class>
[Link]
</listener-class>
</listener>
</web-app>
Now, let us check the required configuration for [Link] file, placed in
your web application's WebContent/WEB-INF directory −
<beans xmlns = "[Link]
xmlns:context = "[Link]
xmlns:xsi = "[Link]
xsi:schemaLocation = "[Link]
[Link]
[Link]
[Link]
</beans>
Following are the important points about [Link] file −
Defining a Controller
The DispatcherServlet delegates the request to the controllers to execute the
functionality specific to it. The @Controller annotation indicates that a particular
class serves the role of a controller. The @RequestMapping annotation is used to
map a URL to either an entire class or a particular handler method.
@Controller
@RequestMapping("/hello")
public class HelloController {
@RequestMapping(method = [Link])
public String printHello(ModelMap model) {
[Link]("message", "Hello Spring MVC Framework!");
return "hello";
}
}
The @Controller annotation defines the class as a Spring MVC controller. Here, the
first usage of @RequestMapping indicates that all handling methods on this
controller are relative to the /hello path.
Next annotation @RequestMapping(method = [Link]) is used to
declare the printHello() method as the controller's default service method to handle
HTTP GET request. You can define another method to handle any POST request at
the same URL.
You can write the above controller in another form where you can add additional
attributes in @RequestMapping as follows −
@Controller
public class HelloController {
@RequestMapping(value = "/hello", method = [Link])
public String printHello(ModelMap model) {
[Link]("message", "Hello Spring MVC Framework!");
return "hello";
}
}
The value attribute indicates the URL to which the handler method is mapped and
the method attribute defines the service method to handle HTTP GET request. The
following important points are to be noted about the controller defined above −
. You will define required business logic inside a service method. You can call
another method inside this method as per requirement.
. Based on the business logic defined, you will create a model within this
method. You can use setter different model attributes and these attributes will
CAREER 82 | P a g
ADVANCEMENT
FULL STACK DEVELOPMENT
be accessed by the view to present the final result. This example creates a
model with its attribute "message".
. A defined service method can return a String, which contains the name of
the view to be used to render the model. This example returns "hello" as
logical view name.
<html>
<head>
<title>Hello Spring MVC</title>
</head>
<body>
<h2>${message}</h2>
</body>
</html>
Here ${message} is the attribute which we have set up inside the Controller. You
can have multiple attributes to be displayed inside your view.
CAREER 83 | P a g
ADVANCEMENT
FULL STACK DEVELOPMENT
[Link]
RESTful API using Spring Framework
Web-based application development is a common part ofJavadevelopment. It is part
and parcel of the enterprise domain wherein they share many common attributes of
building a production-ready application. Spring uniquely addresses the concern for
building a Web application through its MVC framework. It is called MVC because it
is based upon the MVC (Model-View-Controller) pattern. Refer toWikipedia: Model-
view-controllerfor quick information about this. Web applications, in most cases,
have a REST counterpart for resource sharing. This article builds up on both the idea
and ends with aquick example to describe them in a terse manner.
Spring MVC
A Web application is inherently multi-layered because the intricacies between the user
request and server response go through several in-between stages of information
processing. Each stage is handled by a layer. For example, the Web interaction begins
with user interaction with the browser, such as by triggering a request and getting a
response from the server. The request response paradigm is nothing more than an
exchange of certain arranged data, which can be anywhere from trivial to heavily
loaded information gathered from, for example, a form submitted by the user. The
URL encapsulates the request from the user and flutters into the network oblivion.
Voilà! It is returned back with the digital PIZZA you have requested onto the platter
called a browser. The request actually goes through a bunch of agents under the
purview of the Spring MVC framework. Each of these agents performs specific
functions,technically called request processing, before actually responding back to
the requester. Here is an illustration to give you an idea.
1. The journey begins with the HTTP request (sometimes with data payload; for
example, due to form submission) in a URL. It first stations at DispatcherServlet.
The DispatcherServlet is a class defined in
the [Link] package. It is the central dispatcher, a Java
Servlet Component for the Spring MVC framework. This front controller receives
all incoming HTTP client requests and delegates responsibilities to other
components for further processing of the request payload.
2. The handler mapping decides where the request’s next stop would be. It acts as a
consultant to the central dispatcher (DispatcherServlet) for routing the request to
the appropriate controller. The handler mapping parses the request URL to make
decisions and the dispatcher then delegates the request to the controller.
3. The controller‘s responsibility is to process the information payload received from
the request. Typically, a controller is associated with one or more business service
classes which, in turn, may have associated database services repository classes.
The repository classes fetch database information according to the business service
logic. It is the business service classes that contain the crux of processing. The
controller class simply carries the information received from one or more service
classes to the user. However, the response of the controller classes is still raw data
referred to as the model and may not be user friendly (with indentation, bullets,
tables, images, look-and-feel, and so forth).
4. Therefore, the controller packages the model data along with model and view name
back again to the central dispatcher, DispatcherServlet.
5. The view layer can be designed using any third-party framework such as [Link],
Angular, JSP, and soon. The controller is decoupled from the view bypassing the
view name to the DispatcherServlet and is least interested in it. The
DispatcherServlet simply carries the logical name and consults with the view
resolver to map the logical view name with the actual implementation.
CAREER 85 | P a g
ADVANCEMENT
FULL STACK DEVELOPMENT
6. Once the mapping between logical view name and the actual view implementation
is made, the DispatcherServlet delegates the responsibility of rendering model data
to the view implementation.
7. The view implementation finally carries the response back to the client browser.
REST
REST is the acronym of Representational State Transfer. It is a term coined in Roy
Thomas Fielding’s doctoral thesiswhere REST is apart that encompasses the
architecture of transferring the state of resources. The REST architecture is made
popular as an alternative to a SOAP implementation of Web services. Although REST
has a much wider connotation than just Web services, here we’ll limit our discussion
to dealing with REST resources only. The idea Web services are basically resource
sharing in the Web architecture that forms the cornerstone of distributed machine-to-
machine communication. The Spring MVC framework resides pretty well with REST
and provides the necessary API support to implement it seamlessly, with little effort.
CAREER 86 | P a g
ADVANCEMENT
FULL STACK DEVELOPMENT
Though the URL is associated with HTTP methods in REST, there are no strict rules
to adhere to the outcome described above. The point is that RESTful URL structure
should be able to locate aresource on the server. For instance, the PUT instruction can
be used to create anew resource and POST can be used to update aresource.
REST in Spring
The REST API support was introduced in Spring from version 3.0 onwards; since
then, it has steadily evolved to the present day. We can create REST resources in the
following ways:
. Using controllers which are used to handle HTTP requests such as GET, POST,
PUT, and so forth. The PATCH command is supported by Spring 3.2 and higher
versions.
. Using the @PathVariable annotation. This annotation is used to handle
parameterized URLs. This is usually associated with
the @RequestMapping handler method in a Servlet environment.
. There are multiple ways to represent a REST resource using Spring views and view
resolvers with rendering model data as XML, JSON, Atom, and RSS.
. The type of model data view suits the client can be resolved
via ContentNegotiatingViewResolver. The ContentNegotiatingViewResolver,
however, does not resolve views itself but delegates to other ViewResolvers. By
default, these other view resolvers are picked up automatically from the application
context, though they can also be set explicitly by using the viewResolver property.
. Consuming REST resources using RestTemplate.
Firstly, we create a model class named Employee. This maybe designated with JPA
annotation to persist in the backend database. But, to keep it simple, we’ll not use
JPA; instead, we’ll supply dummy data through the EmployeeService class. In a real
situation, data is fetched from the backend database server and the data access
methods are defined in a repository class. To give a hint, in our case, if we had used
JPA with a back-end database, it may have been an interface that
extends CrudRepository, something like this.
// ...
[Link]
package
com. mano. spring_ mvc_ rest_ example. spring_ mvc_ rest. employee
;
public Employee( ) {
[Link] = id;
[Link] = name;
return id;
[Link] = id;
return name;
[Link] = name;
return address;
[Link]
package com. mano. spring_ mvc_ rest_ example. spring_
import [Link];
@Service
"New York"),
"Gotham City"),
"Metropolis"),
"Wakanda"),
"New York")
);
return employeeList;
return [Link]().filter(e->[Link]()
.equals(id)).findFirst().get();
for(int i=0;i<[Link]();i++){
Employee e= [Link]( i ) ;
if([Link]().equals(id)) {
break;
[Link](e->[Link]().equals(id));
[Link]
package
com. mano. spring_ mvc_ rest_ example. spring_ mvc_ rest. employee
;
import
[Link];
@RestController
@ Autowired
@RequestMapping( "/employees" )
return [Link]();
@RequestMapping("/employees/{empid}")
String id){
return [Link](id);
@RequestMapping(method= [Link],
value="/employees")
[Link](employee);
value="/employees/{id}")
[Link](employee, id);
value="/employees/{id}")
}
Observe that the Web controller class named EmployeeController is designated as
a @RestController annotation. This is a convenience annotation that actually
combines the @ Controller and @ ResponseBody annotations.
The @Controller annotation designates a POJO as a Web controller and is a
specialization of @Component. When we designate a POJO class with @Controller or
@Component, or even a @RestController, Spring auto detects them by considering
The valid URL requests for publishing REST resources for the above code are as
follows:
Conclusion
For REST CRUD operations such as adding, updating, and deleting Employee, we
need a HTTP client application that enables us to test Web services, such as postman;
otherwise, we need to implement the view layer of the application with the help of
JavaScript frameworks such as jQuery,AngularJS, and the like. To keep the write-up
well within limits, we have not implemented them here. If possible, we’ll take them
up in a separate write-up. By the way, we have only scratched the surface of Spring
MVC and Spring REST support. Take this as a warm-up before the deep plunge you
may want to take into the stream of Spring. As you swim across, you’ll find many
interesting sight scenes. 。
[Link]
Lifecycle Management
One of the primary objectives of Maven is to manage the
lifecycle of a Java project. While building a Java application may
appear to be a simple, one-step process, there are actually
multiple steps that take place. Maven divides this process into
three lifecycles:
Phases
Maven further subdivides these lifecycles into phases, which
represent a stage in the build process. For example, the default
lifecycle includes
the following phases (as well as others):
1. validate
2. compile
3. test
4. package
5. deploy
1. compiler:compile
2. compiler:testCompile
For example, suppose that we wish to add a goal that verifies that our
code meets the formatting standard of our company. To do this,
we could create a new plugin that has a goal that checks the
source code and
compares it to our company standard, succeeding ifour code
meets the standard and failing otherwise.
We can then tie this goal into the validate phase so that when
Maven runs the validate phase (such as when the compile phase is
run), our custom goal is executed. Creating such a plugin is
outside the scope of this article, but detailed information can
be found in the official
Maven Plugin Developmentdocumentation.
goal foo:bar that is not associated with any phase, Maven will not
execute this goal for us (since no dependency is created to a
phase that Maven is executing), but we can explicitly instruct
Maven to execute this goal on the command line:
1
mvn foo:bar
Lifecycledocumentation.
[Link]
CAREER ADVANCEMENT CELL 97 | P a g
e
FULL STACK DEVELOPMENT
UNIT - V
Databases & Deployment: Relational schemas and normalization
Structured Query Language (SQL) Data persistence using Spring JDBC Agile
development principles and deploying application in Cloud
These are some important terminologies that are used in terms of relation.
Attribute: Attributes are the properties that define a relation.
e.g.; ROLL_NO, NAME etc.
Tuple: Each row in the relation is known as tuple. The above relation
contains 4 tuples, one of which is shown as:
1 RAM DELHI 9455123451 18
1
2
3
4
ROLL_NO NAME
3 SUJIT
4 SURESH
If DISTINCT is not used, DELHI will be repeated twice in result set. Before
understanding GROUP BY and HAVING, we need to understand
aggregations functions in SQL.
AGGRATION FUNCTIONS: Aggregation functions are used to perform
mathematical operations on data values of a relation. Some of the common
aggregation functions used in SQL are:
1. COUNT: Count function is used to count the number of rows in a relation.
e.g; SELECT COUNT (PHONE) FROM STUDENT;
COUNT(PHONE)
4
SUM(AGE)
74
In the same way, MIN, MAX and AVG can be used. As we have seen
above, all aggregation functions return only 1 row.
OR
Syntax: SUM(attributename)/COUNT(attributename)
The above mentioned syntax also retrieves the average value of tupples.
Syntax:MAX(attributename)
MINIMUM: It extracts the minimum value amongst the set of all the tupples.
Syntax:MIN(attributename)
ADDRESS SUM(AGE)
DELHI 36
GURGAON 18
ROHTAK 20
If we try to execute the query given below, it will result in error because
although we have computed SUM(AGE) for each address, there are more
than 1 ROLL_NO for each address we have grouped. So it can’t be
displayed in result set. We need to use aggregate functions on columns after
SELECT statement to make sense of the resulting set whenever we are
using GROUP BY.
. Insert Anomaly: This happens when we cannot insert data into the table
without another.
. Update Anomaly: This is due to data inconsistency caused by data
redundancy and data update.
. Delete exception: Occurs when some attributes are lost due to the
deletion of other attributes.
DDL
DDL is Data Definition Language and is used to define the structures like schema, database,
tables, constraints etc. Examples of DDL are create and alter statements.
DML
DML is Data Manipulation Language and is used to manipulate data. Examples of DML are
insert, update and delete statements.
Following are the important differences between DDL and DML.
CAREER ADVANCEMENT CELL 103 |
Pag
e
FULL STACK DEVELOPMENT
Stands for DDL stands for Data Definition DML stands for Data
1
Language. Manipulation Language.
Transaction Control language is a language that manages transactions within the database.
It is used to execute the changes made by the DML statements.
TCL Commands
Transaction Control Language (TCL) Commands are:
. Commit - It is used to save the transactions in the database.
. Rollback - It is used to restore the database to that state which was last
committed.
. Begin - It is used at the beginning of a transaction.
. Savepoint - The changes done till savpoint will be unchanged and all the
transactions after savepoint will be rolled back.
Example
Given below is an example of the usage of the TCL commands in the database management
system (DBMS) -
BEGIN TRANSACTION
UPDATE employees
SET empname=’bob’
WHERE empid=’001’
UPDATE employees
SET empname =’bob’
WHERE city=’hyderabad’
IF @@ROWCOUNT=5
CAREER ADVANCEMENT CELL 104 |
Pag
e
FULL STACK DEVELOPMENT
COMMIT TRANSACTION
ELSE
ROLLBACK TRANSACTION
In the above example after we begin the transaction, we are trying to update the employee’s
name with some value of id. If we affect five rows with our first query then, it will
COMMIT transaction else It will be ROLLBACK.
Difference between Commit, rollback and savepoint of TCL commands
Sno. Rollback Commit Savepoint
6 Make sure you already created Student table in TEST database. Also make sure
your MySQL server is working fine and you have read/write access on the database
using the give username and password.
7 Create Beans configuration file [Link] under the src folder.
8 The final step is to create the content of all the Java files and Bean Configuration file
and run the application as explained below.
Syntax
String insertQuery = "insert into Student (name, age) values (?, ?)";
[Link]( insertQuery, name, age);
Where,
. insertQuery − Insert query having placeholders.
. jdbcTemplateObject − StudentJDBCTemplate object to insert student object
in database.
To understand the above-mentioned concepts related to Spring JDBC, let us write an example
which will insert a query. To write our example use the following steps to create a Spring
application.
Following is the content of the Data Access Object interface file [Link].
package [Link];
import [Link];
import [Link];
/**
* This is the method to be used to create
* a record in the Student table.
*/
public void create(String name, Integer age);
/**
* This is the method to be used to list down
* all the records from the Student table.
*/
import [Link];
import [Link];
import [Link];
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
StudentJDBCTemplate studentJDBCTemplate =
(StudentJDBCTemplate)[Link]("studentJDBCTemplate");
[Link]("------Records Creation--------" );
[Link]("Zara", 11);
[Link]("Nuha", 2);
[Link]("Ayan", 15);
CAREER 109 |
ADVANCEMENT Pag
FULL STACK DEVELOPMENT
Syntax
String selectQuery = "select * from Student";
List <Student> students = [Link](selectQuery, new StudentMapper());
Where,
. selectQuery − Select query to read students.
. jdbcTemplateObject − StudentJDBCTemplate object to read student object
from database.
. StudentMapper − StudentMapper is a RowMapper object to map each
fetched record to student object.
To understand above mentioned concepts related to Spring JDBC, let us write an example
which will select a query. To write our example, use the following steps to create a Spring
application.
Following is the content of the Data Access Object interface file [Link].
package [Link];
import [Link];
import [Link];
/**
* This is the method to be used to list down
* all the records from the Student table.
*/
public List<Student> listStudents();
}
Following is the content of the [Link] file.
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
}
}
Following is the content of the [Link] file.
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
Once you are done creating the source and bean configuration files, let us run the application.
If everything is fine with your application, it will print the following message.
------Listing Multiple Records--------
ID : 1, Name : Zara, Age : 11
ID : 2, Name : Nuha, Age : 2
ID : 3, Name : Ayan, Age : 15
Syntax
import [Link];
import [Link];
/**
* This is the method to be used to update
* a record into the Student table.
*/
public void update(Integer id, Integer age);
/**
* This is the method to be used to list down
* a record from the Student table corresponding
* to a passed student id.
*/
CAREER ADVANCEMENT CELL 113 |
Pag
e
FULL STACK DEVELOPMENT
import [Link];
import [Link];
import [Link];
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
}
}
Following is the configuration file [Link].
<?xml version = "1.0" encoding = "UTF-8"?>
<beans xmlns = "[Link]
xmlns:xsi = "[Link]
xsi:schemaLocation = "[Link]
[Link] ">
</beans>
Once you are done creating the source and bean configuration files, let us run the application.
If everything is fine with your application, it will print the following message.
----Updating Record with ID = 2 -----
Updated Record with ID = 2
----Listing Record with ID = 2 -----
ID : 2, Name : Nuha, Age : 20
which will delete a query. To write our example, use the following steps to create a Spring
application.
Following is the content of the Data Access Object interface file [Link].
package [Link];
import [Link];
import [Link];
/**
* This is the method to be used to list down
* all the records from the Student table.
*/
public List<Student> listStudents();
/**
* This is the method to be used to delete
* a record from the Student table corresponding
* to a passed student id.
*/
public void delete(Integer id);
}
Following is the content of the [Link] file.
package [Link];
[Link] = id;
}
public Integer getId() {
return id;
}
}
Following is the content of the [Link] file.
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
}
Following is the content of the [Link] file.
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
</beans>
Once you are done creating the source and bean configuration files, let us run the application.
If everything is fine with your application, it will print the following message.
----Updating Record with ID = 2 -----
Updated Record with ID = 2
----Listing Record with ID = 2 -----
ID : 2, Name : Nuha, Age : 20
Most cloud hubs have tens of thousands of servers and storage devices to
enable fast loading. It is often possible to choose a geographic area to put the
data "closer" to users. Thus, deployment models for cloud computing are
categorized based on their location. To know which model would best fit
the requirements of your organization, let us first learn about the various
types.
Public Cloud
The name says it all. It is accessible to the public. Public deployment models
in the cloud are perfect for organizations with growing and fluctuating
demands. It also makes a great choice for companies with low-security
concerns. Thus, you pay a cloud service provider for networking services,
compute virtualization & storage available on the public internet. It is also a
great delivery model for the teams with development and testing. Its
configuration and deployment are quick and easy, making it an ideal choice
for test environments.
CAREER ADVANCEMENT CELL 120 |
Pag
e
FULL STACK DEVELOPMENT
Private Cloud
Now that you understand what the public cloud could offer you, of course,
you are keen to know what a private cloud can do. Companies that look for
cost efficiency and greater control over data & resources will find the private
cloud a more suitable choice.
It means that it will be integrated with your data center and managed by your IT
team. Alternatively, you can also choose to host it externally. The private cloud
offers bigger opportunities that help meet specific organizations'
requirements when it comes to customization. It's also a wise choice for
mission-critical processes that may have frequently changing requirements.
o Higher Cost - With the benefits you get, the investment will also be
larger than the public cloud. Here, you will pay for software, hardware,
and resources for staff and training.
o Fixed Scalability - The hardware you choose will accordingly help you
scale in a certain direction
Community Cloud
The community cloud operates in a way that is similar to the public cloud.
There's just one difference - it allows access to only a specific set of
users who share
Hybrid Cloud
storing on a private cloud, while less sensitive data can be stored on a public
cloud. The hybrid cloud is also frequently used for 'cloud bursting'. It means,
supposes an organization runs an application on-premises, but due to heavy
load, it can burst into the public cloud.
o Specific Use Case - This model makes more sense for organizations
that have multiple use cases or need to separate critical and sensitive
data
Community cloud which is called Cloud deployment model. The demand for
cloud services is increasing so fast and the global cloud computing market is
growing at that rate. A large number of organizations and different business
sectors are preferring cloud services nowadays as they are getting a list of
benefits from cloud computing. Different organizations using cloud computing
for different purposes and with respect to that Cloud Service Providers are
providing various applications in different fields. Applications of Cloud
Computing in real-world : Cloud Service Providers (CSP) are providing
many types of cloud services and now if we will cloud computing has
touched every sector by providing various cloud applications. Sharing and
managing resources is easy in cloud computing that’s why it is one of the
dominant fields of computing. These properties have made it an active
component in many fields. Now let’s know some of the real-world
applications of cloud computing.
1. Online Data Storage: Cloud computing allows storing data like files,
images, audios, and videos, etc on the cloud storage. The organization
need not set physical storage systems to store a huge volume of business
data which costs so high nowadays. As they are growing technologically,
data generation is also growing with respect to time, and storing that
becoming problem. In that situation, Cloud storage is providing this
service to store and access data any time as per requirement.
2. Backup and Recovery : Cloud vendors provide security from their side
by storing safe to the data as well as providing a backup facility to the
data. They offer various recovery application for retrieving the lost data. In
the traditional way backup of data is a very complex problem and also it is
very difficult sometimes impossible to recover the lost data. But cloud
computing has made backup and recovery applications very easy where
there is no fear of running out of backup media or loss of data.
3. BigdataAnalysis : We know the volume of big data is so high where
storing that in traditional data management system for an organization is
impossible. But cloud computing has resolved that problem by allowing
the organizations to store their large volume of data in cloud storage
without worrying about physical storage. Next comes analyzing the raw
data and finding out insights or useful information from it is a big
challenge as it requires high-quality tools for data analytics. Cloud
computing provides the biggest facility to organizations in terms of storing
and analyzing big data.
4. Testingand development : Setting up the platform for development and
finally performing different types of testing to check the readiness of the
product before delivery requires different types of IT resources and
infrastructure. But Cloud computing provides the easiest approach for
development as well as testing even if deployment by using their IT
resources with minimal expenses. Organizations find it more helpful as
they got scalable and flexible cloud services for product development,
testing, and deployment.
CAREER 125 |
ADVANCEMENT Pag
FULL STACK DEVELOPMENT