JAVA

Download as pdf or txt
Download as pdf or txt
You are on page 1of 68

Diploma Engineering

Laboratory Manual
(Advanced JAVA Programming)
4351603
Information Technology 5th Semester
Enrollment No.
Name
Branch
Academic Term
Institute

Directorate Of Technical Education


Gandhinagar - Gujarat
Advanced JAVA Programming (4351603)

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:

Institute’s Vision:

Institute’s Mission:

Department’s Vision:

Department’s Mission:
Advanced JAVA Programming (4351603)

Certificate

This is to certify that Mr./Ms …………………………………………………………………………………………………….


Enrollment No. ………….……………. of …….………. Semester of Diploma
in……………………………………………………………………………………………………….……………………………….. of
………………………………………………………………………. (GTU Code) has satisfactorily completed the
term work in course “Advanced JAVA Programming (4351603)” for the academic year:
…………………… Term: Odd prescribed in the GTU curriculum.

Place:…………………..

Date: …………………..

Signature of Course Faculty Head of the Department


Advanced JAVA Programming (4351603)

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.

3 | Page
Advanced JAVA Programming (4351603)

Programme Outcomes (POs):

1. Basic and Discipline specific knowledge: Apply knowledge of basic mathematics,


science and engineering fundamentals and engineering specialization to solve the
engineering problems.

2. Problem analysis: Identify and analyse well-defined engineering problems using


codified standard methods.

3. Design/ development of solutions: Design solutions for engineering well-defined


technical problems and assist with the design of systems components or processes to
meet specified needs.

4. Engineering Tools, Experimentation and Testing: Apply modern engineering tools


and appropriate technique to conduct standard tests and measurements.

5. Engineering practices for society, sustainability and environment: Apply


appropriate technology in context of society, sustainability, environment and ethical
practices.

6. Project Management: Use engineering management principles individually, as a


team member or a leader to manage projects and effectively communicate about well-
defined engineering activities.

7. Life-long learning: Ability to analyze individual needs and engage in updating in the
context of technological changes in field of engineering.

4 | Page
Advanced JAVA Programming (4351603)

Practical Outcome - Course Outcome matrix


Course Outcomes (COs):

CO1. Develop a GUI application using swing components.


CO2. Apply ORM based Methodology for Application Development.
CO3. Develop Web Applications using Servlets and deploy in popular servers like Tomcat
CO4. Develop JSP based applications with database connectivity.
CO5. Apply MVC architecture using Spring framework.

CO1 CO2 CO3 CO4 CO5


Sr. Practical Outcome/Title of
No. experiment

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.)

4. Develop a program using JDBC


to display student’s record
(Enroll No, Name, Address,
Mobile No,and Email-ID) into
- √ - - -
table ‘StuRec’

5 | Page
Advanced JAVA Programming (4351603)

5. Develop a program using JDBC


to edit (insert, update, delete)
Student’s profile stored in the
database
- √ - - -

6. Develop an application to store,


update, fetch and delete data of
Employee (NAME, AGE, SALARY
and DEPARTMENT) using
- √ - - -
Hibernate CRUD operations.
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.
8.
Create a web form which
processes servlet and
demonstrates use of cookies
and sessions.
- - √ - -

Develop a web form which √


9.
processes servlet for user login
functionality
Develop a JSP web application √
10.
to display student monthly
attendance in each subject of
current semester via
enrollment number.

Develop a JSP web application √


11.
to select shopping products,
buy any products and product
billing page using session
management.

6 | Page
Advanced JAVA Programming (4351603)

Develop a JSP program for √


12.
student registration for new
admission in college and display
stored data into admin
dashboard.

Develop a Web MVC √


13.
Architecture based application
to provide user Login and
Register using Spring Boot.

7 | Page
Advanced JAVA Programming (4351603)

Industry Relevant Skills


The following industry relevant skills are expected to be developed in the
students by performance of experiments of this course.

1. Analytical and logical thinking.


2. Project management, Team-based working, communication skill
3. Creativity & Design ability
4. Effective Analysis and Organizing.

Guidelines to Course Faculty


1. Course faculty should demonstrate experiment with all necessary
implementation strategies described in the curriculum.
2. Course faculty should explain industrial relevance before starting each
experiment.
3. Course faculty should Involve & give opportunity to all students for hands-on
experience.
4. Course faculty should ensure mentioned skills are developed in the students
by asking.
5. Utilise 2 hrs of lab hours effectively and ensure completion of write up with
quiz also.
6. Encourage peer to peer learning by doing the same experiment through fast
learners.

Instructions for Students

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)

Continuous Assessment Sheet


Enrolment No: Batch:
Name: Term:

Sr. Practical Outcome/Title of experiment Page Date Marks


(10) Sign
no No.

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.

Develop a program to Implement Traffic signal(Red,


3
Green and Yellow) by using Swing components ( Using
JFrame, JRadioButton, ItemListener etc.)

4 Develop a program using JDBC to display student’s


record (Enroll No, Name, Address, Mobile No,and
Email-ID) into table ‘StuRec’

5
Develop a program using JDBC to edit (insert, update,
delete) Student’s profile stored in the database

6 Develop an application to store, update, fetch and


delete data of Employee (NAME, AGE, SALARY and
DEPARTMENT) using Hibernate CRUD operations.

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.

9 Develop a web form which processes servlet for user


login functionality

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.

13 Develop a Web MVC Architecture based application


to provide user Login and Register using Spring Boot.

10 | Page
Advanced JAVA Programming (4351603)

Date: ……………

Practical Develop a GUI program by using one swing button and adding it on the JFrame
No:1 object.

A. Objective: Understand Java Swing's JButton and JFrame objects and implement graphical
user interface (GUIs) for Java applications.

B. Expected Program Outcomes (POs)


Po1 - Basic and Discipline specific knowledge.
Po2 - Problem analysis.
Po3 - Design/ development of solutions.
Po4 - Engineering Tools, Experimentation and Testing.
Po5 - Engineering practices for society, sustainability and environment.
Po6 - Project Management.
Po7 - Lifelong learning.
C. Expected Skills to be developed based on competency:
This practical is expected to develop the following skills for the industry identified
competency:
1. Understand Java Swing GUI.
2. Write a code based on Java Swing framework.
D. Expected Course Outcomes (Cos)
CO-1: Develop a GUI application using swing components.
E. Practical Outcome (PRo)
Students will be able to develop GUI programs by using swing button and
frame.
F. Expected Affective domain Outcome (ADos)
1. Follow precautionary measures.
2. Follow Coding standards and practices.
3. Demonstrate working as a leader or two members.
4. Follow ethical practices.

11 | Page
Advanced JAVA Programming (4351603)

G. Prerequisite Theory:

Java Swing: Java Swing is a set of GUI (Graphical User Interface) components and
related classes provided by Java to create rich and interactive user interfaces for
desktop applications. Swing is built on top of the Abstract Window Toolkit (AWT) and
offers a more extensive and customizable set of components compared to AWT. It
provides a platform-independent way to create graphical applications, as it is part of
the Java Standard Edition (Java SE) and works on various operating systems without
any modifications.

Swing components are lightweight and offer a consistent look and feel across different
platforms, ensuring that the GUI behaves similarly on Windows, macOS, Linux, and
other supported systems. Some of the key features and benefits of Swing include:

1. Lightweight: Swing components are lightweight because they are implemented in


Java and do not rely on the underlying operating system's GUI components like
AWT. This allows for better performance and a more consistent user experience
across platforms.
2. Rich Component Library: Swing provides a wide range of GUI components,
including buttons, labels, text fields, checkboxes, radio buttons, menus, dialogs,
and more. These components can be customized and combined to create complex
user interfaces.
3. Customizability: Swing components can be easily customized in terms of
appearance and behavior. Developers can set various properties to control the look
and behavior of the components to match the application's design and
requirements.
4. Layout Management: Swing offers different layout managers (e.g., BorderLayout,
GridLayout, FlowLayout, etc.) to help arrange components in a GUI and ensure they
resize and reposition correctly when the window is resized.
5. Event Handling: Swing provides event-driven programming, allowing developers to
handle user interactions, such as button clicks, mouse movements, and keypresses,
through event listeners.
6. MVC Architecture: Swing follows the Model-View-Controller (MVC) design pattern,
which promotes a clear separation of concerns between the data, user interface,
and application logic. This makes the code more maintainable and easier to
understand.

JFrame: JFrame is a class in Java Swing that represents a top-level window or frame in
a GUI application. It serves as the main container for other GUI components, such as

12 | Page
Advanced JAVA Programming (4351603)

buttons, labels, text fields, etc. JFrame provides the necessary functionality to create,
configure, and manage the application window.

Key features of JFrame include:

1. Window Management: JFrame allows you to set the title, size, location, and
visibility of the window. You can also control how the window behaves when it's
closed, such as terminating the application or hiding the window.
2. Content Pane: JFrame has a content pane (an instance of JPanel) that acts as a
container for placing other Swing components. You can add components to the
content pane using the add() method.
3. Layout Management: JFrame uses a default BorderLayout by default, but you can
change the layout manager to any other available layout manager or implement a
custom layout to organize the components within the window.
4. Event Handling: JFrame can handle various events like window opening, closing,
resizing, etc. by using event listeners.
5. Icon and Image Management: JFrame allows you to set icons for the application
window, which appear in the title bar and taskbar/dock. Overall, using JFrame along
with other Swing components, you can create interactive and user-friendly desktop
applications with ease and flexibility in Java.
H. Experimental set up/ Program Logic-Flow chart:
N/A
I. Resources/Equipment Required

Sr. Instrument/Equipment
Specification Quantity
No.
/Components/Trainer kit
1 Hardware: Computer (i3-i5 preferable)
Computer System
2 Operating System Windows/ Linux/ MAC
As Per
3 Batch
Software JAVA IDE Size
4
Web Browser Edge, Firefox, Chrome or similar

J. Safety and necessary Precautions followed.


N/A
13 | Page
Advanced JAVA Programming (4351603)

K. Procedure to be followed/Source code/Lab Task:

L. Observations and Calculations/Input-Output:

M. Practical Related Quiz/Questions:

a. Explain Swing Components.

b. Describe advantages of Swing Components.

c. Advantages of Swing frame over simple frame.

N. References / Suggestions

1. https://www.javatpoint.com/java-swing

2. https://docs.oracle.com/javase/tutorial/uiswing/start/index.html

3. https://www.javatpoint.com/java-jbutton

14 | Page
Advanced JAVA Programming (4351603)

O. Assessment-Rubrics

Faculty
Marks Date
Signature
Obtained

Program Implementation Studnet’s Total


correctness and Presentation engagement in
Methodology practical activities (10)
(4)
(3) (3)
R1
R2 R3

Sign with Date

15 | Page
Advanced JAVA Programming (4351603)

Date: ……………

Practical Develop a program to create checkboxes for different courses belonging to a


No:2 university such that the course selected would be displayed.

A. Objective: To apply and understand the use of checkbox in java application.


B. Expected Program Outcomes (POs)
Po1 - Basic and Discipline specific knowledge.
Po2 - Problem analysis.
Po3 - Design/ development of solutions.
Po4 - Engineering Tools, Experimentation and Testing.
Po5 - Engineering practices for society, sustainability and environment.
Po6 - Project Management.
Po7 - Lifelong learning.

C. Expected Skills to be developed based on competency:


This practical is expected to develop the following skills for the industry identified
competency:
1. Understand Java Swing Checkbox.
2. Able to implement a code based on the Java Swing framework.

D. Expected Course Outcomes (Cos)


CO-1: Develop a GUI application using swing components.
E. Practical Outcome (PRo)
After completion of this practical student will be able to develop a GUI program
by using swing Checkbox.
F. Expected Affective domain Outcome (ADos)

1. Follow safety practices.


2. Follow Coding standards and practices.
3. Demonstrate working as a leader/ a team member.
4. Follow ethical practices.
5. Maintain tools and equipment..

16 | Page
Advanced JAVA Programming (4351603)

G. Prerequisite Theory:

❖ JCheckbox: The JCheckBox class is used to create a checkbox. It is used to


turn an option on (true) or off (false). Clicking on a CheckBox changes its
state from "on" to "off" or from "off" to "on ".

o Commonly used Class Constructors:-

▪ JCheckBox()
● Creates an initially unselected checkbox button with
no text and no icon
▪ JCheckBox(Action a)
● Creates a checkbox where the properties are taken
from the Action supplied
▪ JCheckBox(Icon icon)
● Creates an initially unselected checkbox with an icon
▪ JCheckBox(String text)
● Creates an initially unselected checkbox with text
▪ JCheckBox(String text, Icon icon, boolean selected)
● Creates a checkbox with text and icon, and specifies
whether or not it is initially selected.

H. Experimental set up/ Program Logic-Flow chart:


N/A

I. Resources/Equipment Required

17 | Page
Advanced JAVA Programming (4351603)

Sr. Instrument/Equipment
Specification Quantity
No.
/Components/Trainer kit
1 Hardware: Computer (i3-i5 preferable)
Computer System
2 Operating System Windows/ Linux/ MAC
As Per
3 Batch
Software JAVA IDE Size
4
Web Browser Edge, Firefox, Chrome or similar

J. Safety and necessary Precautions followed.


N/A
K. Procedure to be followed/Source code/Lab Task:

L. Observations and Calculations/Input-Output:

M. Practical Related Quiz/Questions:

18 | Page
Advanced JAVA Programming (4351603)

1. Explain Swing checkbox.


2. Make use of Jcheckbox.

N. References / Suggestions
1. https://www.javatpoint.com/java-jcheckbox
2. https://www.tutorialspoint.com/swing/swing_jcheckbox.htm
3. https://docs.oracle.com/javase/8/docs/api/javax/swing/JCheckBox.html

O. Assessment-Rubrics

Faculty
Marks Date
Signature
Obtained

Program Implementation Studnet’s Total


correctness and Presentation engagement in
Methodology practical activities (10)
(4)
(3) (3)
R1
R2 R3

Sign with Date

19 | Page
Advanced JAVA Programming (4351603)

Date: ……………

Practical Develop a program to Implement Traffic signal(Red, Green and Yellow) by using
No:3 Swing components ( Using JFrame, JRadioButton, ItemListener etc.).

A. Objective: Understand and be able to use JFrame, JRadioButton, ItemListener etc in Java
applications.

B. Expected Program Outcomes (POs)


Po1 - Basic and Discipline specific knowledge.
Po2 - Problem analysis.
Po3 - Design/ development of solutions.
Po4 - Engineering Tools, Experimentation and Testing.
Po5 - Engineering practices for society, sustainability and environment.
Po6 - Project Management.
Po7 - Lifelong learning.

C. Expected Skills to be developed based on competency:


This practical is expected to develop the following skills for the industry identified
competency:
1. Understand Java Swing JFrame, JRadioButton, ItemListener, etc.
2. Develop a code based on Java Swing framework using JFrame, JRadioButton,
ItemListener, etc.

D. Expected Course Outcomes (Cos)


CO-1: Develop a GUI application using swing components.
E. Practical Outcome (PRo)
After completion of this practical course, students will be able to develop GUI
programs by using JFrame, JRadioButton, ItemListener, etc.
F. Expected Affective domain Outcome (ADos)

1. Follow safety practices.


2. Follow Coding standards and practices.
3. Demonstrate working as a leader/ a team member.
4. Follow ethical practices.
5. Maintain tools and equipment.

20 | Page
Advanced JAVA Programming (4351603)

G. Prerequisite Theory:

❖ JRadioButton:The JRadioButton class is used to create a radio button. It is


used to choose one option from multiple options. It is widely used in exam
MCQ based test or quiz.
o Commonly used Class Constructors:-
▪ JRadioButton()
o Creates an initially unselected radio button with no set text.
▪ JRadioButton(Action a)
o Creates a radiobutton where properties are taken from the
Action supplied
▪ JRadioButton(Icon icon)
o Creates an initially unselected radio button with the
specified image but no text
▪ JRadioButton(String text, Icon icon, boolean selected)
o Creates a radio button that has the specified text, image,
and selection state
❖ Event listeners: Event listeners represent the interfaces responsible to
handle events. Java provides various Event listener classes, however, only
those which are more frequently used will be discussed. Every method of
an event listener method has a single argument as an object which is the
subclass of EventObject class. For example, mouse event listener methods
will accept instances of MouseEvent, where MouseEvent derives from
EventObject. It is a marker interface which every listener interface has to
extend. This class is defined in java.util package.
❖ ItemListener:The class which processes the ItemEvent should implement
this interface.The object of that class must be registered with a component.
The object can be registered using the addItemListener() method. When
the action event occurs, that object's itemStateChanged method is invoked.
Interface Method:-
· void itemStateChanged(ItemEvent e): Invoked when an item has been
selected or deselected by the user

H. Experimental set up/ Program Logic-Flow chart:


N/A
I. Resources/Equipment Required

21 | Page
Advanced JAVA Programming (4351603)

Sr. Instrument/Equipment
Specification Quantity
No.
/Components/Trainer kit
1 Hardware: Computer (i3-i5 preferable)
Computer System
2 Operating System Windows/ Linux/ MAC
As Per
3 Batch
Software JAVA IDE Size
4
Web Browser Edge, Firefox, Chrome or similar

J. Safety and necessary Precautions followed.


N/A

K. Procedure to be followed/Source code/Lab Task:

22 | Page
Advanced JAVA Programming (4351603)

L. Observations and Calculations/Input-Output:

M. Practical Related Quiz/Questions:


1. Discuss Event Listener in detail.
2. List out all the event listeners and also list out the name of the methods
associated with all event listeners.

N. References / Suggestions
1. https://www.javatpoint.com/java-jradiobutton
2. https://www.tutorialspoint.com/swing/swing_jradiobutton.htm
3. https://www.tutorialspoint.com/swing/swing_event_listeners.htm
4. https://www.javatpoint.com/java-itemlistener

O. Assessment-Rubrics

Faculty
Marks Date
Signature
Obtained

Program Implementation Studnet’s Total


correctness and Presentation engagement in
Methodology practical activities (10)
(4)
(3) (3)
R1
R2 R3

Sign with Date

Date: ……………
23 | Page
Advanced JAVA Programming (4351603)

Practical Develop a program using JDBC to display student’s record (Enroll No, Name,
No:4 Address, Mobile No,and Email-ID) into table ‘StuRec’.

A. Objective: Understand and apply the logic for connection between Java applications
with the database by using JDBC.

B. Expected Program Outcomes (POs)


Po1 - Basic and Discipline specific knowledge.
Po2 - Problem analysis.
Po3 - Design/ development of solutions.
Po4 - Engineering Tools, Experimentation and Testing.
Po6 - Project Management.
Po7 - Lifelong learning.

C. Expected Skills to be developed based on competency:

This practical is expected to develop the following skills for the industry identified
competency:
1. Download and install any one JDBC driver as per requirement.
2. Download database server.
3. Implement and run programs using any IDE.

D. Expected Course Outcomes (Cos)


CO2- Apply ORM based Methodology for Application Development.
E. Practical Outcome (PRo)
After completion of this practical students will be able to install Database server
and be able to use appropriate JDBC driver.Also able to develop applications to
connect java applications with databases.
F. Expected Affective domain Outcome (ADos)

1. Follow safety practices.


2. Follow Coding standards and practices.
3. Demonstrate working as a leader/ a team member.
4. Follow ethical practices.
5. Maintain tools and equipment.

G. Prerequisite Theory:

24 | Page
Advanced JAVA Programming (4351603)

❖ JDBC: JDBC stands for Java Database Connectivity. JDBC is a Java API to connect
and execute the query with the database. It is a part of JavaSE (Java Standard
Edition). JDBC API uses JDBC drivers to connect with the database. There are
four types of JDBC drivers
o JDBC-ODBC Bridge Driver,

o Native Driver,
o Network Protocol Driver, and
o Thin Driver

We can use JDBC API to access tabular data stored in any relational database.
By the help of JDBC API, we can save, update, delete and fetch data from the
database. It is like Open Database Connectivity (ODBC) provided by Microsoft.
Here are some essential components of JDBC

DriverManager: The central class in the JDBC API. It helps manage the drivers for
different database systems and provides methods to establish database connections.

Driver: A JDBC driver is a software component that enables Java applications to interact
with a specific database. Each database vendor provides its JDBC driver
implementation.

Connection: Represents a connection to a specific database. It is obtained using the


DriverManager class and is used to execute SQL queries.

Statement: Used to execute SQL queries without parameters. You can create instances
of Statement from a Connection object.

PreparedStatement: A precompiled SQL statement that can be parameterized,


providing better performance and security compared to simple Statements.

ResultSet: Represents the result of a query execution. It allows you to iterate over the
rows returned by the query

7 Steps to connect with the Database:

There are 5 steps to connect any java application with the database using JDBC. These
steps are as follows:
o Import the required package
o Load and Register the Driver class

25 | Page
Advanced JAVA Programming (4351603)

o Create connection
o Create statement
o Execute queries
o Process the result
o Close connection

JDBC is widely used in Java-based applications that need to interact with databases,
and it provides a standard way to manage database connections across various
platforms and database systems

H. Experimental set up/ Program Logic-Flow chart:


N/A
I. Resources/Equipment Required
Sr. Instrument/Equipment
Specification Quantity
No.
/Components/Trainer kit
1 Hardware: Computer (i3-i5 preferable)
Computer System
2 Operating System Windows/ Linux/ MAC
As Per
3 Batch
Software JAVA IDE Size
4
Web Browser Edge, Firefox, Chrome or similar

J. Safety and necessary Precautions followed.


N/A

K. Procedure to be followed/Source code/Lab Task:

26 | Page
Advanced JAVA Programming (4351603)

L. Observations and Calculations/Input-Output:

M. Practical Related Quiz/Questions:


1. Describe the basics of JDBC and its connectivity.
2. Develop program using JDBC to query a database and able to modify it

N. References / Suggestions

1. https://www.geeksforgeeks.org/introduction-to-jdbc/

2. https://www.tutorialspoint.com/jdbc/index.htm

3. https://www.javatpoint.com/steps-to-connect-to-the-database-in-java

4. https://docs.oracle.com/javase/8/docs/technotes/guides/jdbc/

27 | Page
Advanced JAVA Programming (4351603)

O. Assessment-Rubrics

Faculty
Marks Date
Signature
Obtained

Program Implementation Studnet’s Total


correctness and Presentation engagement in
Methodology practical activities (10)
(4)
(3) (3)
R1
R2 R3

Sign with Date

28 | Page
Advanced JAVA Programming (4351603)

Date: ……………

Practical Develop a program using JDBC to edit (insert, update, delete) Student’s profile
No:5 stored in the database.

A. Objective: Develop graphical user interfaces (GUIs) application using JDBC to insert,
update and delete any record in the database.
B. Expected Program Outcomes (POs)
Po1 - Basic and Discipline specific knowledge.
Po2 - Problem analysis.
Po3 - Design/ development of solutions.
Po4 - Engineering Tools, Experimentation and Testing.
Po6 - Project Management.
Po7 - Lifelong learning.

C. Expected Skills to be developed based on competency:

This practical is expected to develop the following skills.


1. Update database through Java Application.

D. Expected Course Outcomes (Cos)

CO2: Apply ORM based Methodology for Application Development.


E. Practical Outcome (PRo)

Students will be able to develop Java applications using JDBC to update the
database.
F. Expected Affective domain Outcome (ADos)

1. Follow safety practices.


2. Follow Coding standards and practices.
3. Demonstrate working as a leader/ a team member.
4. Follow ethical practices.
5. Maintain tools and equipment.

G. Prerequisite Theory:

❖ Connection Interface: A Connection is a session between a Java application


and a database. It helps to establish a connection with the database. The
Connection interface is a factory of Statement, PreparedStatement, and
29 | Page
Advanced JAVA Programming (4351603)

DatabaseMetaData, i.e., an object of Connection can be used to get the object


of Statement and DatabaseMetaData. The Connection interface provide
many methods for transaction management like commit(), rollback(),
setAutoCommit(), setTransactionIsolation(), etc

Commonly used methods of Connection interface:

1)public Statement createStatement(): creates a statement object that


can be used to execute SQL queries.

2)public Statement createStatement(int resultSetType,int


resultSetConcurrency): Creates a Statement object that will generate
ResultSet objects with the given type and concurrency.

❖ Statement Interface: The Statement interface provides methods to execute


queries with the database. The statement interface is a factory of ResultSet
i.e. it provides a factory method to get the object of ResultSet.

Commonly used methods of Connection interface:

1) public ResultSet executeQuery(String sql): is used to execute


SELECT query.It returns the object of ResultSet

2) public int executeUpdate(String sql): is used to execute specified


query, it may be create, drop, insert, update, delete etc

3) public boolean execute(String sql): is used to execute queries that


may return multiple results.

❖ ResultSet Interface: The object of ResultSet maintains a cursor pointing to


a row of a table. Initially, cursor points to the first row.

Commonly used methods of Connection interface:

1) public boolean next(): is used to move the cursor to the one row next
from the current position.

2) public boolean previous(): is used to move the cursor to the one row
previous from the current position.

30 | Page
Advanced JAVA Programming (4351603)

H. Experimental set up/ Program Logic-Flow chart:


NA
I. Resources/Equipment Required

Sr. Instrument/Equipment
Specification Quantity
No.
/Components/Trainer kit
1 Hardware: Computer (i3-i5 preferable)
Computer System
2 Operating System Windows/ Linux/ MAC
As Per
3 Batch
Software JAVA IDE Size
4
Web Browser Edge, Firefox, Chrome or similar

J. Safety and necessary Precautions followed.

NA
K. Source code:

L. Input-Output:

31 | Page
Advanced JAVA Programming (4351603)

M. Practical Related Quiz/Questions:


a. Describe the important methods of statement interface.
b. Develop a java application select a particular student record by using its
name or enrollment and display it .
N. References / Suggestions

1. https://www.javatpoint.com/Connection-interface

2. https://www.tutorialspoint.com/jdbc/jdbc-statements.htm

3. https://www.javatpoint.com/ResultSet-interface

O. Assessment-Rubrics

Faculty
Marks Date
Signature
Obtained

Program Implementation Studnet’s Total


correctness and Presentation engagement in
Methodology practical activities (10)
(4)
(3) (3)
R1
R2 R3

Sign with Date

32 | Page
Advanced JAVA Programming (4351603)

Date: ……………

Practical Develop an application to store, update, fetch and delete data of Employee
(NAME, AGE, SALARY and DEPARTMENT) using Hibernate CRUD
No:6 operations.

A. Objective: Understand Hibernate and implement database operation using


hibernate architecture.

B. Expected Program Outcomes (POs)


Po1 - Basic and Discipline specific knowledge.
Po2 - Problem analysis.
Po3 - Design/ development of solutions.
Po4 - Engineering Tools, Experimentation and Testing.
Po6 - Project Management.
Po7 - Lifelong learning.

C. Expected Skills to be developed based on competency:


This practical is expected to develop the following skills.
1. Understand Hibernate architecture.
2. Write a code based on the Hibernate framework.

D. Expected Course Outcomes (Cos)

CO2: Apply ORM based Methodology for Application Development.

E. Practical Outcome (PRo)

Students will be able to apply on the hibernate architecture to java web application
development.
F. Expected Affective domain Outcome (ADos)

1. Follow safety practices.


2. Follow Coding standards and practices.
3. Demonstrate working as a leader/ a team member.
4. Follow ethical practices.
5. Maintain tools and equipment.

33 | Page
Advanced JAVA Programming (4351603)

G. Prerequisite Theory:

❖ Object-Relational Mapping: Object-Relational Mapping (ORM) is a


programming technique that allows developers to efficiently work with
relational databases using object-oriented programming languages. It bridges
the gap between the object-oriented model used in application code and the
relational model used in databases.

In a traditional relational database, data is stored in tables consisting of rows


and columns. Each row represents a record, and each column represents a
specific attribute of that record. On the other hand, in object-oriented
programming, data is represented as objects with properties and methods.

ORM frameworks, like Hibernate, provide a way to map the objects in an


application to the tables in a relational database. It automates the process of
converting data between the object-oriented model and the relational model,
allowing developers to interact with the database using objects and their
relationships instead of writing complex SQL queries.

ORM offers several benefits:

1. Simplified Database Interaction

2. Database Independence

3. Increased Productivity

4. Object-Relational Transparency

5. Performance Optimization

The Hibernate architecture can be divided into the following key components:

1. Application Layer: This layer represents the application code and the
domain model, which includes the Java classes that map to database tables. The
application layer interacts with Hibernate to perform various operations on the
database.

2. Configuration: The configuration component is responsible for setting up


and configuring Hibernate. It involves specifying database connection details,
mapping files, caching options, and other Hibernate properties. The

34 | Page
Advanced JAVA Programming (4351603)

configuration can be provided through XML configuration files or


programmatically using Java code.

3. SessionFactory: The SessionFactory is a crucial component in Hibernate. It is


responsible for creating and managing sessions, which are used to interact with
the database. The SessionFactory is typically a thread-safe singleton and serves
as a factory for creating session instances.

4. Session: A Session represents a single unit of work with the database. It


provides APIs to perform database operations like saving, updating, and
deleting objects, as well as executing queries. The Session acts as a persistence
context, tracking changes to objects and synchronizing them with the database.

5. Transaction Management: Hibernate supports transaction management,


ensuring that multiple database operations are executed atomically. It provides
transaction APIs to begin, commit, or rollback transactions. Transactions help
maintain data integrity and consistency in the database.

6. Object-Relational Mapping (ORM) Layer: The ORM layer is the core of


Hibernate, responsible for mapping Java objects to database tables. It handles
the translation of object-oriented concepts (objects, classes, inheritance,
associations) to relational database concepts (tables, columns, relationships).
Hibernate uses various mapping techniques, including XML-based mapping
files, annotations, or a combination of both, to define the mappings between
Java classes and database tables.

7. Persistent Object Cache: Hibernate includes a first-level cache, also known


as the session cache or the first-level cache. It is used to cache objects loaded
from the database during a session. The first-level cache improves performance
by reducing database round-trips and facilitating efficient object retrieval and
updates.

8. Connection Management: Hibernate manages database connections


efficiently using a connection pool. It abstracts the connection acquisition and
release process, optimizing connection usage and handling connection pooling
mechanisms.

9. Query Language Support: Hibernate provides its own query language called
Hibernate Query Language (HQL), which is a powerful and flexible language for
querying the database. HQL is similar to SQL but operates on object-oriented

35 | Page
Advanced JAVA Programming (4351603)

concepts instead of database tables and columns. Hibernate also supports the
Criteria API and native SQL queries for more complex query requirements.

❖ To set up Eclipse with Hibernate API, you can follow these steps:

• Install Eclipse: Download and install Eclipse IDE from the official Eclipse
website (https://www.eclipse.org/downloads/). Choose the version suitable for
your operating system and Java development needs.

• Create a Java Project: Open Eclipse and create a new Java project by
selecting "File" > "New" > "Java Project". Give your project a name and click
"Finish" to create the project.

• Add Hibernate Libraries: Download the Hibernate libraries (JAR files) from
the Hibernate website (https://hibernate.org/orm/releases/) or use a
dependency management tool like Maven. Copy the Hibernate JAR files to a
folder in your project, such as a "lib" folder.

Configure Build Path: Right-click on your project, select "Properties", and


navigate to "Java Build Path". Click on the "Libraries" tab and then click "Add
JARs" or "Add External JARs". Browse to the location where you copied the
Hibernate JAR files and select them. Click "Apply" and then "OK" to add the
Hibernate libraries to your project's build path.

Set Up Hibernate Configuration File: Right-click on your project, select "New"


> "File". Enter a file name like "hibernate.cfg.xml" and click "Finish". In the
newly created configuration file, you can specify database connection details,
mapping files, and other Hibernate properties. Refer to the Hibernate
documentation for more information on configuring the Hibernate
configuration file.

Create Hibernate Mapping Files: Right-click on your project, select "New" >
"File". Enter a file name like "Employee.hbm.xml" and click "Finish". In the
mapping file, define the mappings between your Java classes and database
tables using the Hibernate mapping language. Repeat this step for each entity
you want to persist with Hibernate.

Start Coding with Hibernate: Begin coding your application using Hibernate
API. Import the necessary Hibernate classes and annotations into your Java
classes. Use the SessionFactory, Session, and Transaction APIs to perform
database operations like saving, updating, and querying objects.
36 | Page
Advanced JAVA Programming (4351603)

Run and Test: Once you have written your code, you can run and test your
Hibernate-enabled application. Make sure you have a database connection set
up and running, and that it aligns with the configuration specified in the
hibernate.cfg.xml file.

H. Experimental set up/ Program Logic-Flow chart:


N/A
I. Resources/Equipment Required

Sr. Instrument/Equipment
Specification Quantity
No.
/Components/Trainer kit
1 Hardware: Computer (i3-i5 preferable)
Computer System
2 Operating System Windows/ Linux/ MAC
As Per
3 Batch
Software JAVA IDE Size
4
Web Browser Edge, Firefox, Chrome or similar

J. Safety and necessary Precautions followed.

NA

K. Source code:

37 | Page
Advanced JAVA Programming (4351603)

L. Input-Output:

M. Practical Related Quiz/Questions:

a. What is Object-Relational Mapping (ORM)?

b. What are the advantages of using Hibernate in a project?

c. How do you configure Hibernate in an application?

d. What is the SessionFactory in Hibernate?

e. What is the role of Hibernate's HQL (Hibernate Query Language) in database


operations?
N. References / Suggestions
1. https://www.tutorialspoint.com/hibernate/hibernate_examples.htm
2. https://www.javatpoint.com/steps-to-create-first-hibernate-application
3. https://www.digitalocean.com/community/tutorials/hibernate-tutorial-for-
beginners

O. Assessment-Rubrics
Faculty
Marks Date
Signature
Obtained

Program Implementation Studnet’s Total


correctness and Presentation engagement in
Methodology practical activities (10)
(4)
(3) (3)
R1
R2 R3

Sign with Date

38 | Page
Advanced JAVA Programming (4351603)

Date: ……………

Practical 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
No:7 deployment descriptors.

A. Objective: Understand web application and implement web application using


servlet which counts total number of visits for that servlet also use web.xml file to
initialize the counter.
B. Expected Program Outcomes (POs)
Po1 - Basic and Discipline specific knowledge.
Po2 - Problem analysis.
Po3 - Design/ development of solutions.
Po4 - Engineering Tools, Experimentation and Testing.
Po5 - Engineering practices for society, sustainability and environment.
Po6 - Project Management.
Po7 - Lifelong learning.

C. Expected Skills to be developed based on competency:


This practical is expected to develop the following skills.
1. Install tomcat server and configure
2. Develop web applications using servlet.
3. Use and understand the deployment descriptor file.

D. Expected Course Outcomes (Cos)

CO3: Develop Web Applications using Servlets and deploy in popular servers
like Tomcat.

E. Practical Outcome (PRo)

Students will be able to develop web applications using servlet.

F. Expected Affective domain Outcome (ADos)

1. Follow safety practices.


2. Follow Coding standards and practices.
3. Demonstrate working as a leader/ a team member.

39 | Page
Advanced JAVA Programming (4351603)

4. Follow ethical practices.


5. Maintain tools and equipment.
G. Prerequisite Theory:

❖ Servlet: Servlet technology is used to create a web application (resides at


server side and generates a dynamic web page). Servlet technology is robust
and scalable because of java language. Before Servlet, CGI (Common
Gateway Interface) scripting language was common as a server-side
programming language. However, there were many disadvantages to this
technology. We have discussed these disadvantages below.
▪ There are many interfaces and classes in the Servlet API such as
Servlet, GenericServlet, HttpServlet, ServletRequest,
ServletResponse, etc.
▪ Java Servlets often serve the same purpose as programs
implemented using the Common Gateway Interface (CGI). But
Servlets offer several advantages in comparison with the CGI.
▪ Performance is significantly better.
▪ Servlets execute within the address space of a Web server. It is
not necessary to create a separate process to handle each client
request.
▪ Servlets are platform-independent because they are written in
Java.
▪ Java security manager on the server enforces a set of restrictions
to protect the resources on a server machine. So servlets are
trusted.
▪ The full functionality of the Java class libraries is available to a
servlet. It can communicate with applets, databases, or other
software via the sockets and RMI mechanisms that you have seen
already.
Applications of Servlet
▪ Read the explicit data sent by the clients (browsers). This
includes an HTML form on a Web page or it could also come from
an applet or a custom HTTP client program.
▪ Read the implicit HTTP request data sent by the clients
(browsers). This includes cookies, media types and compression
schemes the browser understands, and so forth.
▪ Process the data and generate the results. This process may
require talking to a database, executing an RMI or CORBA call,
invoking a Web service, or computing the response directly.
▪ Send the explicit data (i.e., the document) to the clients
(browsers). This document can be sent in a variety of formats,
including text (HTML or XML), binary (GIF images), Excel, etc.
▪ Send the implicit HTTP response to the clients (browsers). This
includes telling the browsers or other clients what type of

40 | Page
Advanced JAVA Programming (4351603)

document is being returned (e.g., HTML), setting cookies and


caching parameters, and other such tasks.

H. Experimental set up/ Program Logic-Flow chart:


N/A
I. Resources/Equipment Required
Sr. Instrument/Equipment
Specification Quantity
No.
/Components/Trainer kit
1 Hardware: Computer (i3-i5 preferable)
Computer System
2 Operating System Windows/ Linux/ MAC
As Per
3 Batch
Software JAVA IDE Size
4
Web Browser Edge, Firefox, Chrome or similar

J. Safety and necessary Precautions followed.


NA
K. Procedure to be followed/Source code/Lab Task:

41 | Page
Advanced JAVA Programming (4351603)

L. Observations and Calculations/Input-Output:

M. Practical Related Quiz/Questions:


1. What is the web application and what is the difference between Get and Post
request.
2. Compare Static and Dynamic websites.
3. How to run servlet in Eclipse, MyEclipse and Netbeans IDE.

N. References / Suggestions
1. https://www.javatpoint.com/servlet-tutorial
2. https://www.tutorialspoint.com/servlets/index.htm
3. https://www.geeksforgeeks.org/introduction-java-servlets/

O. Assessment-Rubrics

Faculty
Marks Date
Signature
Obtained

Program Implementation Studnet’s Total


correctness and Presentation engagement in
Methodology practical activities (10)
(4)
(3) (3)
R1
R2 R3

Sign with Date

42 | Page
Advanced JAVA Programming (4351603)

Date: ……………

Practical Create a web form which processes servlet and demonstrates use of cookies and
No:8 sessions.

A. Objective: Describe state management, and implement a java application using


sessions and cookies to maintain the state of the client.
B. Expected Program Outcomes (POs)
Po1 - Basic and Discipline specific knowledge.
Po2 - Problem analysis.
Po3 - Design/ development of solutions.
Po4 - Engineering Tools, Experimentation and Testing.
Po5 - Engineering practices for society, sustainability and environment.
Po6 - Project Management.
Po7 - Lifelong learning.

C. Expected Skills to be developed based on competency:

This practical is expected to develop the following skills.


1. State management techniques.

D. Expected Course Outcomes (Cos)

CO3: Develop Web Applications using Servlets and deploy in popular servers
like Tomcat.

E. Practical Outcome (PRo)

Students will be able to Develop Web Applications using Servlets to maintain


the state of the client by using sessions and cookies.

F. Expected Affective domain Outcome (ADos)

1. Follow safety practices.


2. Follow Coding standards and practices.
3. Demonstrate working as a leader/ a team member.
4. Follow ethical practices.
5. Maintain tools and equipment.

43 | Page
Advanced JAVA Programming (4351603)

G. Prerequisite Theory:
❖ Session Tracking: Session simply means a particular interval of time.
Session Tracking is a way to maintain the state (data) of an user. It is also
known as session management in servlet.
Http protocol is stateless so we need to maintain state using session
tracking techniques. Each time a user requests to the server, the server
treats the request as the new request. So we need to maintain the state of a
user to recognize a particular user. HTTP is stateless, which means each
request is considered as the new request.
❖ Cookies: Cookies are used a lot in web applications to personalize
responses based on your choice or to keep track of sessions. A cookie is a
small piece of information that is persisted between the multiple client
requests. A cookie has a name, a single value, and optional attributes such
as a comment, path and domain qualifiers, a maximum age, and a version
number.
There are 2 types of cookies in servlets:

Non-persistent cookie: It is valid for a single session only. It is removed


each time the user closes the browser.

Persistent cookie: It is valid for multiple sessions. It is not removed


each time the user closes the browser. It is removed only if user logout or
signout.

H. Experimental set up/ Program Logic-Flow chart:


N/A
I. Resources/Equipment Required
Sr. Instrument/Equipment
Specification Quantit
No.
/Components/Trainer kit y
1 Hardware: Computer (i3-i5 preferable)
Computer System
2 Operating System Windows/ Linux/ MAC
As Per
3
Software JAVA IDE Batch
Size
4
Web Browser Edge, Firefox, Chrome or
similar

44 | Page
Advanced JAVA Programming (4351603)

J. Safety and necessary Precautions followed.


NA
K. Procedure to be followed/Source code/Lab Task:

L. Observations and Calculations/Input-Output:

M. Practical Related Quiz/Questions:


1. Differentiate between ServletConfig and ServletContext interface.
2. Explain HTTPSession interface.
3. Discuss Advantages and disadvantages of cookies.

N. References / Suggestions
1. https://www.ibm.com/docs/en/was/8.5.5?topic=SSEQTP_8.5.5/com.ibm.we
bsphere.nd.multiplatform.doc/ae/tprs_sesi.htm
2. https://www.javatpoint.com/session-tracking-in-servlets
3. https://www.javatpoint.com/http-session-in-session-tracking
4. https://www.geeksforgeeks.org/servlet-session-tracking/
5. https://www.digitalocean.com/community/tutorials/java-session-
management-servlet-httpsession-url-rewriting

45 | Page
Advanced JAVA Programming (4351603)

O. Assessment-Rubrics

Faculty
Marks Date
Signature
Obtained

Program Implementation Studnet’s Total


correctness and engagement in
Presentation practical (10)
(4) Methodology activities

R1 (3) (3)

R2 R3

Sign with Date

46 | Page
Advanced JAVA Programming (4351603)

Date: ……………

Practical
Develop a web form which processes servlet for user login functionality.
No:9

A. Objective: Able to connect the database application using servlet technology.


B. Expected Program Outcomes (POs)
Po1 - Basic and Discipline specific knowledge.
Po2 - Problem analysis.
Po3 - Design/ development of solutions.
Po4 - Engineering Tools, Experimentation and Testing.
Po5 - Engineering practices for society, sustainability and environment.
Po6 - Project Management.
Po7 - Lifelong learning.

C. Expected Skills to be developed based on competency:


This practical is expected to develop the following skills.
1. Database connectivity with servlet
2. Designing
3. Validation.

D. Expected Course Outcomes (Cos)


CO3: Develop Web Applications using Servlets and deploy in popular servers
like Tomcat.

E. Practical Outcome (PRo)

Students will be able to develop web applications using servlet and connect it
with databases.

F. Expected Affective domain Outcome (ADos)

1. Follow safety practices.


2. Follow Coding standards and practices.
3. Demonstrate working as a leader/ a team member.
4. Follow ethical practices.
5. Maintain tools and equipment.

47 | Page
Advanced JAVA Programming (4351603)

G. Prerequisite Theory:
❖ Servlet Database Access: Here we assume that you have an understanding
on how the JDBC application works. Before starting with database access
through a servlet, make sure you have a proper JDBC environment setup
along with a database server setup. For more detail on how to access
databases using JDBC you can go through JDBC practical theory.

H. Experimental set up/ Program Logic-Flow chart:


N/A
I. Resources/Equipment Required

Sr. Instrument/Equipment
Specification Quantity
No.
/Components/Trainer kit
1 Hardware: Computer (i3-i5 preferable)
Computer System
2 Operating System Windows/ Linux/ MAC
As Per
3 Batch Size
Software JAVA IDE
4
Web Browser Edge, Firefox, Chrome or
similar

J. Safety and necessary Precautions followed.


N/A

48 | Page
Advanced JAVA Programming (4351603)

K. Procedure to be followed/Source code/Lab Task:

L. Observations and Calculations/Input-Output:

M. Practical Related Quiz/Questions:


1. Implement Registration form with validation.
2. Implement forgot password functionalities.

N. References / Suggestions
1. https://www.geeksforgeeks.org/servlet-database-access/
2. https://www.tutorialspoint.com/servlets/servlets-database-access.htm

49 | Page
Advanced JAVA Programming (4351603)

O. Assessment-Rubrics

Faculty
Marks Date
Signature
Obtained

Program Implementation Studnet’s Total


correctness and engagement in
Presentation practical (10)
(4) Methodology activities

R1 (3) (3)

R2 R3

Sign with Date

50 | Page
Advanced JAVA Programming (4351603)

Date: ……………

Practical Develop a JSP web application to display student monthly attendance in


No:10 each subject of current semester via enrollment number.

A. Objective: JSP integrates well with other Java technologies, such as Java
Servlets and Java EE frameworks. It allows seamless communication with back-
end systems, databases, and other services using Java code.
B. Expected Program Outcomes (POs)
Po1 - Basic and Discipline specific knowledge.
Po2 - Problem analysis.
Po3 - Design/ development of solutions.
Po4 - Engineering Tools, Experimentation and Testing.
Po6 - Project Management.
Po7 - Lifelong learning.

C. Expected Skills to be developed based on competency:

1) Understand JSP Lifecycle and Session tracking.


2) Apply database logic with JSP page.
3) Follow coding standards and debug programs to fix errors.

D. Expected Course Outcomes (Cos)


CO4: Develop JSP based applications with database connectivity.

E. Practical Outcome (PRo)

Students will be able to use JSP applications with databases.

F. Expected Affective domain Outcome (ADos)

1) Follow safety practices.


2) Follow Coding standards and practices.
3) Demonstrate working as a leader/ a team member.
4) Follow ethical practices.
5) Maintain tools and equipment.

G. Prerequisite Theory:

51 | Page
Advanced JAVA Programming (4351603)

❖ To create a JSP application in Eclipse, you can follow these steps:


1. Open Eclipse: Launch the Eclipse IDE on your computer.
2. Create a new Dynamic Web Project: Select "File" > "New" > "Dynamic
Web Project" from the Eclipse menu. Give your project a name and click
"Next".
3. Configure project settings: Specify the target runtime for your project.
If you haven't set up a runtime, click on "New Runtime" and follow the
prompts to set up Apache Tomcat or any other supported server. Select the
configured runtime and click "Next".
4. Configure project facets: In the "Project Facets" section, make sure
"Dynamic Web Module" is selected. You can also choose other facets based
on your project requirements. Click "Further Configuration Available" to
configure additional settings if needed, then click "Next".
5. Configure the content directory: Specify the content directory where
the web application files will be stored. The default is "WebContent". You
can change this if desired and click "Finish" to create the project.
6. Create a JSP file: Right-click on the "WebContent" folder in the Project
Explorer and select "New" > "JSP". Enter a name for your JSP file, such as
"index.jsp", and click "Finish". This will create a new JSP file in the specified
folder.
7. Edit the JSP file: Open the created JSP file and start editing the content
using HTML markup and embedded Java code (if necessary). You can also
include JSP tags, expressions, and scriptlets to dynamically generate
content.
8. Run the JSP application: Right-click on the project, select "Run As" >
"Run on Server". Choose the configured server (e.g., Apache Tomcat) and
click "Finish". This will deploy and launch the JSP application on the
specified server.

9. View the JSP application: Eclipse will open a web browser, showing the
JSP application running locally on the server. You can interact with the JSP
page and test its functionality.

H. Experimental set up/ Program Logic-Flow chart:


N/A

52 | Page
Advanced JAVA Programming (4351603)

I. Resources/Equipment Required

Sr. Instrument/Equipment
Specification Quantity
No.
/Components/Trainer kit
1 Hardware: Computer (i3-i5 preferable)
Computer System
2 Operating System Windows/ Linux/ MAC
As Per
3
Software JAVA IDE Batch
Size
4
Web Browser Edge, Firefox, Chrome or
similar

J. Safety and necessary Precautions followed.

NA

K. Source code:

L. Observations and Calculations/Input-Output:

M. Practical Related Quiz/Questions:


53 | Page
Advanced JAVA Programming (4351603)

1. Explain the role of JSP scripting elements: scriptlet, expression, and


declaration.
2. What is the difference between JSP and servlets?

N. References / Suggestions
1) https://www.tutorialspoint.com/jsp/jsp_form_processing.htm

2) https://www.javatpoint.com/registration-form-in-jsp

3) https://dotnettutorials.net/lesson/jsp-form-processing/

O. Assessment-Rubrics

Faculty
Marks Date
Signature
Obtained

Program Implementation Studnet’s Total


correctness and engagement in
Presentation practical (10)
(4) Methodology activities

R1 (3) (3)

R2 R3

Sign with Date

54 | Page
Advanced JAVA Programming (4351603)

Date: ……………

Practical Develop a JSP web application to select shopping products, buy any
No:11 products and product billing page using session management.

A. Objective: JSP session management is to maintain user sessions and store session-
specific data for personalized, stateful, and secure web interactions.
B. Expected Program Outcomes (POs)
Po1 - Basic and Discipline specific knowledge.
Po2 - Problem analysis.
Po3 - Design/ development of solutions.
Po4 - Engineering Tools, Experimentation and Testing.
Po6 - Project Management.
Po7 - Lifelong learning.

C. Expected Skills to be developed based on competency:


1) Understand JSP Session Management.
2) Follow coding standards and debug program to fix errors.

D. Expected Course Outcomes (Cos)

CO4: Develop JSP based applications with database connectivity.

E. Practical Outcome (PRo)

Students will be able to use JSP Application with session management and tracking
session data.

F. Expected Affective domain Outcome (ADos)

1) Follow safety practices.


2) Follow Coding standards and practices.
3) Demonstrate working as a leader/ a team member.
4) Follow ethical practices.
5) Maintain tools and equipment.

55 | Page
Advanced JAVA Programming (4351603)

G. Prerequisite Theory:

❖ To develop a JSP session management application, you can follow these steps:

○ Set up a Development Environment: Install a web server like Apache Tomcat


and configure it with your preferred IDE, such as Eclipse or IntelliJ IDEA.
○ Create a New Dynamic Web Project: Create a new dynamic web project in
your IDE.
○ Design User Interfaces: Design the user interfaces (JSP pages) for login,
registration, and other relevant pages using HTML and JSP tags.
○ Handle User Authentication: Implement user authentication mechanisms
like username/password validation. Upon successful authentication, create
a session and store session-specific data.
○ Store Session Attributes: Use the session object (available in JSP as session)
to store session attributes. Store user-related data or any other session-
specific information that needs to persist throughout the session.
○ Manage Session Expiration: Set the session timeout period, specifying how
long the session should be active without any activity. Handle session
expiration by removing session attributes and redirecting the user to the
login page.
○ Implement Logout Functionality: Provide a logout option to invalidate the
session, removing all associated session attributes and redirecting the user
to the login page.
○ Test and Debug: Test the application by running it on the web server. Verify
session creation, session attribute storage, expiration, and logout
functionality.
○ Handle Session Errors: Handle any session-related errors or exceptions
gracefully by displaying appropriate error messages or redirecting the user
to an error page.

Remember to handle security aspects carefully, such as preventing session hijacking,


protecting sensitive data, and implementing secure authentication and
authorization mechanisms.

56 | Page
Advanced JAVA Programming (4351603)

H. Experimental set up/ Program Logic-Flow chart:


N/A
I. Resources/Equipment Required

Sr. No. Instrument/Equipment


Specification Quantity
/Components/Trainer kit

Computer (i3-i5 As Per


1 Hardware: Computer Batch
preferable)
System Size
2 Operating System Windows/ Linux/ MAC

JAVA IDE
3 Software

4 Web Browser Edge, Firefox, Chrome or similar

J. Safety and necessary Precautions followed.


NA

K. Source code:

L. Input-Output:

M. Practical Related Quiz/Questions:


1. Write the importance of session tracking in web applications.
2. Explain the concept of session attributes in JSP.

N. References / Suggestions

1) https://www.w3schools.in/jsp/session

2) https://www.javatpoint.com/session-implicit-object

57 | Page
Advanced JAVA Programming (4351603)

O. Assessment-Rubrics

Faculty
Marks Date
Signature
Obtained

Program Implementation Studnet’s Total


correctness and Presentation engagement in
Methodology practical activities (10)
(4)
(3) (3)
R1
R2 R3

Sign with Date

58 | Page
Advanced JAVA Programming (4351603)

Date: ……………

Practical Develop a JSP program for student registration for new admission in
No:12 college and display stored data it into admin dashboard.

A. Objective: JSP database application is to interact with a database to store, retrieve,


manipulate, and present data dynamically through JSP pages.
B. Expected Program Outcomes (POs)
Po1 - Basic and Discipline specific knowledge.
Po2 - Problem analysis.
Po3 - Design/ development of solutions.
Po4 - Engineering Tools, Experimentation and Testing.
Po6 - Project Management.
Po7 - Lifelong learning.

C. Expected Skills to be developed based on competency:


1) Apply database logic with JSP page.
2) Follow coding standards and debug programs to fix errors.
D. Expected Course Outcomes (Cos)

CO4: Develop JSP based applications with database connectivity.


E. Practical Outcome (PRo)

Students will be able to apply different JSP tags with the database.

F. Expected Affective domain Outcome (ADos)


1) Follow safety practices.
2) Follow Coding standards and practices.
3) Demonstrate working as a leader/ a team member.
4) Follow ethical practices.
5) Maintain tools and equipment.

59 | Page
Advanced JAVA Programming (4351603)

G. Prerequisite Theory:
❖ To create a JSP registration page with a database, you can follow these steps:
○ Set up Database: Create a database and the required table(s) to store user
registration data.
○ Create JSP Registration Page: Design a JSP page with form fields for user
registration, such as username, password, email, etc.
○ Establish Database Connection: Write Java code to establish a connection
with the database using JDBC (Java Database Connectivity).
○ Retrieve User Input: Capture user input from the registration form using JSP
or Java code.
○ Validate User Input: Validate the user input to ensure data integrity and
perform necessary checks, such as checking for duplicate usernames or
password strength.
○ Insert Data into the Database: Use SQL queries or prepared statements to
insert the user registration data into the database table.
○ Display Success/Failure Message: Based on the result of the database
operation, display a success or failure message on the JSP registration page.
○ Close Database Connection: Properly close the database connection to
release resources.
○ Test and Debug: Run the application and test the registration page by
entering user details. Verify if the data is successfully inserted into the
database.
○ Enhance Functionality: Add additional features as needed, such as email
verification, password encryption, or CAPTCHA for enhanced security.

H. Experimental set up/ Program Logic-Flow chart:


N/A

60 | Page
Advanced JAVA Programming (4351603)

I. Resources/Equipment Required

Sr. No. Instrument/Equipment


Specification Quantity
/Components/Trainer kit

Computer (i3-i5 As Per


1 Hardware: Computer Batch
preferable)
System Size
2 Operating System Windows/ Linux/ MAC

JAVA IDE
3 Software

4 Web Browser Edge, Firefox, Chrome or similar

J. Safety and necessary Precautions followed.


NA

K. Source code:

L. Input-Output:

M. Practical Related Quiz/Questions:

1. Write different ways to handle database transactions in a JSP


application.

2. Explain pagination or filtering of database results in a JSP application

N. References / Suggestions

1) https://www.tutorialspoint.com/jsp/jsp_database_access.htm

2) https://www.javaguides.net/2019/01/jsp-jdbc-mysql-example.html

61 | Page
Advanced JAVA Programming (4351603)

O. Assessment-Rubrics

Faculty
Marks Date
Signature
Obtained

Program Implementation Studnet’s Total


correctness and Presentation engagement in
Methodology practical activities (10)
(4)
(3) (3)
R1
R2 R3

Sign with Date

62 | Page
Advanced JAVA Programming (4351603)

Date: ……………

Practical Develop a Web MVC Architecture based application to provide user Login
No:13 and Register using Spring Boot.

A. Objective: Application is to provide a secure and user-friendly platform for user


registration, storing registration data in a database, and performing necessary
validations and actions.
B. Expected Program Outcomes (POs)
Po1 - Basic and Discipline specific knowledge.
Po2 - Problem analysis.
Po3 - Design/ development of solutions.
Po4 - Engineering Tools, Experimentation and Testing.
Po6 - Project Management.
Po7 - Lifelong learning.

C. Expected Skills to be developed based on competency:


1) Understand MVC Architecture and Spring Boot.
2) Follow coding standards and debug program to fix errors.

D. Expected Course Outcomes (Cos)


CO5: Apply MVC architecture using Spring framework.

E. Practical Outcome (PRo)

Students will be able to understand Spring Boot application development with


validation of data.

F. Expected Affective domain Outcome (ADos)

1) Follow safety practices.


2) Follow Coding standards and practices.
3) Demonstrate working as a leader/ a team member.
4) Follow ethical practices.
5) Maintain tools and equipment.

63 | Page
Advanced JAVA Programming (4351603)

G. Prerequisite Theory:

❖ To create a login and registration form using Spring Boot, you can follow these
steps:
● Set up Development Environment: Install Java Development Kit (JDK) and
your preferred IDE (e.g., Eclipse, IntelliJ IDEA) with Spring Boot support.
● Create a Spring Boot Project: Create a new Spring Boot project using your
IDE or the Spring Initializr (https://start.spring.io/). Include the necessary
dependencies for web, security, and database access.
● Design Login and Registration Forms: Design HTML forms for login and
registration, including input fields for username, password, email, etc. Use
Thymeleaf or any other templating engine supported by Spring Boot for
server-side rendering.
● Implement User Entity and Database Schema: Define a User entity class to
represent user data and create the corresponding database schema using
an ORM tool like Hibernate or Spring Data JPA.
● Implement User Service: Create a UserService class to handle user-related
operations, including user registration, authentication, and retrieval from
the database.
● Implement Controllers: Create Spring MVC controllers to handle HTTP
requests for login and registration. Map these requests to appropriate
methods in the controllers.
● Implement Registration Functionality: In the registration controller, validate
user input, create a new User object, and save it to the database using the
UserService.
● Implement Login Functionality: In the login controller, validate user
credentials, authenticate the user using Spring Security, and redirect to the
appropriate page based on the authentication result.

64 | Page
Advanced JAVA Programming (4351603)

● Configure Spring Security: Set up Spring Security configuration to handle


user authentication, authorization, and password encoding. Customize
security settings as per your application requirements.
● Test and Debug: Run the Spring Boot application and test the login and
registration forms by entering user details. Verify if the data is correctly
stored in the database and authentication works as expected.

H. Experimental set up/ Program Logic-Flow chart:


N/A

I. Resources/Equipment Required

Sr. No. Instrument/Equipment


Specification Quantity
/Components/Trainer kit

Computer (i3-i5 As Per


1 Hardware: Computer Batch
preferable)
System Size
2 Operating System Windows/ Linux/ MAC

JAVA IDE
3 Software

4 Web Browser Edge, Firefox, Chrome or similar

J. Safety and necessary Precautions followed.


NA

K. Source code:

65 | Page
Advanced JAVA Programming (4351603)

L. Input-Output:

M. Practical Related Quiz/Questions:

1. How does Spring Boot simplify application development?


2. Explain configuration properties in a Spring Boot application

N. References / Suggestions

1)https://www.javaguides.net/2018/10/user-registration-module-using-
springboot-springmvc-springsecurity-hibernate5-thymeleaf-mysql.html

2)https://www.codejava.net/frameworks/spring-boot/user-registration-and-
login-tutorial
O. Assessment-Rubrics

Faculty
Marks Date
Signature
Obtained

Program Implementation Studnet’s Total


correctness and Presentation engagement in
Methodology practical activities (10)
(4)
(3) (3)
R1
R2 R3

Sign with Date

66 | Page
Advanced JAVA Programming (4351603)

Advanced JAVA Programming


4351603
Lab manual
Prepared By:

Mr. AJAYKUMAR BAROT


Lecturer
Government Polytechnic College, Himatnagar
&
Mr. UMANG SHUKLA
Lecturer
Dr.S & S.S Gandhi College (Diploma), Surat

Branch Coordinator
Mr. Nandu Fatak
HOD(IT)
Government Polytechnic for Girls, Ahmedabad

Committee Chairman
Shri R. D. Raghani
(HOD-EC)
Principal (I/C)
Government Polytechnic, Gandhinagar

67 | Page

You might also like