0% found this document useful (0 votes)
4 views20 pages

Java Programming: Generics, Collections, and JSP

The document outlines a series of Java experiments demonstrating various programming concepts including Generics, Collections (List, Set, Map), Lambda Expressions, and JSP. Each experiment includes a specific aim, code implementation, and output results. Additionally, it provides an index of topics covered in the course related to advanced Java programming.

Uploaded by

Jay Agrawal
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)
4 views20 pages

Java Programming: Generics, Collections, and JSP

The document outlines a series of Java experiments demonstrating various programming concepts including Generics, Collections (List, Set, Map), Lambda Expressions, and JSP. Each experiment includes a specific aim, code implementation, and output results. Additionally, it provides an index of topics covered in the course related to advanced Java programming.

Uploaded by

Jay Agrawal
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

EXPERIMENT: 01

AIM: Write a java program to demonstrate a Generic Class, Generic Methods, and
Wildcards.

// Class Formation
class Generic<T> {
private T info;

// Constructor
public Generic(T info) {
[Link] = info;
}

// Getter method
public T getInfo() {
return info;
}

// Setter method
public void setInfo(T info) {
[Link] = info;
}

// Generic method to display type of value


public <U> void display(U item) {
[Link]("DataType of value: " + [Link]().getName());
}
}

public class GenericDemo {

// Wildcards
public static void printValue(Generic<?> object) {
[Link]("Wildcards Contains: " + [Link]());
}

public static void main(String[] args) {


// Functionality of generic class
Generic<Integer> intObj = new Generic<>(10);
[Link]("Data Contained: " + [Link]());

Generic<String> strObj = new Generic<>("Aayushii");


[Link]("Data Contained: " + [Link]());

// Functionality of Generic method


[Link](1000);
[Link]("Advanced Java");
// Demonstration of Wildcards
printValue(intObj);
printValue(strObj);
}
}
OUTPUT:

Data Contained: 10
Data Contained: Aayushii
DataType of value: [Link]
DataType of value: [Link]
Wildcards Contains: 10
Wildcards Contains: Aayushii
EXPERIMENT: 02

AIM: Write a java program to create List, containing list of items of type String and use
for-loop, Iterator Interface, List Iterator interface to print the items of the list.

import [Link];
import [Link];
import [Link];
import [Link];
public class File{
public static void main(String[] args){
List<String> var1= new ArrayList<String> ();
[Link]("Aayushi");
[Link]("Samraddhi");
[Link]("Abhisar");
//print with help of loop
[Link]("Elements are:");
for(String item : var1){
[Link](item);
}

//print with help of iterator


[Link]("Elements using iterator:");
Iterator <String> i= [Link]();
while ([Link]()){
[Link]([Link]());
}

// print with help of List Iterator interface


[Link]("Elements by using ListIterator (Forward):");
ListIterator <String> l= [Link]();
while([Link]()){
[Link]([Link]());
}

[Link]("Elements by ListIterator (Backwards):");


while ([Link]()){
[Link]([Link]());

}
}
}
OUTPUT:

Elements are:
Aayushi
Samraddhi
Abhisar
Elements using iterator:
Aayushi
Samraddhi
Abhisar
Elements by using ListIterator (Forward):
Aayushi
Samraddhi
Abhisar
Elements by ListIterator (Backwards):
Abhisar
Samraddhi
Aayushi
EXPERIMENT: 03

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 into another set.
c) Remove items from the set.
d) Search the specified item in the set.

import [Link].*;
public class File3{
public static void main(String [] args){
// Hashset usage
Set <String> hashset1= new HashSet<>();
Set <String> hashset2= new HashSet<> ();
//To add items to set
[Link]("Aayushii");
[Link]("Samraddhi");
[Link]("Aditi");
[Link]("Avani");
[Link]("Harshili");
[Link]("Aashi");
[Link]("Abhisar");
[Link]("Aayush");
[Link]("Aayan");
[Link]("Set 1:"+ hashset1);
[Link]("Set 2:"+ hashset2);

//Insert elements of one set into another:


[Link](hashset2);
[Link]("New set is:"+ hashset1);
//Now to remove:
[Link]("Harshili");
[Link]("Abhisar");
[Link]("Updated is:" +hashset1);
//Now to search
String item="Aayushii";
if([Link](item)){
[Link]("Yes it contains "+ item);
}
else{
[Link]("It doesn't contain" +item);

}
}
OUTPUT:

Set 1:[Harshili, Aayushii, Samraddhi, Aditi, Avani]


Set 2:[Aashi, Aayan, Abhisar, Aayush]
New set is:[Aashi, Harshili, Aayan, Aayushii, Samraddhi, Aditi, Abhisar, Aayush, Avani]
Updated is:[Aashi, Aayan, Aayushii, Samraddhi, Aditi, Aayush, Avani]
Yes it contains Aayushii
EXPERIMENT: 04

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 specified key in the map.
d) Get value of that specified key.
e) Insert map elements of one map to Another Map.
f) Print all keys and values of the map.

import [Link].*;
public class File4{
public static void main(String [] args){
Map<String, String> obj1= new HashMap<>();
Map<String, String> obj2= new HashMap<>();
[Link]("Aayushi", "Sec A");
[Link]("Abhisar", "Sec A");
[Link]("Samraddhi", "C8");
[Link]("Bhumit", "C8");
[Link]("Rohit", "C8");
[Link]("Map 1:" + obj1);
[Link]("Map 2" + obj2);
[Link]("Abhisar");
[Link]("New Map:" + obj1);
String item= "Aayushi" ;
if([Link](item)){
[Link]("Yes we have" +item);
}
else{
[Link]("Couldn't find" + item);
}

String data= "Aayushi";


String value= [Link](data);
if(value!=null){
[Link]("The Key is" + value);
}
else{
[Link]("Couldn't find" + value);
}

[Link](obj2);
[Link]("Final Elements:" + obj1);
}
}
OUTPUT:

Map 1:{Aayushi=Sec A, Abhisar=Sec A, Samraddhi=C8}


Map 2{Rohit=C8, Bhumit=C8}
New Map:{Aayushi=Sec A, Samraddhi=C8}
Yes we have Aayushi
The Key is Sec A
Final Elements: {Rohit=C8, Aayushi=Sec A, Samraddhi=C8, Bhumit=C8}
EXPERIMENT:05

AIM: Implement Java program using Lambda Expressions to add two numbers and
concatenate two strings.

// Functional interface for operation


interface AddOperation {
int operate(int a, int b);
}

// Functional interface for string concatenation


interface ConcatenateOperation {
String concatenate(String s1, String s2);
}

public class LambdaExpressions {


public static void main(String[] args) {
// Lambda expression to add two numbers
AddOperation addOperation = (a, b) -> a + b;

// Lambda expression to concatenate two strings


ConcatenateOperation concatenateOperation = (s1, s2) -> s1 + s2;

// Test the operations


[Link]("Addition: " + [Link](53, 63));
[Link]("Concatenation: " + [Link]("Aayushii",
"Shah"));
}
}
OUTPUT:

Addition: 116
Concatenation: AayushiiShah
EXPERIMENT: 06

AIM: Write a JSP page to display the Registration form.

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-


8" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration Form</title>
</head>
<body>
<h2>Registration Form</h2>

<form action="registration_process.jsp" method="post">


<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br><br>

<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br><br>

<label for="password">Password:</label>
<input type="password" id="password" name="password" required><br><br>

<input type="submit" value="Register">


</form>
</body>
</html>
OUTPUT:
EXPERIMENT: 07

AIM: Write a JSP program to add, delete and display the records from Student Master
(Roll No, Name, Semester, Course) table.

public class Student {


private int rollNo;
private String name;
private int semester;
private String course;
// Constructors, getters, and setters }
import [Link];
import [Link];

public class StudentDao {


private static List<Student> students = new ArrayList<>();

static {
// Add some sample data
[Link](new Student(1, "John Doe", 1, "Computer Science"));
[Link](new Student(2, "Jane Smith", 2, "Electrical Engineering"));
}

public static List<Student> getAllStudents() {


return students;
}

public static void addStudent(Student student) {


[Link](student);
}

public static void deleteStudent(int rollNo) {


[Link](student -> [Link]() == rollNo);
}
}

Create the JSP page ([Link]):

<%@ page language="java" contentType="text/html; charset=UTF-8"


pageEncoding="UTF-8"%>
<%@ page import="[Link]" %>
<%@ page import="[Link]" %>
<%@ page import="[Link]" %>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Student Management</title>
</head>
<body>

<h2>Student Management</h2>
<h3>Student List</h3>
<table border="1">
<tr>
<th>Roll No</th>
<th>Name</th>
<th>Semester</th>
<th>Course</th>
<th>Action</th>
</tr>
<%
List<Student> students = [Link]();
for (Student student : students) {
%>
<tr>
<td><%= [Link]() %></td>
<td><%= [Link]() %></td>
<td><%= [Link]() %></td>
<td><%= [Link]() %></td>
<td><a href="[Link]?action=delete&rollNo=<%=
[Link]() %>">Delete</a></td>
</tr>
<%
}
%>
</table>

<h3>Add Student</h3>
<form action="[Link]?action=add" method="post">
Roll No: <input type="text" name="rollNo" required><br>
Name: <input type="text" name="name" required><br>
Semester: <input type="text" name="semester" required><br>
Course: <input type="text" name="course" required><br>
<input type="submit" value="Add Student">
</form>

<%
String action = [Link]("action");
if ("add".equals(action)) {
// Handle adding a new student
int rollNo = [Link]([Link]("rollNo"));
String name = [Link]("name");
int semester = [Link]([Link]("semester"));
String course = [Link]("course");

[Link](new Student(rollNo, name, semester, course));


[Link]("[Link]");
} else if ("delete".equals(action)) {
// Handle deleting a student
int rollNo = [Link]([Link]("rollNo"));
[Link](rollNo);
[Link]("[Link]");
}
%>

</body>
</html>
OUTPUT:
MEDICAPS UNIVERSITY INDORE

DEPARTMENT OF COMPUTER SCIENCE


ENGINEERING

SUBJECT NAME: ADVANCED JAVA


PROGRAMMING
SUBJECT CODE: CS3CO37
SESSION: 2025-2026

SUBMITTED TO: SUBMITTED BY:


Prof. Ankita Chourasia Mam Aayushi Shah Jain
(EN23CS301034)
4A
INDEX

[Link]. Description Date of Experiment Date of Remarks


Submission

1. Write a Java Program to


demonstrate a Generic Class,
Generic methods, and
wildcards.
2. Write a Java program to
create List containing list of
items of type String and use
for-each loop, Iterator
interface, List Iterator
interface to print the items of
the list.
3. Write a Java program using
Set interface containing list
of items and perform
operations.
4. Write a Java program using
Map interface containing list
of items having keys and
associated values and
perform operations.
5. Write a Java program using
Lambda Expression with
multiple parameters to add
two numbers and to
concatenate two strings.
6. Write a JSP page to display
the Registration form.

7. Write a JSP program to add,


delete and display the
records from Student Master
(Roll No, Name, Semester,
Course) table.
8. Write a JSP program that
demonstrates the use of JSP
declaration, script let,
directives
9. Design loan calculator using
JSP which accepts Period of
Time (in years) and Principal
Loan Amount. Display the
payment amount for each
loan
10. Write a program to
demonstrate get and post
method using servlets?
11. Write a program to print
“Hello World” using spring
framework
12. Write a program to
demonstrate dependency
injection via setter method.
13. Write a program to
demonstrate Prepared
Statement in Spring
JdbcTemplate.

You might also like