PPS Unit 1
PPS Unit 1
PPS Unit 1
Questions of Java
Q 1. What is the difference between JDK and JRE?
Ans: The JDK (Java Development Kit) is used by developers for
creating Java applications and includes the necessary tools,
libraries, and compilers.
01
Q 3. What are the different components of the Java platform?
Ans: The Java platform is a software environment that provides a
standard way for developing and running Java applications. It
consists of the following components:
02
Q 6. What are the different types of Java exceptions?
Ans: There are two types of exceptions in Java: checked exceptions
and unchecked exceptions.
Checked exceptions are exceptions that must be declared in
the method signature. If a checked exception is thrown in a
method, the method must either handle the exception or
declare it to be thrown. If the method does not handle the
exception, the compiler will generate an error.
03
Q 7. What are the different types of Java classes & Java
interfaces?
Ans: There are two main types of Java classes:
Normal classes are the most common type of class in Java.
They can have fields, methods, and constructors.
Abstract classes are classes that cannot be instantiated. They
can only be used as a base class for other classes.
05
Object-Oriented Programming:
06
Q 3. What is the difference between Overloading and
Overriding?
Ans: Overloading refers to the ability to have multiple methods with
the same name, but different parameters.
Ans: Static binding and dynamic binding are two different ways of
resolving function calls in object-oriented programming (OOP).
07
Q 5. What is the difference between Abstract class and
Interface?
Ans: Here is a table that summarizes the key differences between
abstract classes and interfaces:
Feature Abstract Class Interface
Can be instantiated No No
08
Q 7. When do you use interface and abstract class in
Java?
Ans: Abstract classes and interfaces are both used to achieve
abstraction in object-oriented programming.
Abstract classes are similar to normal classes, with the
difference that they can include abstract methods, which are
methods without a body. Abstract classes cannot be
instantiated.
09
Data Structures & Algorithms
Q 1. What is the difference between an array
and a linked list?
Ans: In general, arrays are a good choice for data structures where the
data is accessed frequently and the order of the data is
important.
Linked lists are a good choice for data structures where the data
is inserted or deleted frequently and the order of the data is not
important.
10
Q 3. What is the time complexity of various operations in a
binary search tree (BST)?
Ans: The time complexity of various operations in a binary search tree
(BST) depends on the height of the tree. The height of a BST is the
number of nodes on the longest path from the root node to a leaf
node.
Search O(log n)
Insert O(log n)
Delete O(log n)
All nodes at the current level As far as possible down one path
Explores
before moving on to the next level before backtracking
Time
O(V+E) V
complexity
Space
O(v) V
complexity
Finding the shortest path, finding Finding all of the nodes in a graph,
Use cases all of the nodes in a graph that are finding all of the paths between
reachable from a given node two nodes
11
Q 5. Explain the concept of a priority queue and provide an
example of its application.
Ans: A priority queue is a data structure that stores elements along
with their associated priorities. It allows efficient retrieval of the
element with the highest (or lowest) priority. The priority
determines the order in which elements are processed or
accessed.
12
Q 7. How does a HashSet work internally in Java?
Ans: A HashSet internally uses a HashMap to store its elements. When
you add an element to a HashSet, it is first hashed using the
hashCode() method.
13
Multi-threading
Q 1. What is multithreading, and why is it important in
Java?
Ans: Multithreading is a programming concept that allows multiple
tasks to be executed concurrently. In Java, multithreading is
implemented using the Thread class. A Thread object represents
a single thread of execution.
14
Q 4. How does synchronization work in Java? Explain the
concepts of synchronized methods and blocks.
Ans: Synchronization in Java is a mechanism that allows multiple
threads to access shared resources safely. When a thread is
synchronized on a resource, it is the only thread that can access
that resource.
Synchronized methods
A synchronized method is a method that can only be executed by
one thread at a time. To declare a method as synchronized, you
need to use the synchronized keyword.
Synchronized blocks
A synchronized block is a block of code that can only be executed
by one thread at a time. To declare a block of code as
synchronized, you need to use the synchronized keyword and
specify the object that the block is synchronized on.
15
Q 6. What are the differences between the Thread class and
the Runnable interface in Java?
Ans: The Thread class is a concrete class. while the Runnable interface
is an abstract interface. This means that you can create a new
thread by extending the Thread class, or you can create a new
thread by implementing the Runnable interface.
The key differences between the Thread class and the Runnable
interface:
Implementation Must override the run() method Must implement the run() method
17
Q 3. Describe the try-catch-finally block and its purpose in
exception handling.
Ans: The try-catch-finally block is a Java syntax that allows you to
handle exceptions gracefully. It consists of three parts:
The try block
The catch block
The finally block
18