0% found this document useful (0 votes)
27 views42 pages

Advanced Java Lab Practical Journal

This document is a practical journal for the Advanced Java Lab course (MCAL12) submitted by Naveedh Ali M. Jinna for the Master's in Computer Application at the University of Mumbai. It includes various practical exercises demonstrating Java concepts such as Generics, List, Set, Map interfaces, Lambda Expressions, and Spring Framework. The journal outlines the objectives and code implementations for each practical task, showcasing the student's understanding of advanced Java programming techniques.

Uploaded by

ssghadge
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views42 pages

Advanced Java Lab Practical Journal

This document is a practical journal for the Advanced Java Lab course (MCAL12) submitted by Naveedh Ali M. Jinna for the Master's in Computer Application at the University of Mumbai. It includes various practical exercises demonstrating Java concepts such as Generics, List, Set, Map interfaces, Lambda Expressions, and Spring Framework. The journal outlines the objectives and code implementations for each practical task, showcasing the student's understanding of advanced Java programming techniques.

Uploaded by

ssghadge
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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]("") ||


![Link](password2))) {
[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])

Common questions

Powered by AI

Web applications benefit from using JSP declarations, scriptlets, and directives by allowing server-side processing of requests, embedding Java code within HTML, and defining reusable page-level components. For instance, a registration form can use HTML for the form layout, JSP scriptlets for embedding dynamic content processing, and directives for importing necessary Java packages or using beans. The form captures user inputs like `firstName`, `lastName`, and validates them using a bean `FormBean`, checking field requirements such as non-empty first and last names. The directives enable the page to interact with beans and forward the validated form to a success page .

A JSP program plays a critical role in the web application lifecycle by dynamically generating web pages based on user interactions, handling form submissions, and directing flow based on user inputs and server-side logic. It processes incoming data, interacts with server-side components, and incorporates JSP declarations, scriptlets, and directives to manage user input processing and feedback. For example, when a user submits a registration form, the JSP page captures the data, validates it using a bean (`FormBean`), and conditionally forwards the user to different pages (`success.jsp` or `retry.jsp`) based on validation results .

The process of initializing a Java `Map` involves creating a `HashMap` instance and inserting key-value pairs using the `put` method. Modifications include adding new entries, updating existing values, and removing entries. For example, initializing a map with `hm1.put(1, "Geeks")` adds the entry `1=Geeks`, updating can be done with `hm1.put(2, "For")`, and removing an entry uses `remove`, such as `hm1.remove(4)`, which deletes the key-value pair associated with `4`. These operations demonstrate the flexibility of the map interface in efficiently storing and managing key-value pairs, facilitating rapid data access and modification .

Spring Boot and RESTful Web Services are instrumental in building scalable web applications due to their efficient framework configurations and robust HTTP-based architecture. An example application might be an e-commerce platform where Spring Boot facilitates rapid development and deployment of microservices, while RESTful web services enable the platform to expose operations like product retrieval, order processing, and user management over the web, interacting with clients in a stateless architecture. This setup allows seamless scaling of the application by decoupling services, enabling independent scaling units and thus handling large volumes of traffic efficiently .

The Spring Framework facilitates the development of Java applications by providing a comprehensive programming and configuration model. An example of a "Hello World" program using Spring involves defining a `HelloWorld` class with a `message` property, setting the property value via XML configuration (in a `Beans.xml` file), and retrieving and printing this message using a Spring ApplicationContext. The `ApplicationContext` handles bean creation and dependency injection, executing `obj.getMessage()` to print "Hello World!". This setup demonstrates Spring's capabilities in reducing boilerplate code and enhancing modularity and maintainability through its inversion of control and dependency injection features .

The key operations performed using Java's `Set` interface include adding items, removing items, union, intersection, and difference operations. For example, given two sets instantiated with arrays, `set1` and `set2`, union can be achieved by adding all elements from both sets into a new set `union_data`, intersection by retaining elements common to both sets in `intersection_data`, and difference by removing elements of one set from another in `difference_data`. These operations allow efficient management of unique data collections, ensuring no duplicates and enabling efficient data retrieval and manipulation .

Lambda expressions in Java enhance code readability and maintainability by enabling more concise and expressive code, particularly in scenarios involving functional interfaces. They simplify the syntax for representing instances of single-method interfaces as a series of expressions. For example, instead of implementing an interface using an anonymous class, a lambda expression can directly specify the behavior needed, such as `SayHello hello = () -> {System.out.println("Hello World");};`. This reduces verbosity and clarifies intent by focusing on the function's purpose rather than its structure, enhancing code clarity and reducing boilerplate .

In Java, `List` and `Set` are distinct in that a `List` is an ordered collection allowing duplicate elements, while a `Set` is an unordered collection that prohibits duplicates. This means that `Lists` are preferable when the order of elements must be preserved, such as maintaining a list of tasks, while `Sets` are ideal for scenarios where uniqueness is crucial, like storing user IDs. Operations like adding multiple identical items will differ: `List` allows all entries whereas `Set` prevents duplicates. This affects manipulation tasks such as searching and adding elements, determining whether to prioritize order or uniqueness in data management .

JSP directives enhance a web application's configurability and performance by allowing global setup of JSP page attributes and resources. They control the page processing environment, import Java classes, manage includes, and configure error handling. For instance, the `page` directive can specify content types, language, and buffer size, optimizing performance by tailoring the page's behavior to specific needs. The `include` directive allows reusable content or code to be inserted, reducing redundancy. These capabilities enable fine-tuning of application environments, thereby enhancing modularity and processing efficiency .

Java generics enhance code flexibility and reuse by allowing classes, interfaces, and methods to operate on parameters of various types, eliminating the need for type casting and letting the same code work with different data types. For instance, a generic class `Test<T>` can be instantiated with different data types such as `Integer` and `String`. When instantiated with `Integer`, the object can hold integer values, e.g., `new Test<Integer>(169593)`, and similarly for `String`, e.g., `new Test<String>("Pratibha")` . This mechanism provides type safety and reduces the overhead of type casting.

You might also like