Advance
Java – Question Bank
Chapter 1: Interfaces
1. What is an interface in Java? Explain how it differs
from a class in terms of method implementation.
2. Explain how variables in an interface are accessed
and state their default modifiers.
3. Create two interfaces Flyable and Swimmable. Write a class Duck implementing both to demonstrate multiple inheritance.
4. Analyze the use of interfaces in achieving multiple inheritance in Java.
5. What is the importance of the implements keyword? Show how a class can implement multiple
interfaces.
6. Define an interface. Explain the syntax for defining
and implementing an interface with a suitable example.
7. How do we extend an interface? Explain with a code
snippet.
8. Evaluate the use of interfaces over abstract classes
in Java. Compare flexibility and reusability.
9. Explain how interfaces are used to achieve multiple inheritance in Java.
10.
What are default
methods and static methods in interfaces? Explain with examples.
11.
Explain
functional interfaces in Java. Give suitable examples (e.g., Runnable, Comparator).
12.
What is a marker
interface? Explain with examples like Serializable.
13.
Compare
interface and abstract class with respect to constructors, variables, and
methods.
Chapter 2: Packages
1. Demonstrate how to create a user-defined package
with steps and commands.
2. Explain the concept of Java packages. What are the
advantages of using packages?
3. Analyze how improper use of packages can lead to naming
conflicts.
4. Compare default package and named package in Java.
5. What are Java API packages? List any three system
packages and their purpose.
6. Evaluate the use of access specifiers
in Java packages. Compare accessibility across packages.
7. Write a Java program to create a package named employee. Define a class Employee and access it from another package.
8. Describe Java API packages and explain any four
commonly used packages.
9. Explain why Java packages are important in
organizing programs.
10.
Explain the role
of the import keyword in Java packages with examples.
11.
Differentiate
between import
package.* and import package.classname.
12.
What is
CLASSPATH? Explain its importance in package execution.
13.
Explain how
package naming conventions help avoid conflicts in large applications.
Chapter 3: Multithreading
1. Explain thread priority and constants: MIN_PRIORITY, NORM_PRIORITY,
MAX_PRIORITY.
2. Describe the purpose of sleep(), yield(), and join() methods.
3. Illustrate different states of a Java thread.
4. Explain the Runnable interface. Why is it preferred
over extending the Thread class?
5. Explain the process of creating a thread by
extending the Thread class.
6. What is thread priority? Explain how to get and set
thread priority.
7. Describe the life cycle of a thread with a neat labeled diagram.
8. Explain thread methods with syntax: sleep(), wait(), and notify().
9. Explain how the synchronized keyword helps maintain data consistency in
multithreading.
10.
What is thread
synchronization? Explain with a suitable example.
11.
Differentiate
between process and thread.
12.
Explain daemon
threads in Java and their use cases.
13.
What is thread
communication? Explain inter-thread communication methods.
Chapter 4: Servlets & Web
Programming
1. Compare Servlets with CGI. Why are Servlets better?
2. Explain the lifecycle of a Servlet (init(), service(), destroy()).
3. What is a web application? Explain the role of a web
server in Java web programs.
4. Write a simple “Hello World” Servlet and explain its
components.
5. Explain the structure of the javax.servlet.http package.
6. Give differences between static web pages and
dynamic pages generated using Servlets.
7. What is the purpose of the init() method? How many times is it called?
8. Differentiate between static and dynamic web pages
with examples.
9. Write a Servlet program to display “Welcome to Java
Servlets” in a browser.
10.
What is the
difference between doGet() and doPost() methods?
11.
Explain the
concept of session tracking in Servlets.
12.
What is ServletConfig and ServletContext? Differentiate between them.
13.
Explain request
and response objects in Servlets with examples.