Lab Workbook Final Copy - Copy Aoop
Lab Workbook Final Copy - Copy Aoop
STUDENT ID:
STUDENT NAME:
STUDENT ID: ACADEMIC YEAR: 2024-25
STUDENT NAME:
Table of Contents
S.no Date Experiment Pre In-Lab (25M) Post Viva Total Faculty
Lab Program/ Data Analysis Lab Voce (50M) Signature
(10M) Procedure and & (10M) (5M)
(5M) Results Inference
(10M) (10M)
1 Introductory Session
18 Servlets
1. Introductory Session
Pre-Lab:
1) Explain how a Java class helps in structuring and organizing code in software
development.
In-Lab:
1) Write a java program that how encapsulation and inheritance are used to design a library
system that manages different types of items such as books, magazines, and DVDs,
each having both common and unique properties and behaviours.
Procedure/Program:
Post-Lab:
Aim/Objective: To understand the concept and implementation of Singleton for the real time
scenarios.
Description: The student will understand the concept of Creational Design Patterns (Singleton)
Pre-Lab:
2) Draw the UML Relationship Diagram for Factory Design Pattern for any customized
scenario.
In-Lab:
1) Write a Java Program on Singleton Pattern for Real-life Logging System Scenario
One common use case for the Singleton pattern is in implementing logging
systems, where it’s important to ensure that only one instance of the logger is used
throughout the entire application.
Note: The Logger class uses the Singleton pattern to ensure that only one
instance of the logger is created and used throughout the entire application. The Instance
property provides a way to access the single instance of the logger, and the Log method
can be used to log messages.
Procedure/Program:
2) In a server application, managing configurations like API keys, server settings, and max
connections is crucial. To ensure that there is only one configuration manager handling
these settings, we can use the Singleton pattern. This ensures consistency and prevents
multiple instances from causing conflicts.
Implementation
A. ConfigurationManager Class: This class will use the Singleton pattern to
manage server configurations.
B. Properties and Methods: It will have methods to get and set configuration
values.
1) Which classes are candidates of Singleton? Which kind of class do you make Singleton
in Java?
Post-Lab:
1) In a Banking process, create a Singleton pattern to manage the Login state of the user
in all the operations like View Balance, Deposit & Withdraw.
Note: Create a Singleton Class to maintain the User Login-State.
Procedure/Program:
Aim/Objective: To analyse the implementation of Factory and Abstract Design Patterns for
the real time scenarios.
Description: The student will understand the concept of Creational Design Patterns (Factory
and Abstract Factory)
Pre-Lab:
2) Draw the UML Relationship Diagram for Factory Design Pattern for any customized
scenario.
In-Lab:
1) Develop a game application with multiple levels and varying difficulty settings.
Implement the following design patterns to manage different aspects of the game:
Singleton Pattern: Use this pattern to manage the game state, ensuring that there is
only one instance of the game state throughout the application.
Factory Method Pattern: Apply this pattern to create different types of enemies for
each level.
Abstract Factory Pattern: Utilize this pattern to create various types of weapons and
power-ups based on the level and difficulty settings.
Ensure that the design of your game is flexible and can easily accommodate new levels,
enemies, weapons, and power-ups in the future.
Procedure/Program:
1) Which classes are candidates of Singleton? Which kind of class do you make Singleton
in Java?
2) Discuss the difference between Factory and Abstract Factory design patterns.
Post-Lab:
1) Design and implement a ride-sharing application that allows users to request rides from
various types of vehicles (cars, bikes, scooters). Utilize the Factory Method pattern to
create vehicle instances, the Abstract Factory pattern to implement different payment
methods (credit card, PayPal, cash), and the Singleton pattern to manage user
authentication securely. Provide a detailed example demonstrating the interaction of
these patterns within the application.
Procedure/Program:
Aim/Objective: To analyse the implementation of Adapter and Decorator Design Patterns for
the real-time scenario.
Description: The student will understand the concept of Adapter and Decorator Design
Patterns.
Pre-Lab:
1) Draw the UML Relationship Diagram for Adapter Design Pattern for Mobile charger
adapter scenario. Note: Mobile battery needs 3 volts to charge but the normal socket
produces either 120V (US) or 240V (India). So, the mobile charger works as an adapter
between mobile charging socket and the wall socket.
2) State about Structural Design Pattern with example and list all the types of Structural
Design Pattern.
In-Lab:
1) Develop a music streaming application that can play music from various sources, such
as local files, online streaming services, and radio stations. Implement the following
design patterns to achieve this functionality:
Adapter Pattern: Adapt different music sources to a common interface.
Decorator Pattern: Add additional features (e.g., equalizer, volume control) to the
music playback.
Your task is to design and implement the application using these design patterns to
ensure flexibility, scalability, and maintainability.
Procedure/Program:
1) State how the adapter pattern allows the objects with incompatible interfaces to
collaborate.
2) Discuss about Adapter Pattern by considering the scenario of a USB to Ethernet adapter.
Post-Lab:
1) Implement the below depicted UML Diagram in Java Program with respective to
Adapter Pattern
Procedure/Program:
Aim/Objective: To analyse the implementation of Adapter and Decorator Design Patterns for
the real-time scenario.
Description: The student will understand the concept of Adapter and Decorator Design
Patterns.
Pre-Lab:
In-Lab:
1) Develop a music streaming application that can play music from various sources, such
as local files, online streaming services, and radio stations. Implement the following
design patterns to achieve this functionality:
Adapter Pattern: Adapt different music sources to a common interface.
Bridge Pattern: Decouple the music playback functionality from the music source.
Decorator Pattern: Add additional features (e.g., equalizer, volume control) to the
music playback.
Your task is to design and implement the application using these design patterns to
ensure flexibility, scalability, and maintainability.
Procedure/Program:
Post-Lab:
Procedure/Program:
Pre-Lab:
1) Draw the UML Relationship Diagram for Chain of Responsibility Design Pattern for
customized Scenarios.
2) Draw the UML Relationship Diagram for Iterator Design Pattern for customized
Scenarios.
In-Lab:
1) You are required to design and implement a logging system in Java that processes log
messages of different severity levels: INFO, DEBUG, and ERROR. The system
should utilize the Chain of Responsibility, Command, and Iterator design patterns.
Below are the detailed requirements:
A. Severity Levels:
a. INFO: General information about system operations.
b. DEBUG: Detailed information typically used for diagnosing problems.
c. ERROR: Error conditions indicating problems that need to be
addressed.
B. Handlers:
a. Each handler is responsible for processing messages of a specific
severity level.
b. Handlers should be linked in a chain such that if a handler cannot
process a message, it passes the message to the next handler in the
chain.
C. Command Pattern:
a. Use the Command pattern to encapsulate the logging requests.
b. Define a Command interface with an execute(String message) method.
c. Implement a LogCommand class that executes logging requests using
handlers.
D. Iterator Pattern:
a. Use the Iterator pattern to manage a list of commands.
b. Create a Logger class that maintains a list of Command objects and
processes them sequentially.
E. Implementation Steps:
a. Define an enum LogLevel to represent the severity levels.
b. Implement the Command interface and LogCommand class.
c. Create an abstract LogHandler class and concrete handler classes
(InfoHandler, DebugHandler, ErrorHandler) for each severity level.
d. Implement the Logger class that uses an iterator to process commands.
e. Provide a client class to configure the chain of responsibility, create
commands, and process log messages.
Procedure/Program:
Pre-Lab:
1) Draw the UML Relationship Diagram for Template Design Pattern for customized
Scenarios.
2) Draw the UML Relationship Diagram for Observer Design Pattern for customized
Scenarios.
In-Lab:
1) Design an online auction system that utilizes the Observer and Template design
patterns to manage auction events and bidding processes efficiently.
Requirements:
A. Observer Design Pattern:
o Use the Observer pattern to notify bidders about auction events such as
item availability, bidding start, and bidding end.
o Bidders should be able to subscribe and unsubscribe to receive
notifications.
o Implement the Template pattern to define the structure and steps of the
auction process.
o Customize specific steps for different types of auctions (e.g., standard
auction, reserve auction).
Procedure/Program:
Procedure/Program:
Post-Lab:
1) Imagine you are developing a weather monitoring system that notifies various displays
when the weather conditions change. The system involves multiple displays that need
to stay updated with the latest weather data in real-time. Implement the Observer design
pattern to achieve this functionality.
Requirements:
A. Subject Interface: WeatherStationSubject
a. Define an interface WeatherStationSubject that declares
methods to register, remove, and notify observers.
B. Observer Interface: WeatherObserver
a. Define an interface WeatherObserver that declares a method
for updating when notified by the subject.
C. Concrete Subject: WeatherStation
a. Implement the WeatherStationSubject interface in a class
called WeatherStation. This class will maintain a list of
observers and notify them when weather data changes.
D. Concrete Observers: Display Devices
a. Implement WeatherObserver interface in various display
devices such as CurrentConditionsDisplay, StatisticsDisplay,
and ForecastDisplay. These displays will update their
information whenever the weather data changes.
Procedure/Program:
2) Design a scenario that incorporates the Template Method, Dependency Injection, and
Observer patterns in Java. The scenario will be a notification system where different
types of notifications (Email, SMS, and Push) are sent based on user events (e.g., user
registration, password reset).
A. Template Method Pattern: Use this pattern to define the steps of sending a
notification, allowing subclasses to implement specific steps for different
notification types.
B. Dependency Injection: Use this pattern to inject the specific notification
service into a notifier class.
C. Observer Pattern: Use this pattern to observe user events and trigger the
appropriate notifications.
Procedure/Program:
Description: The student will understand the concept of SOLID Principles & Test-Driven
Development (TDD).
Pre-Lab:
In-Lab:
1) Develop a Student Information System (SIS) that adheres to SOLID design principles,
where you need to manage the Student Information System (SIS) with the incorporation
of the concepts of Classes, Objects, Constructors, Interfaces and inheritance.
Requirements
1. Student Management:
o Manage student details such as name, ID, and courses enrolled.
2. Course Management:
o Manage course details such as course ID, course name, and list of enrolled
students.
3. Enrollment Management:
o Handle the enrollment of students in courses.
Procedure/Program:
2) During an NCC parade, a large number of cadets participated, and the leader instructed
them to stand in a line sorted alphabetically by their names for easier identification.
After organizing the cadets in alphabetical order, the leader wants to verify whether
they are indeed standing in the correct sorted order.
You as the leader, construct a JUnit test program to validate the cadet’s arrangement
and ensure it aligns with the expected alphabetical sorting order. The test program
should include various scenarios such as an empty list of cadets, a single cadet, multiple
cadets with different names, and cadets with identical names and also assertions within
the unit test to verify the correctness of the cadet’s alphabetical arrangement.
Procedure/Program:
5) What is the problem of not having Interface segregation principle in SOLID principles>
Post-Lab:
1) Write a Test-Driven Development program to accept the password when the length of
it should be between 5 to 10 characters (“Password validator”)
Input: Abc123
Output: Valid
password: accepted
Procedure/Program:
2) Write a Java program to check whether the given number is odd or even and do unit
testing in JUnit.
Procedure/Program:
Aim/Objective: To analyse the implementation of the concept of Generics with Interfaces for
the real time scenario.
Description: The student will understand the concept of Generics with Interfaces.
Pre-Lab:
In-Lab:
1) Write a Java Program to identify the Maximum Value and Minimum Value in the arrays
of different datatypes like Integer, String, Character & float by incorporating the
concept of Generics with interfaces.
Procedure/Program:
Post-Lab:
1) Create a generic class that implements a binary search algorithm. Test the class with
different data types such as integers, doubles, and strings.
Procedure/Program:
2) Create a generic method that sorts an array of objects using a bubble sort algorithm.
Test the method with different types of objects such as integers, doubles, and strings.
Procedure/Program:
Aim/Objective: To analyse the implementation of the concept of Stacks and Queues with
Interfaces for the real-time scenario.
Description: The student will understand the concept of Stacks and Queues.
Pre-Lab:
1) Write a JAVA program for Basic ADT Operations on Stack Data Structure.
2) Write a JAVA program for Basic ADT Operations on Queue Data Structure.
In-Lab:
1) Create a generic interface for a stack data structure with additional methods for peeking
at the top element without removing it and checking if the stack is empty. Implement
the interface using a linked list and an array. Test the implementations with different
data types.
Procedure/Program:
Post-Lab:
1) Create a generic class that implements a priority queue data structure. Test the class
with different data types such as integers, doubles, and strings.
Procedure/Program:
Description: Student will be able to understand and apply the concept of Comparator and
Comparable Interfaces.
Pre-Lab:
1) Discuss the differences between Comparator and Comparable by filling the below
mentioned table.
2.
3.
4.
2) Write a Java program that sorts a Linked List using the Comparable interface.
In-Lab:
1) Create a Java program that sorts a list of Movie objects by their year of release. Define
the Movie class with attributes such as rating, name, and year. Implement the
Comparable interface in the Movie class and override the compareTo() method to sort
the movies based on their release year.
Program:
2) You are tasked with developing a system to manage employee records for a large
corporation. The Employee class has attributes such as id, name, department, and salary.
Different departments and teams need to sort employee records based on different
criteria, such as salary, name, and department.
Implement a Java program that sorts a list of Employee objects using the Comparator
interface. The program should allow sorting by multiple criteria: by salary (ascending
and descending), by name (alphabetical order), and by department (alphabetical order).
Program:
4) What happens if you do not override the compareTo method when implementing
Comparable?
Post-Lab:
1) Develop a Java program to compare movies by their ratings using a custom Comparator
implementation. Your program should follow these steps: a. Implement a class that
serves as a Comparator for Movie objects, providing the comparison logic based on
movie ratings. b. Instantiate the Comparator class. c. Utilize the overloaded sort ()
method, passing both the list of movies and the instance of the Comparator class to
perform the sorting.
Sample Input:
Program:
Aim/Objective: To understand the concept and implementation of the Cloneable and Iterator
interfaces.
Description: The student will understand the Cloneable and Iterator interface.
Pre-Lab:
2) Draw a class diagram illustrating the relationship between the Cloneable and Iterator
interfaces and a class that implements both interfaces.
In-Lab:
4) What are the methods provided by the Iterator interface? Explain their significance.
5) Can you explain the difference between the Cloneable interface and the Clone method
in Java?
Post-Lab:
1) Create a class called "Student" that represents student information. This class has
attributes such as name, roll number, and marks. Implement the Cloneable interface in
the student class and write a code snippet to demonstrate the cloning of a student object.
Write code to demonstrate the cloning functionality.
Procedure/Program:
Aim/Objective: To understand the concept and implementation of concepts of sets and maps.
Description: The student will understand the concepts of sets and maps.
Pre-Requisites: Classes and Objects, HashMap, TreeMap, HashSet and TreeSet in JAVA.
Pre-Lab:
1) Explain the concept of a set in Java. What is the main characteristic of a set? Provide
an example code snippet demonstrating the usage of a set.
2) Draw a UML diagram showing the relationship between the Set interface, the
Collection interface, and two implementations of Set: HashSet and TreeSet.
In-Lab:
1) You are tasked with developing a contact management application where you need to
store a collection of contacts. Each contact has a name and a phone number. Implement
a class called ContactManager that uses a map to store the contacts, with the contact’s
name as the key and the phone number as the value. Write code to demonstrate the
implementation of the ContactManager class.
Requirements
1. ContactManager Class:
o Use a map to store contacts.
o The key of the map is the contact’s name (String).
o The value of the map is the phone number (String).
o Provide methods to add, remove, and retrieve contacts.
o Provide a method to list all contacts.
2. Demonstration:
o Create an instance of ContactManager.
o Add several contacts.
o Retrieve and display a contact's phone number.
o Remove a contact.
o List all contacts.
Procedure/Program:
2) You are working on a program that stores student grades. Each student has a unique ID
assigned to them. Design a data structure using sets and maps to efficiently store and
retrieve student grades based on their ID. Write the code for adding a student's grade to
the data structure given their ID and grade.
Procedure/Program:
5) What is the purpose of the key-value pairs in a map? Can the same key have multiple
values?
Post-Lab:
1) Given a set of integers, write a code snippet to find the maximum value in the set.
Procedure/Program:
2) Write a Java program that uses a Set to store a list of fruits. The program should then
iterate over the Set and print out the fruits in alphabetical order.
Procedure/Program:
14. Nested Classes, Functional interfaces, Lambda Expressions and Stream API
Aim/Objective: To implement the concepts of Lambda expression and Stream API to solve
real world data through Collection classes.
Description: The student will understand the concepts of Nested classes, lambdas and stream
api for efficient processing of data in a Collection.
Pre-Lab:
1) Explain the difference between static nested classes and inner classes.
4) Write a stream pipeline that filters a list of integers to only even numbers, doubles them,
and then collects them into a list.
In-Lab:
1) Consider a Coffee shop which has staff member count of 5. Employer at the end of the
month, before giving the salaries to the employees, employer asked them to stand in a
queue where employee having more experience should stand first and later followed by
less experience so on. Employee has attributes like name, age and experience. You as
an employer should distribute salary along with bonus.
Bonus should be given to the employees based on experience.
Employee1 has experience 5 years
Employee2 has 4 years
Employee 3 has 3 years,
Employee 4 has 1 year and
Employee 5 is a fresher.
Filter the employees who have experience more than 2 years should be given bonus.
Make use of Predicate interface and construct the scenario.
Procedure/Program:
1) What is an anonymous inner class, and when would you use one?
4) Explain the difference between collect() and reduce() in the Stream API.
Post-Lab:
1) You are tasked with designing an Employee Management System for a company. The
system needs to handle various operations on a list of employees using the Java
Stream API. Each employee has attributes such as ID, name, department, salary, and
age. The operations include filtering, sorting, grouping, and aggregation.
Requirements
1. Data Model:
o Create an Employee class with attributes: id, name, department, salary, and
age.
2. Operations:
o Filter employees based on department.
o Sort employees by salary in descending order.
o Group employees by department.
o Find the highest-paid employee.
o Calculate the average salary of employees in a department.
o List the names of employees who earn more than a specified amount.
Procedure/Program:
Aim/Objective: To explore the basics of concurrent programming and understand the concepts
of threading in Java.
Description: The student will gain an understanding of Java threading, encompassing the
fundamentals of threads, their creation, synchronization, and communication, enabling
concurrent execution of multiple tasks within a program.
Pre-Lab:
1) Explain what a thread is in Java and how it facilitates concurrent execution, as well as
implement a sample task of your choice by performing actions such as extending the
Thread class and implementing the Runnable interface?
2) How can you implement five functions (printTwo, printThree, printFour, printFive, and
printNumber) using multiple threads to print numbers from 1 to 15, where each function
prints a message if the number is divisible by 2, 3, 4, or 5, and printNumber prints the
number if none of these conditions are met?
Program:
In-Lab:
Expected Results:
Program:
4) explain the terms "synchronization" and "thread safety" in the context of threading.
Post-Lab:
Program:
Description: The student will understand the concepts of the Producer-Consumer pattern,
which is used to solve the problem of synchronizing access to a shared resource between
multiple threads.
Pre-Lab:
In-Lab:
1) You are tasked with designing a Bank Account Management System where multiple
users can perform transactions on a shared bank account simultaneously. To ensure
the consistency and correctness of the account balance, synchronization is necessary.
Requirements
A. BankAccount Class:
B. Thread Safety:
a. Use synchronization to ensure that deposit and withdrawal operations
are thread-safe.
C. Operations:
a. Multiple threads will simulate users performing deposit and
withdrawal operations concurrently.
Procedure/Program:
B. Consumer Class:
a. Consumes messages from the shared buffer.
b. Uses synchronization to ensure thread safety
C. Shared Buffer:
a. A thread-safe queue to store messages.
Procedure/Program:
2) How does the synchronized keyword ensure that only one thread can access a shared
resource at a time?
3) How does the wait() and notify() methods facilitate inter-thread communication in the
Producer-Consumer pattern?
4) How can you ensure mutual exclusion between the producers and consumers while
accessing the shared buffer?
5) How does the Producer-Consumer pattern ensure thread safety and synchronization?
Post-Lab:
1) Write a code to implement a bounded buffer using the concepts learned in the
experiment. Ensure that the buffer has a maximum capacity of 10 items, and the
producer and consumer threads operate correctly while avoiding race conditions.
Procedure/Program:
Aim/Objective: To understand the how a Java application can be connected with any database
in the world for data persistence.
Pre-Lab:
2) Explain the concept of JDBC and its role in Java database connectivity. What are the
main steps involved in performing database operations using JDBC?
In-Lab:
1) You are developing a Student Information Management System where student details
such as student ID, name, address, and program can be managed through a web
interface. Implement a servlet called StudentDetailsServlet that accepts student details
through a form submission and stores these details in a database using JDBC. Perform
the following steps to create and manage the student database:
Requirements
Procedure/Program:
2) What are the different types of JDBC drivers? Explain their differences and advantages.
5) How do you handle exceptions related to database operations in JDBC? What are some
common JDBC-related exceptions?
Post-Lab:
Aim/Objective: To understand the concept of servlets in Java and implement them in a web
application.
Description: The student will understand the concepts of servlets, which are Java classes used
to extend the functionality of web servers and handle client requests.
Pre-Requisites: Classes, Objects, Java Servlet API, Understanding of HTTP protocol and web
development concepts.
Tools: Eclipse IDE for Enterprise Java and Web Developers, Apache Tomcat - Web Server,
Java Servlet APIs.
Pre-Lab:
1) Explanation of what a servlet is and how it differs from other Java classes. What are the
main advantages of using servlets in web development?
2) Write a servlet application code to print the current date and time.
In-Lab:
1) You are developing a voter eligibility checker web application. The application should
accept the user's age and name through a form submission and display a message
indicating whether the user is eligible for voting or not. In this scenario, implement a
servlet called "VoterEligibilityServlet" that handles the form submission and displays
the eligibility message based on the user's age. If the age is 18 or above, display a
message like "Hello [name], you are eligible to vote!" Otherwise, display a message
like "Hello [name], you are not eligible to vote yet." Ensure proper validation and
error handling for invalid input
Procedure/Program:
3) How can servlets handle user input data submitted through an HTML form?
5) What are the steps involved in configuring and deploying a servlet in a web application
Post-Lab:
1) Write a code demonstrating the usage of request and response objects in a servlet. Use
a scenario where you need to retrieve user input from a form and display a customized
response based on that input the entered data on the web page.
Procedure/Program:
Description: The student will understand the concepts of servlets with JDBC, which allows us
to connect to a database, execute SQL queries, and perform database operations from within a
web application.
Tools: Eclipse IDE for Enterprise Java and Web Developers, Apache Tomcat - Web Server,
Java Servlet API.
Pre-Lab:
1) Explain the concept of JDBC and its role in Java database connectivity. What are the
main steps involved in performing database operations using JDBC?
2) Write a code demonstrating the steps to establish a database connection using JDBC.
Write a java program to accept the details of Teacher (TId, Name, Address) from the
user and insert it into the MySQL database, specifying the necessary connection
parameters such as URL, username, and password.
In-Lab:
Procedure/Program:
2) What are the different types of JDBC drivers? Explain their differences and advantages.
5) How do you handle exceptions related to database operations in JDBC? What are some
common JDBC-related exceptions?
Post-Lab:
20. Handling Form Data in JSP, Processing with Servlet, and Persisting into Database
Aim/Objective: To understand the how to fetch form data in JSP and handle the data by using
Servlet and persist the data into database.
Description: The student will understand creating a web application that collects user input
through a form in a JSP page, processes the submitted data using a servlet, and persists the data
into a database using JDBC.
Pre-Lab:
1) Explain the concept of JSP and its role in web development. How does JSP differ from
servlets? Describe the lifecycle of a JSP page.
In-Lab:
1) Develop a web application that allows users to submit their contact details through a
form on a JSP page. The form data will be processed by a servlet and stored in a
PostgreSQL database.
A. Set Up the Database
Procedure/Program:
1) What is the role of a servlet in handling form data submitted by a user in a JSP page?
2) What is the difference between the request and response objects in servlets?
3) Explain the process of sending form data from a JSP page to a servlet for processing.
4) What is the purpose of the web.xml deployment descriptor file in a Java web
application?
5) How can you access the request parameters sent from a JSP form in a servlet?
Post-Lab:
1) Write a code snippet demonstrating the use of JSP and servlet to handle a login form.
Use a scenario where a user submits a login form, and the servlet validates the
credentials. Your code should include the following:
a. Create a JSP page with a login form that collects username and password.
b. Implement a servlet that receives the form data, validates the credentials, and
redirects the user to a success or error page based on the validation result.
c. Test your program by submitting different login credentials to ensure proper
validation and redirection.
Procedure/Program: