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

OOPS WITH JAVA

Unit 1-
What are the key features of Java that contribute to its "write once, run anywhere" capability?

Explain the roles of the JVM (Java Virtual Machine), JRE (Java Runtime Environment), and JDK
(Java Development Kit) in the Java programming environment.

What are the main components of a simple Java program, and how do they contribute to the
program's execution?

Describe the purpose and usage of command line arguments in a Java program.

Describe the significance of the static keyword in Java. How do static variables and methods
differ from instance variables and methods?

How does the if expression work in Java, and what is the difference between a simple if
expression and a nested if expression?

Unit 2
Create a class Calculator with two overloaded methods add(int a, int b) and
add(double a, double b). Write a main method to demonstrate calling both overloaded
methods.

Define a superclass Parent with a method showMessage(). Create a subclass Child that
tries to override showMessage(). Mark showMessage() in Parent as final and
demonstrate the compilation error that occurs when trying to override it

Define an interface Playable with methods play() and pause(). Create a class
MusicPlayer that implements Playable. Write a main method to demonstrate the use of
MusicPlayer through the Playable interface.

Explain how inheritance promotes code reusability in Java. Provide an example of a superclass
and a subclass.

What is polymorphism in Java, and how is it implemented using method overriding?

Explain how to set the CLASSPATH environment variable to include user-defined packages.
What is the purpose of the final keyword in Java, and how is it used with methods and
variables?
Explain the difference between instance variables and static variables, providing examples.

Unit 3

What is an exception in Java, and how does the JVM handle an exception when it occurs during
program execution?

How do the try, catch, and finally blocks work together to handle exceptions in Java?
Provide a code example to illustrate their use.

What are some common in-built exceptions in Java? Provide examples and describe scenarios
where they might be thrown.

Explain the difference between byte streams and character streams in Java I/O. Provide
examples of classes used for each type of stream.

Write a method that reads a file and prints its contents to the console. Use appropriate
exception handling to manage IOException. Include try, catch, and finally blocks in
your implementation.

Create a user-defined exception InsufficientBalanceException. Write a BankAccount


class with a method withdraw that throws this exception if the withdrawal amount is greater
than the balance. Demonstrate the use of try, catch, and finally blocks to handle this
exception.

Write a method to copy a file using byte streams. Handle any IOException that may occur
during the file operations.

Unit 4-

Describe the life cycle of a thread in Java. What are the different states a thread can be in, and
how does it transition from one state to another?

Explain how inter-thread communication works in Java. What are the roles of the wait(),
notify(), and notifyAll()methods in this process?

What is the Stream API in Java, and what are its main benefits? Provide an example of using
the Stream API to process a collection of data.
What is local variable type inference in Java, and how does it work with the var keyword? What
are the limitations and benefits of using var in your code?

How do you perform Base64 encoding and decoding in Java? Provide an example using the
java. util.Base64 class.

Unit 5-
Explain the hierarchy of the Java Collections Framework. What are the main interfaces and
classes, and how are they related?

What is the purpose of the Iterator interface in Java? How does it differ from the
ListIterator interface?

What is the Queue interface in Java? Discuss its main methods and compare the LinkedList
and PriorityQueueimplementations

What is the SortedSet interface, and how does it ensure elements are in a specific order?
Discuss the TreeSet class as an implementation of SortedSet

Write a Java program to demonstrate the difference between HashSet and


TreeSet. Add elements to both sets and show how they maintain their
order.

Write a Java program that defines a Student class implementing the


Comparable interface. Sort a list of Student objects by their grades.

Write a Java program to demonstrate the difference between HashMap and


LinkedHashMap. Insert several key-value pairs and print the order in
which the entries are stored.

You might also like