Java Sample Questions
1. Define Synchronization in thread and How does it work?
2. Define thread Priorities with priority constant.
3. Write a program to implement wait() and notify() function to print
numbers in alternate order.
4. Explain Expression tag and declaration tag in JSP.
5. What are functional interfaces and implement predicate interface
using Anonymous class.
6. Explain Records and Sealed class in Java with a program each.
7. What are JSP Directives and Implicit objects.
8. What is JSP Session. How it can be implemented?
9. What are http methods ?
10. Explain Dependency Injection DI, IoC, MVC, Spring and
SpringBoot.
11. Explain try, catch , throws and throw in exception handling.
12. How iterator is used in java with collection?
13. Classes used in list interface
14. Differentiate Stack, Vector, HashMap
15. How comparator is different from comparable interface? How
they can be used in java to sort elements.
Programs to Implement
1. Apply a Java program where two threads print numbers from 1 to 5. Use Thread class
and Runnable interface for the two threads. Print each on alternate lines.
2. Apply “try with resource” to print the string "Hi Welcome to Jumanji"
to a file.
3. Simulate a train reservation system where multiple users book tickets concurrently.
Use threads and synchronization to avoid overbooking.
4. Use a record class to represent a student with name, rollNo, and marks. Store 3
student records in a list and display them.
5. Write a program demonstrating Lambda expression and Stream filter to process a list
of integers, and filter the even numbers from the list.
6. Implement a Java program to find odd no of elements from an ArrayList using
StreamAPI.
7. Stream API with filter( ) and map( ).
8. Apply the concept of functional interface, lambda expression and anonymous class.
9. Write a program to demonstrate request dispatcher.
Java Programs (Stream and Lamda Expression)
1. Sum two integers using lambda expression
2. Check if a string is empty using lambda
3. Filter even and odd numbers with lambda
4. Convert strings to upper/lowercase using lambda
5. Find average of doubles using lambda
6. Sort strings alphabetically using lambda
7. Remove integer duplicates using lambda
Java Sample questions
1. Imagine you are developing a software system for a Smart
Home. The home has 4 different types of devices, and each
device has a specific name, makes a specific notification sound,
and has behaviors like turnOn() and turnOff() that behave
differently depending on the device. You are required to design
this system in Java using interfaces having methods name(),
sound(), turnOn(), and turnOff(). Perform runtime
polymorphism and print the specific name, sound, and on/off
behavior of all 4 devices.
2. Imagine you are developing a software system for a sports academy. The
academy trains 4 different types of players, and each player has a specific name,
makes a specific motivational sound/cheer, and has behaviors like play() and
train() that behave differently depending on the sport. You are required to design
this system in Java using interfaces having methods name(), sound(). Perform
runtime polymorphism and print the specific name, sound, and play/train
behavior of all 4 players.
3. Imagine you are developing a software system for a Library. The
library manages student memberships and book borrowing. You
need to design an exception hierarchy that includes two
custom exceptions:
MemberNotFoundException → thrown when the
student/member details don’t exist in the library records.
BookNotAvailableException → thrown when the requested
book is not available or already issued.
Write Java code to call MemberNotFoundException if the details
of the student/member don’t exist, and
BookNotAvailableException if the requested book is unavailable.
4. Imagine you are developing a software system for a Hospital.
The hospital manages patient records and treatments. You need
to design an exception hierarchy that includes two custom
exceptions:
PatientNotFoundException → thrown when patient details
don’t exist in the hospital records.
InsufficientInsuranceCoverageException → thrown when the
patient’s insurance coverage is less than the required treatment
cost.
Write Java code to call PatientNotFoundException if the patient
details don’t exist, and InsufficientInsuranceCoverageException if
the insurance coverage is insufficient.
5. Imagine you are developing a Spring application for a School
Management System. The system has two POJO classes:
Student and [Link] Student class contains three properties:
name, rollNo, and a reference to [Link] Course class
contains two properties: courseName and duration.
You are required to apply the concepts of Dependency
Injection (DI) and Inversion of Control (IoC) to create a
Spring application where the Course object is injected into the
Student object using getter and setter methods.
6. Imagine you are developing a Spring application for a Bank
Account Management System. The system has two POJO
classes: Customer and Account.
The Customer class contains three properties: name, customerId,
and a reference to Account.
The Account class contains two properties: accountNumber and
accountType.
You are required to apply the concepts of Dependency
Injection (DI) and Inversion of Control (IoC) to create a
Spring application where the Account object is injected into the
Customer object using getter and setter methods.
7. You are developing a Java application to manage University
Student data. The administrator enters student details using
fields like student name, roll number, course, highest
marks, lowest marks through a form in JSP. The JSP form action
must perform CRUD operations on MySQL using JDBC: Create
Table Student in the database using JDBC PreparedStatement.
Insert rows of all the form’s fields’ information into the
database.
Delete the lowest marks record from the database.
Retrieve remaining student details from the database and
display them using JSP.
8. You are developing a Java application to manage E-Commerce
Product data. The administrator enters product details using
fields like product name, price, quantity, highest discount,
lowest discount through a form in JSP. The JSP form action must
perform CRUD operations on MySQL using JDBC:
Create Table Product in the database using JDBC
PreparedStatement. Insert 2 rows. Delete record. Retrieve
product details.