lOMoARcPSD|57317643
168061 Advance Java
Bsc. Information Technology (University of Mumbai)
Scan to open on Studocu
Studocu is not sponsored or endorsed by any college or university
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
Advanced Java Lab Subject Code: MCAL12
A Practical Journal Submitted in Fulfilment
of the Degree of
MASTER In
COMPUTER APPLICATION
Year 2022-2023
By
NAVEEDH ALI M. JINNA
(168061)
Semester- 1
Under the Guidance of
MS. Richa
Institute of Distance and Open Learning
Vidya Nagari, Kalina, Santacruz East – 400098.
University of Mumbai
PCP Center
[Satish Pradhan Dyanasadhana College, Thane]
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
Institute of Distance and Open Learning,
Vidyanagari, Kalina, Santacruz (E) -400098
CERTIFICATE
This to certify that, NAVEEDH ALI M. JINNA appearing master’s in
computer application (Semester I) 168061: has satisfactorily completed the
prescribed practical of MCAL12- Advanced JAVA Lab as laid down by the
University of Mumbai for the academic year 2022-23
Teacher in charge Examiners Coordinator
IDOL, MCA
University of Mumbai
Date: - Place: -
1|Page Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
INDEX
Pract Practical Page Date Signature
No No
1 Java Generics
1. Write a Java Program to demonstrate a Generic Class. 1
2. Write a Java Program to demonstrate Generic Methods.
2 List Interface :
Write a Java program to create List containing list of items of 3
type String and use for---each loop to print the items of the
list.
3 Set Interface :
Write a Java program using Set interface containing list of
items and perform the following operations: 5
a. Add items in the set.
b. Insert items of one set in to other set.
c. Remove items from the set
d. Search the specified item in the set
4 Map Interface :
Write a Java program using Map interface containing list of
items having keys and associated values and perform the 7
following operations:
a. Add items in the map.
b. Remove items from the map
c. Search specific key from the map
d. Get value of the specified key
e. Insert map elements of one map in to other map.
f. Print all keys and values of the map
5 Lambda Expression :
Write a Java program using Lambda Expression to print
”Hello World”. 12
6 Web application development using JSP :
a. Write a JSP page to display the Registration form (Make
your own assumptions) 13
b. Write a JSP program that demonstrates the use of JSP
declaration, scriptlet, directives, expression, header and
footer.
7 Spring Framework :
Write a program to print “Hello World” using spring 26
framework.
8 Spring JDBC :
Write a program to insert, update and delete records from the 28
given table
9 Spring Boot and RESTful Web Services
Write a program to create a simple Spring Boot application 37
that prints a message.
2|Page Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
Practical 1 : Java Generics
Aim : Write a Java Program to demonstrate a Generic Class.
Generic Class : - Generics means parameterized types. The idea is to allow type (Integer,
String, … etc., and user-defined types) to be a parameter to methods, classes, and interfaces.
Using Generics, it is possible to create classes that work with different data types. An entity
such as class, interface, or method that operates on a parameterized type is a generic entity.
class Test<T> {
T obj;
Test(T obj) { [Link] = obj; } // constructor
public T getObject() { return [Link]; }
}
class Main {
public static void main(String[] args)
{
// instance of Integer type
Test<Integer> iObj = new Test<Integer>(169593);
[Link]([Link]());
// instance of String type
Test<String> sObj
= new Test<String>("Pratibha");
[Link]([Link]());
}
}
Output:
3|Page Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
Aim:- Write a Java Program to demonstrate Generic Methods.
class Test {
// A Generic method example
static <T> void genericDisplay(T element)
{
[Link]([Link]().getName()
+ " = " + element);
}
// Driver method
public static void main(String[] args)
{
// Calling generic method with Integer argument
genericDisplay(169593);
// Calling generic method with String argument
genericDisplay("Pratibha");
// Calling generic method with double argument
genericDisplay(5.5);
}
}
4|Page Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
Practical 2: - List Interface
Aim: - Write a Java program to create List containing list of items of type String and
use for---each loop to print the items of the list.
import [Link].*;
public class Main
{
public static void main(String[] args) {
String[] strArray = {"Java", "ADBMS", "Data Structure", "Web Technology"};
List<String> mylist = [Link](strArray);
[Link]("Immutable list:");
for(String val : mylist){
[Link](val + " ");
}
[Link]("\n");
List<String> arrayList = new ArrayList<>([Link](strArray));
[Link]("New List:");
[Link]("Cloud");
//print the arraylist
for(String val : arrayList){
[Link](val + " ");
}
}
}
5|Page Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
Output:-
6|Page Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
Practical 3: - Set Interface
Aim :- Write a Java program using Set interface containing list of items and perform
the following operations:
a. Add items in the set.
b. Insert items of one set in to other set.
c. Remove items from the set
d. Search the specified item in the set
import [Link].*;
public class SetOperations
{
public static void main(String args[])
{
Integer[] A = {22, 45,33, 66, 55, 34, 77};
Integer[] B = {33, 2, 83, 45, 3, 12, 55};
Set<Integer> set1 = new HashSet<Integer>();
[Link]([Link](A));
Set<Integer> set2 = new HashSet<Integer>();
[Link]([Link](B));
// Finding Union of set1 and set2
Set<Integer> union_data = new HashSet<Integer>(set1);
union_data.addAll(set2);
[Link]("Union of set1 and set2 is:");
[Link](union_data);
// Finding Intersection of set1 and set2
Set<Integer> intersection_data = new HashSet<Integer>(set1);
intersection_data.retainAll(set2);
[Link]("Intersection of set1 and set2 is:");
[Link](intersection_data);
7|Page Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
// Finding Difference of set1 and set2
Set<Integer> difference_data = new HashSet<Integer>(set1);
difference_data.removeAll(set2);
[Link]("Difference of set1 and set2 is:");
[Link](difference_data);
}
}
8|Page Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
Practical 4: - Map Interface
Aim : - Write a Java program using Map interface containing list of items having keys
and associated values and perform the following operations:
a. Add items in the map.
b. Remove items from the map
c. Search specific key from the map
d. Get value of the specified key
e. Insert map elements of one map in to other map.
f. Print all keys and values of the map.
Operation 1: Adding Elements
// Java program to demonstrate
// the working of Map interface
import [Link].*;
class GFG {
public static void main(String args[])
{
// Default Initialization of a
// Map
Map<Integer, String> hm1 = new HashMap<>();
// Initialization of a Map
// using Generics
Map<Integer, String> hm2
= new HashMap<Integer, String>();
// Inserting the Elements
[Link](1, "Geeks");
[Link](2, "For");
[Link](3, "Geeks");
9|Page Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
[Link](new Integer(1), "Geeks");
[Link](new Integer(2), "For");
[Link](new Integer(3), "Geeks");
[Link](hm1);
[Link](hm2);
}
}
Output
{1=Geeks, 2=For, 3=Geeks}
{1=Geeks, 2=For, 3=Geeks}
Operation 2: Changing Element
// Java program to demonstrate
// the working of Map interface
import [Link].*;
class GFG {
public static void main(String args[])
{
// Initialization of a Map
// using Generics
Map<Integer, String> hm1
= new HashMap<Integer, String>();
// Inserting the Elements
[Link](new Integer(1), "Geeks");
[Link](new Integer(2), "Geeks");
[Link](new Integer(3), "Geeks");
10 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
[Link]("Initial Map " + hm1);
[Link](new Integer(2), "For");
[Link]("Updated Map " + hm1);
}
}
Output
Initial Map {1=Geeks, 2=Geeks, 3=Geeks}
Updated Map {1=Geeks, 2=For, 3=Geeks}
Operation 3: Removing Elements
// Java program to demonstrate
// the working of Map interface
import [Link].*;
class GFG {
public static void main(String args[])
{
// Initialization of a Map
// using Generics
Map<Integer, String> hm1
= new HashMap<Integer, String>();
// Inserting the Elements
[Link](new Integer(1), "Geeks");
[Link](new Integer(2), "For");
[Link](new Integer(3), "Geeks");
11 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
[Link](new Integer(4), "For");
// Initial Map
[Link](hm1);
[Link](new Integer(4));
// Final Map
[Link](hm1);
}
}
Output
{1=Geeks, 2=For, 3=Geeks, 4=For}
{1=Geeks, 2=For, 3=Geeks}
Operation 4: Iterating through the Map
// Java program to demonstrate
// the working of Map interface
import [Link].*;
class GFG {
public static void main(String args[])
{
// Initialization of a Map
// using Generics
Map<Integer, String> hm1
= new HashMap<Integer, String>();
// Inserting the Elements
[Link](new Integer(1), "Geeks");
12 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
[Link](new Integer(2), "For");
[Link](new Integer(3), "Geeks");
for ([Link] mapElement : [Link]()) {
int key
= (int)[Link]();
// Finding the value
String value
= (String)[Link]();
[Link](key + " : "
+ value);
}
}
}
Output
1 : Geeks
2 : For
3 : Geeks
13 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
Practical 5: - Lambda Expression
Aim : - Write a Java program using Lambda Expression to print ”Hello World”.
interface SayHello{
void sayHelloJava8();
}
public class HelloWorld {
public static void main(String[] args) {
SayHello hello = () -> {[Link]("Hello World");};
hello.sayHelloJava8();
Output :
14 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
Practical 6: - Web application development using JSP
Aim:-
a. Write a JSP page to display the Registration form (Make your own assumptions)
b. Write a JSP program that demonstrates the use of JSP declaration, scriptlet, directives,
expression, header and footer.
[Link]
<html>
<body >
<form action="/examples/jsp/[Link]" method=post>
<center>
<table cellpadding=2 cellspacing=1 border="1" bgcolor="lightblue">
<th bgcolor="lightblue" colspan=2>
<font size=5>User Registration</font>
<br>
<font size=2 color="red"><sup>*</sup> Required Fields</font>
</th>
<tr bgcolor="lightblue">
<td valign=top>
<b>First Name<sup>*</sup></b>
<br>
<input type="text" name="firstName" value="" size=20 maxlength=20></td>
<td valign=top>
<b>Last Name<sup>*</sup></b>
<br>
<input type="text" name="lastName" value="" size=15 maxlength=20></td>
</tr>
<tr bgcolor="lightblue">
<td valign=top>
<b>E-Mail<sup>*</sup></b>
<br>
<input type="text" name="email" value="" size=25 maxlength=125>
15 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
<br></td>
<td valign=top>
<b>Zip Code<sup>*</sup></b>
<br>
<input type="text" name="zip" value="" size=10 maxlength=8></td>
</tr>
<tr bgcolor="lightblue">
<td valign=top colspan=2>
<b>User Name<sup>*</sup></b>
<br>
<input type="text" name="userName" size=20 value="" maxlength=10>
</td>
</tr>
<tr bgcolor="lightblue">
<td valign=top>
<b>Password<sup>*</sup></b>
<br>
<input type="password" name="password1" size=10 value="" maxlength=10></td>
<td valign=top>
<b>Confirm Password<sup>*</sup></b>
<br>
<input type="password" name="password2" size=10 value="" maxlength=10></td>
<br>
</tr>
<tr bgcolor="lightblue">
<td valign=top colspan=2>
<b>What Technology are you interested in?</b>
<br>
<input type="checkbox" name="faveTech" value="Java">Java
<input type="checkbox" name="faveTech" value="JSP">JSP
16 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
<input type="checkbox" name="faveTech" value="Struts 1.1">Struts 1.1<br>
<input type="checkbox" name="faveTech" value="Ajax">Ajax
<input type="checkbox" name="faveTech" value="Struts 2.0 ">Struts 2.0
<input type="checkbox" name="faveTech" value="Servlets">Servlets<br>
</td>
</tr>
<tr bgcolor="lightblue">
<td valign=top colspan=2>
<b>Would you like to receive e-mail notifications on our special
sales?</b>
<br>
<input type="radio" name="notify" value="Yes" checked>Yes
<input type="radio" name="notify" value="No" > No
<br><br></td>
</tr>
<tr bgcolor="lightblue">
<td align=center colspan=2>
<input type="submit" value="Submit"> <input type="reset" value="Reset">
</td>
</tr>
</table>
</center>
</form>
</body>
</html>
<%@ page language="java" %>
<%@ page import="[Link].*" %>
<%!
17 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
%>
<jsp:useBean id="formHandler" class="[Link]" scope="request">
<jsp:setProperty name="formHandler" property="*"/>
</jsp:useBean>
<%
if ([Link]()) {
%>
<jsp:forward page="[Link]"/>
<%
} else {
%>
<jsp:forward page="[Link]"/>
<%
}
%>
package test;
import [Link].*;
import [Link].*;
public class FormBean {
private String firstName;
private String lastName;
private String email;
private String userName;
private String password1;
private String password2;
private String zip;
18 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
private String[] faveTech;
private String notify;
private Hashtable errors;
public boolean validate() {
boolean bool=true;
if ([Link]("")) {
[Link]("firstName","Please enter your first name");
firstName="";
bool=false;
}
if ([Link]("")) {
[Link]("lastName","Please enter your last name");
lastName="";
bool=false;
}
if ([Link]("") || ([Link]('@') == -1)) {
[Link]("email","Please enter a valid email address");
email="";
bool=false;
}
if ([Link]("")) {
[Link]("userName","Please enter a username");
userName="";
bool=false;
}
if ([Link]("") ) {
[Link]("password1","Please enter a valid password");
password1="";
bool=false;
}
19 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
if ( && ([Link]("") ||
)) {
[Link]("password2","Please confirm your password");
password2="";
bool=false;
}
if ([Link]("") || [Link]() !=6 ) {
[Link]("zip","Please enter a valid zip code");
zip="";
bool=false;
} else {
try {
int x = [Link](zip);
} catch (NumberFormatException e) {
[Link]("zip","Please enter a valid zip code");
zip="";
bool=false;
}
}
return bool;
}
public String getErrorMsg(String s) {
String errorMsg =(String)[Link]([Link]());
return (errorMsg == null) ? "":errorMsg;
}
public FormBean() {
firstName="";
lastName="";
email="";
userName="";
20 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
password1="";
password2="";
zip="";
faveTech = new String[] { "1" };
notify="";
errors = new Hashtable();
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getEmail() {
return email;
}
public String getUserName() {
return userName;
}
public String getPassword1() {
return password1;
}
public String getPassword2() {
return password2;
}
public String getZip() {
return zip;
}
public String getNotify() {
return notify;
21 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
}
public String[] getFaveTech() {
return faveTech;
}
public String isCbSelected(String s) {
boolean found=false;
if (!faveTech[0].equals("1")) {
for (int i = 0; i < [Link]; i++) {
if (faveTech[i].equals(s)) {
found=true;
break;
}
}
if (found) return "checked";
}
return "";
}
public String isRbSelected(String s) {
return ([Link](s))? "checked" : "";
}
public void setFirstName(String fname) {
firstName =fname;
}
public void setLastName(String lname) {
lastName =lname;
}
public void setEmail(String eml) {
email=eml;
}
public void setUserName(String u) {
22 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
userName=u;
}
public void setPassword1(String p1) {
password1=p1;
}
public void setPassword2(String p2) {
password2=p2;
}
public void setZip(String z) {
zip=z;
}
public void setFaveTech(String[] music) {
faveTech=music;
}
public void setErrors(String key, String msg) {
[Link](key,msg);
}
public void setNotify(String n) {
notify=n;
}
}
[Link]
<jsp:useBean id="formHandler" class="[Link]" scope="request"/>
<html>
<body>
<form action="[Link]" method=post>
<center>
<table cellpadding=4 cellspacing=2 border=0>
<th bgcolor="lightblue" colspan=2>
23 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
<font size=5>User Registration</font>
<br>
<font size=2 color="red"><sup>*</sup> Required Fields </font>
</th>
<tr bgcolor="lightblue">
<td valign=top>
<B>First Name<sup>*</sup></B>
<br>
<input type="text" name="firstName"
value='<%=[Link]()%>' size=15 maxlength=20>
<br><font size=2
color=red><%=[Link]("firstName")%></font>
</td>
<td valign=top>
<B>Last Name<sup>*</sup></B>
<br>
<input type="text" name="lastName"
value='<%=[Link]()%>' size=15 maxlength=20>
<br><font size=2
color=red><%=[Link]("lastName")%></font>
</td>
</tr>
<tr bgcolor="lightblue">
<td valign=top>
<B>E-Mail<sup>*</sup></B>
<br>
<input type="text" name="email" value='<%=[Link]()%>'
size=25 maxlength=125>
<br><font size=2 color=red><%=[Link]("email")%></font>
</td>
24 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
<td valign=top>
<B>Zip Code<sup>*</sup></B>
<br>
<input type="text" name="zip" value='<%=[Link]()%>' size=5
maxlength=6>
<br><font size=2 color=red><%=[Link]("zip")%></font>
</td>
</tr>
<tr bgcolor="lightblue">
<td valign=top colspan=2>
<B>User Name<sup>*</sup></B>
<br>
<input type="text" name="userName" size=10
value='<%=[Link]()%>' maxlength=10>
<br><font size=2
color=red><%=[Link]("userName")%></font>
</td>
</tr>
<tr bgcolor="lightblue">
<td valign=top>
<B>Password<sup>*</sup></B>
<br>
<input type="password" name="password1" size=10
value='<%=formHandler.getPassword1()%>' maxlength=10>
<br><font size=2
color=red><%=[Link]("password1")%></font>
</td>
<td valign=top>
<B>Confirm Password<sup>*</sup></B>
<br>
25 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
<input type="password" name="password2" size=10
value='<%=formHandler.getPassword2()%>' maxlength=10>
<br><font size=2
color=red><%=[Link]("password2")%></font>
</td>
<br>
</tr>
<tr bgcolor="lightblue">
<td colspan=2 valign=top>
<B>What Technology are you interested in?</B>
<br>
<input type="checkbox" name="faveTech"
value="Java"<%=[Link]("Java")%>>Java
<input type="checkbox" name="faveTech" value="JSP"
<%=[Link]("JSP")%>>JSP
<input type="checkbox" name="faveTech" value="Struts 1.1"
<%=[Link]("Struts 1.1")%>>Struts 1.1<br>
<input type="checkbox" name="faveTech" value="Ajax"
<%=[Link]("Ajax")%>>Ajax
<input type="checkbox" name="faveTech" value="Struts 2.0"
<%=[Link]("Struts 2.0")%>>Struts 2.0
<input type="checkbox" name="faveTech" value="Servlets"
<%=[Link]("Servlets")%>>Servlets<br>
</td>
</tr>
<tr bgcolor="lightblue">
<td colspan=2 valign=top>
<B>Would you like to receive e-mail notifications on our special
sales?</B>
<br>
<input type="radio" name="notify" value="Yes"
26 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
<%=[Link]("Yes")%>>Yes
<input type="radio" name="notify" value="No"
<%=[Link]("No")%>> No
<br><br></td>
</tr>
<tr bgcolor="lightblue">
<td colspan=2 align=center>
<input type="submit" value="Submit"> <input type="reset" value="Reset">
</td>
</tr>
</table>
</center>
</form>
</body>
</html>
27 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
Practical 7: Spring Framework
Aim :- Write a program to print “Hello World” using spring framework.
[Link]
package [Link];
public class HelloWorld {
private String message;
public void setMessage(String message){
[Link] = message;
}
public void getMessage(){
[Link]("Your Message : " + message);
}
}
[Link]
package [Link];
import [Link];
import [Link];
public class MainApp {
public static void main(String[] args) {
ApplicationContext context = new
FileSystemXmlApplicationContext("C:\\Users\\User\\eclipse-
workspace\\Spring\\src\\[Link]
");
HelloWorld obj = (HelloWorld) [Link]("helloWorld");
[Link]();
}
}
[Link]
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns = "[Link]
xmlns:xsi = "[Link]
28 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
xsi:schemaLocation = "[Link]
[Link]
<bean id = "helloWorld" class = "[Link]">
<property name = "message" value = "Hello World!"/>
</bean>
</beans>
OUTPUT
29 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
Practical 8: Spring JDBC
Aim: - Write a program to insert, update and delete records from the given table.
[Link] Class Student :
package [Link];
public class Student {
private Integer age;
private String name;
private Integer id;
public void setAge(Integer age) {
[Link] = age;
}
public Integer getAge() {
return age;
}
public void setName(String name) {
[Link] = name;
}
public String getName() {
return name;
}
public void setId(Integer id) {
[Link] = id;
}
public Integer getId() {
return id;
}
}
30 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
[Link] Class StudentMapper
package [Link];
import [Link];
import [Link];
import [Link];
public class StudentMapper implements RowMapper {
public Student mapRow(ResultSet rs, int rowNum) throws SQLException {
Student student = new Student();
[Link]([Link]("id"));
[Link]([Link]("name"));
[Link]([Link]("age"));
return student;
}
}
[Link] Class StudentDAO
package [Link];
import [Link];
import [Link];
31 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
public interface StudentDAO {
/**
* This is the method to be used to initialize
* database resources ie. connection.
*/
public void setDataSource(DataSource ds);
/**
* 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
* a record from the Student table corresponding
* to a passed student id.
*/
public Student getStudent(Integer id);
/**
* 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.
32 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
*/
public void delete(Integer id);
/**
* This is the method to be used to update
* a record into the Student table.
*/
public void update(Integer id, Integer age);
}
[Link] Class StudentJDBCTemplate
package [Link];
import [Link];
import [Link];
import [Link];
public class StudentJDBCTemplate implements StudentDAO {
private DataSource dataSource;
private JdbcTemplate jdbcTemplateObject;
public void setDataSource(DataSource dataSource) {
[Link] = dataSource;
[Link] = new JdbcTemplate(dataSource);
}
public void create(String name, Integer age) {
String SQL = "insert into Student (name, age) values (?,? )";
[Link]( SQL,new Object[]{name, age});
33 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
[Link]("Created Record Name = " + name + " Age = " + age);
return;
}
public Student getStudent(Integer id) {
String SQL = "select * from Student where id = ?";
Student student = (Student) [Link](SQL,
new Object[]{id}, new StudentMapper());
return student;
}
public List<Student> listStudents() {
String SQL = "select * from Student";
List <Student> students = [Link](SQL, new
StudentMapper());
return students;
}
public void delete(Integer id) {
String SQL = "delete from Student where id = ?";
[Link](SQL,new Object[]{id});
[Link]("Deleted Record with ID = " + id );
return;
}
public void update(Integer id, Integer age){
String SQL = "update Student set age = ? where id = ?";
[Link](SQL,new Object[]{age, id});
[Link]("Updated Record with ID = " + id );
return;
}
34 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
[Link] Class MainApp
package [Link];
import [Link];
import [Link];
import [Link];
public class MainApp {
public static void main(String[] args) {
//pplicationContext context = new
ClassPathXmlApplicationContext("C:\\Users\\spdc\\eclipse-
workspace\\demo\\JdbcTemplate\\src\\com\\jdbctemplate\\[Link]");
ApplicationContext context = new
FileSystemXmlApplicationContext("C:\\Users\\spdc\\eclipse-
workspace\\demo\\JdbcTemplate\\src\\com\\jdbctemplate\\[Link]");
StudentJDBCTemplate studentJDBCTemplate =
(StudentJDBCTemplate)[Link]("studentJDBCTemplate");
[Link]("------Records Creation--------" );
[Link]("Sachin", 11);
[Link]("Virat", 2);
[Link]("Dravid", 15);
[Link]("------Listing Multiple Records--------" );
List<Student> students = [Link]();
for (Student record : students) {
[Link]("ID : " + [Link]() );
[Link](", Name : " + [Link]() );
[Link](", Age : " + [Link]());
}
35 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
[Link]("----Updating Record with ID = 2 -----" );
[Link](2, 20);
[Link]("----Listing Record with ID = 2 -----" );
Student student = [Link](2);
[Link]("ID : " + [Link]() );
[Link](", Name : " + [Link]() );
[Link](", Age : " + [Link]());
}
}
[Link] [Link]
<?xml version = "1.0" encoding = "UTF-8"?>
<beans xmlns = "[Link]
xmlns:xsi = "[Link]
xsi:schemaLocation = "[Link]
[Link] ">
<!-- Initialization for data source -->
<bean id="dataSource"
class = "[Link]">
<property name = "driverClassName" value = "[Link]"/>
<property name = "url" value = "jdbc:mysql://localhost:3306/test"/>
<property name = "username" value = "root"/>
<property name = "password" value = "12345"/>
</bean>
<!-- Definition for studentJDBCTemplate bean -->
<bean id = "studentJDBCTemplate"
36 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
class = "[Link]">
<property name = "dataSource" ref = "dataSource" />
</bean>
</beans>
Output in eclipse :
Output in Mysql
37 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
38 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
Practical 9 : Spring Boot and RESTful Web Services
Aim : - Write a program to create a simple Spring Boot application that prints a message.
package [Link];
import [Link];
import [Link];
@RestController
public class HelloWorldController
{
@RequestMapping("/")
public String hello()
{
return "Hello javaTpoint";
}
}
package [Link];
import [Link];
import [Link];
@SpringBootApplication
public class SpringBootHelloWorldExampleApplication
{
public static void main(String[] args)
{
[Link]([Link], args);
}
}
Output:-
39 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])
lOMoARcPSD|57317643
NAVEEDH ALI MUHAMED ALI JINNA (168061)
40 | P a g e Subject:- MCAL12 – Advanced Java Lab
Downloaded by Mrs. Sayali Sumit Ghadge (ssghadge@[Link])