AJP Praticals Dhvanit
AJP Praticals Dhvanit
AJP Praticals Dhvanit
Laboratory Manual
(Advanced JAVA Programming)
4351603
Information Technology 5th Semester
Enrollment No. 226170316152
Name Vara Dhvanit M.
Branch Information Technology
Academic Term 2024-25
Institute Government Polytechnic
Ahamedabad
DTE’s Vision:
● To provide globally competitive technical education;
● Remove geographical imbalances and inconsistencies;
● Develop student friendly resources with a special focus on girls’ education
and support to weaker sections;
● Develop programs relevant to industry and create a vibrant pool of technical
professionals.
DTE’s Mission:
Quality technical and professional education with continuous improvement of all the
resources and personnel
Institute’s Vision:
To be a leading technical institute that provides transformative education to learners for achieving
competency as per the needs of industry and society, thus contributing to nation building.
Institute’s Mission:
Department’s Vision:
Department’s Mission:
The graduates of our department will be efficient in technical and ethical responsibilities to
become globally recognised by pursuing opportunities for higher studies and real time
problem solving.
Project development in association with the Government, Industries and Professionals will
be done that can meet industrial needs.
Students will be competent by learning the principals of Information technology that can
match national and international standards.
Advanced JAVA Programming (4351603)
Certificate
Place:……………..
Date: …………………..
Preface
The primary aim of any laboratory/Practical/field work is enhancement of required skills as well
as creative ability amongst students to solve real time problems by developing relevant competencies in
psychomotor domain. Keeping in view, GTU has designed competency focused outcome-based
curriculum -2021 (COGC-2021) for Diploma engineering programmes. In this more time is allotted to
practical work than theory. It shows importance of enhancement of skills amongst students and it pays
attention to utilize every second of time allotted for practical amongst Students, Instructors and Lecturers
to achieve relevant outcomes by performing rather than writing practice in study type. It is essential for
effective implementation of competency focused outcome- based Green curriculum-2021. Every
practical has been keenly designed to serve as a tool to develop & enhance relevant industry needed
competency in each and every student. These psychomotor skills are very difficult to develop through
traditional chalk and board content delivery method in the classroom. Accordingly, this lab manual has
been designed to focus on the industry defined relevant outcomes, rather than old practice of conducting
practical to prove concept and theory.
By using this lab manual, students can read procedure one day in advance to actual performance
day of practical experiment which generates interest and also, they can have idea of judgement of
magnitude prior to performance. This in turn enhances predetermined outcomes amongst students. Each
and every Experiment /Practical in this manual begins by competency, industry relevant skills, course
outcomes as well as practical outcomes which serve as a key role for doing the practical. The students
will also have a clear idea of safety and necessary precautions to be taken while performing experiments.
This manual also provides guidelines to lecturers to facilitate student-centered lab activities for
each practical/experiment by arranging and managing necessary resources in order that the students
follow the procedures with required safety and necessary precautions to achieve outcomes. It also gives
an idea of how students will be assessed by providing Rubrics.
This course provides the knowledge necessary to develop dynamic web pages using Servlet, JSP,
MVC web frameworks and hibernate. It covers the basic underlying concepts and techniques recently
used in the IT industry. After going through this course students will be able to design MVC based Web
applications.
Although we try our level best to design this lab manual, there are always chances of
improvement. We welcome any suggestions for improvement.
Advanced JAVA Programming (4351603)
7. Life-long learning: Ability to analyze individual needs and engage in updating in the
context of technological changes in field of engineering.
Advanced JAVA Programming (4351603)
1.
Develop a GUI program by using
one swing button and adding it
√ - - - -
on the JFrame object
2.
Develop a program to create
checkboxes for different courses
belonging to a university such
that the course selected would √ - - - -
be displayed.
3.
Develop a program to Implement
Traffic signal(Red, Green and
Yellow) by using Swing
components ( Using JFrame, √ - - - -
JRadioButton, ItemListener etc.)
1. Organize the work in the group and make a record of all observations.
2. Students shall develop maintenance skills as expected by industries.
3. Students shall attempt to develop related hand-on skills and build
confidence.
4. Students shall develop the habits of evolving more ideas, innovations, skills
etc.
5. Students shall refer to technical magazines and data books.
6. Students should develop the habit to submit the practical on date and time.
7. Students should prepare well while submitting a write-up of exercise.
8 | Page
Advanced JAVA Programming (4351603)
1
Develop a GUI program by using one swing button and
adding it on the JFrame object
2
Develop a program to create checkboxes for different
courses belonging to a university such that the course
selected would be displayed.
5
Develop a program using JDBC to edit (insert, update,
delete) Student’s profile stored in the database
7
Develop a simple servlet program which maintains a
counter for the number of times it has been accessed
since its loading; initialize the counter using
deployment descriptor.
9 | Page
Advanced JAVA Programming (4351603)
8
Create a web form which processes servlet and
demonstrates use of cookies and sessions.
10
Develop a JSP web application to display student
monthly attendance in each subject of current
semester via enrollment number.
11
Develop a JSP web application to select shopping
products, buy any products and product billing page
using session management.
12
Develop a JSP program for student registration for
new admission in college and display stored data into
admin dashboard.
10 | Page
Advanced JAVA Programming (4351603) Dhvanit Vara (226170316152)
Practical: 1 Develop a GUI program by using one swing button and adding it on the
JFrame object.
Code:
import javax.swing.*;
import java.awt.*;
public class p1 {
public static void main(String[] args) {
h.setForeground(Color.white);
f.add(h);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(3000, 800);
f.setLayout(null);
f.setVisible(true);
}
}
Advanced JAVA Programming (4351603) Dhvanit Vara (226170316152)
Assessment-Rubrics
Faculty
Date
Signature
Marks Obtained
Program Total
correctness Implementation Studnet’s
and Presentation engagement in (10)
(4) Methodology practical activities
R1 (3) (3)
R2 R3
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public p2() {
// Create checkboxes for courses
String[] courses = { "MCN", "AJP", "AIML", "start up" };
checkBoxes = new JCheckBox[courses.length];
selectedCoursesTextArea.setText(selectedCourses.toString());
}
Output:
Assessment-Rubrics
Faculty
Date
Signature
Marks Obtained
Program Total
correctness Implementation Studnet’s
and Presentation engagement in (10)
(4) Methodology practical activities
R1 (3) (3)
R2 R3
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public p3() {
setTitle("Traffic Signal");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());
redButton.addItemListener(this);
greenButton.addItemListener(this);
yellowButton.addItemListener(this);
add(redButton);
add(greenButton);
add(yellowButton);
add(signalLabel);
pack();
setVisible(true);
}
Output:
Advanced JAVA Programming (4351603) Dhvanit Vara (226170316152)
Assessment-Rubrics
Faculty
Date
Signature
Marks Obtained
Program Total
correctness Implementation Studnet’s
and Presentation engagement in (10)
(4) Methodology practical activities
R1 (3) (3)
R2 R3
Code:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
Output:
Advanced JAVA Programming (4351603) Dhvanit Vara (226170316152)
Assessment-Rubrics
Faculty
Date
Signature
Marks Obtained
Program Total
correctness Implementation Studnet’s
and Presentation engagement in (10)
(4) Methodology practical activities
R1 (3) (3)
R2 R3
Code:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;
public class pr5 {
public static void main(String[] args) {
String jdbcUrl = "jdbc:mysql://localhost:3306/StudentDB";
String user = "root";
String password = "Ridham4580";
try {
Connection connection = DriverManager.getConnection(jdbcUrl, user, password);
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("Choose an operation:");
System.out.println("1. Insert Student Profile");
System.out.println("2. Update Student Profile");
System.out.println("3. Delete Student Profile");
System.out.println("4. Exit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
scanner.nextLine();
switch (choice) {
case 1:
insertStudentProfile(connection, scanner);
break;
case 2:
updateStudentProfile(connection, scanner);
break;
case 3:
deleteStudentProfile(connection, scanner);
break;
case 4:
System.out.println("Exiting the program.");
connection.close();
System.exit(0);
break;
default:
System.out.println("Invalid choice. Please try again.");
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
Advanced JAVA Programming (4351603) Dhvanit Vara (226170316152)
preparedStatement.setLong(1, enrollNo);
int rowsAffected = preparedStatement.executeUpdate();
if (rowsAffected > 0) {
System.out.println("Student profile deleted successfully.");
} else {
System.out.println("No student profile found for the given Enroll_No.");
}
}
}
Output:
1. Insert in database
2. Update Name
Assessment-Rubrics
Faculty
Date
Signature
Marks Obtained
Program Total
correctness Implementation Studnet’s
and Presentation engagement in (10)
(4) Methodology practical activities
R1 (3) (3)
R2 R3
package com.employeeapp.dao;
import java.util.List;
import com.employeeapp.model.User;
import com.employeeapp.model.User;
public class HibernateConf {
private static SessionFactory factory;
private HibernateConf() {
}
public static SessionFactory getFactory() {
if (factory == null) {
Configuration configuration = new Configuration();
Properties settings = new Properties();
settings.put("hibernate.connection.driver_class", "com.mysql.cj.jdbc.Driver");
settings.put("hibernate.connection.url", "jdbc:mysql://localhost:3306/StudentDB");
settings.put("hibernate.connection.username", "root");
settings.put("hibernate.connection.password", "Ridham4580");
settings.put("hibernate.dialect", "org.hibernate.dialect.MySQL8Dialect");
settings.put("hibernate.show_sql", "true");
settings.put("hibernate.hbm2ddl.auto", "update");
configuration.setProperties(settings);
configuration.addAnnotatedClass(User.class);
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties())
.build();
factory = configuration.buildSessionFactory(serviceRegistry);
}
return factory;
}
}
}
return user;
}
@Override
public List<User> getAllUsers() {
Transaction transaction = null;
List<User> users = null;
try (Session session = factory.openSession()) {
transaction = session.beginTransaction();
users = session.createQuery("from User", User.class).getResultList();
transaction.commit();
} catch (Exception e) {
}
return users;
}
@Override
public void updateUser(User user) {
Transaction transaction = null;
try (Session session = factory.openSession()) {
Advanced JAVA Programming (4351603) Dhvanit Vara (226170316152)
transaction = session.beginTransaction();
session.merge(user);
transaction.commit();
} catch (Exception e) {
}
}
@Override
public void deleteUserById(long id) {
Transaction transaction = null;
try (Session session = factory.openSession()) {
transaction = session.beginTransaction();
User user = session.get(User.class, id);
if (user != null) {
session.remove(user);
}
transaction.commit();
} catch (Exception e) {
}
}
}
Output:
Advanced JAVA Programming (4351603) Dhvanit Vara (226170316152)
Assessment-Rubrics
Faculty
Date
Signature
Marks Obtained
Program Total
correctness Implementation Studnet’s
and Presentation engagement in (10)
(4) Methodology practical activities
R1 (3) (3)
R2 R3
Code:
File Name: - CounterServlet.java
package servlets;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
Output:
Advanced JAVA Programming (4351603) Dhvanit Vara (226170316152)
Assessment-Rubrics
Faculty
Date
Signature
Marks Obtained
Program Total
correctness Implementation Studnet’s
and Presentation engagement in (10)
(4) Methodology practical activities
R1 (3) (3)
R2 R3
Code:
package servlets;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class practical8 extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String username = request.getParameter("username");
String password = request.getParameter("password");
HttpSession session = request.getSession();
session.setAttribute("username", username);
session.setAttribute("password", password);
Cookie usernameCookie = new Cookie("username", username);
usernameCookie.setMaxAge(3600);
response.addCookie(usernameCookie);
response.sendRedirect("result.jsp");
}
}
<!DOCTYPE html>
<html>
<head><title>Registration Form</title></head>
<body>
<h1>Registration Form</h1>
<form action="practical8" method="POST">
<label for="username">Username:</label>
<input type="text" name="username" required /><br />
<label for="password">Password:</label>
<input type="password" name="password" required /><br />
<input type="submit" value="Register" />
</form>
</body>
</html>
File Name: - result.jsp
<!DOCTYPE html>
<html>
<head>
<title>Registration Successful</title>
</head>
<body>
Advanced JAVA Programming (4351603) Dhvanit Vara (226170316152)
<h1>Registration Successful</h1>
<p>Thank you for registering, ${sessionScope.username}!</p>
<p>Your username is also stored in a cookie.</p>
</body>
</html>
Output:
Advanced JAVA Programming (4351603) Dhvanit Vara (226170316152)
Assessment-Rubrics
Faculty
Date
Signature
Marks Obtained
Program Total
correctness Implementation Studnet’s
and Presentation engagement in (10)
(4) Methodology practical activities
R1 (3) (3)
R2 R3
Practical 9: Develop a web form which processes servlet for user login functionality.
Code:
File Name: - practical9.java
package servlets;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class practical9 extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String username = request.getParameter("username");
String password = request.getParameter("password");
if (username.equals("Manav") && password.equals("saliya123")) {
HttpSession session = request.getSession();
session.setAttribute("username", username);
response.sendRedirect("welcome.jsp");
} else {
response.sendRedirect("index.html");
}
}
}
Output:
Advanced JAVA Programming (4351603) Dhvanit Vara (226170316152)
Assessment-Rubrics
Faculty
Date
Signature
Marks Obtained
Program Total
correctness Implementation Studnet’s
and Presentation engagement in (10)
(4) Methodology practical activities
R1 (3) (3)
R2 R3
Code:
AJP Dhvanit Vara (226170316152)
AJP Dhvanit Vara (226170316152)
Assessment-Rubrics
Faculty
Date
Signature
Marks Obtained
Program Total
correctness Implementation Studnet’s
and Presentation engagement in (10)
(4) Methodology practical activities
R1 (3) (3)
R2 R3
Code:
AJP Dhvanit Vara (226170316152)
AJP Dhvanit Vara (226170316152)
AJP Dhvanit Vara (226170316152)
AJP Dhvanit Vara (226170316152)
AJP Dhvanit Vara (226170316152)
Output:
Index.jsp
Product.jsp
Cart.jsp
AJP Dhvanit Vara (226170316152)
Billing.jsp
Logout.jsp
AJP Dhvanit Vara (226170316152)
Assessment-Rubrics
Faculty
Date
Signature
Marks Obtained
Program Total
correctness Implementation Studnet’s
and Presentation engagement in (10)
(4) Methodology practical activities
R1 (3) (3)
R2 R3
Practical 12: Develop a JSP program for student registration for new
admission in college and display stored data it into admin dashboard.
Code:
AJP Dhvanit Vara (226170316152)
AJP Dhvanit Vara (226170316152)
AJP Dhvanit Vara (226170316152)
Output:
registration.jsp
registered.jsp
AJP Dhvanit Vara (226170316152)
admin.jsp
AJP Dhvanit Vara (226170316152)
Assessment-Rubrics
Faculty
Date
Signature
Marks Obtained
Program Total
correctness Implementation Studnet’s
and Presentation engagement in (10)
(4) Methodology practical activities
R1 (3) (3)
R2 R3
Output:
AJP Dhvanit Vara (226170316152)
Assessment-Rubrics
Faculty
Date
Signature
Marks Obtained
Program Total
correctness Implementation Studnet’s
and Presentation engagement in (10)
(4) Methodology practical activities
R1 (3) (3)
R2 R3