100 Most Asked Java Interview QnA
100 Most Asked Java Interview QnA
18. What is the difference between the JDK and the JRE?
The JDK (Java Development Kit) is a software development kit that includes the tools needed
to develop Java applications, while the JRE (Java Runtime Environment) is a runtime
environment required to run Java applications.
35. What is the difference between the "synchronized" block and the
"synchronized" method?
A "synchronized" block in Java allows a specific block of code to be synchronized, ensuring
that only one thread can execute it at a time. A "synchronized" method applies
synchronization to the entire method, making it mutually exclusive for all threads.
41. What is the difference between the "throw" and "throws" keywords in
Java?
The "throw" keyword in Java is used to manually throw an exception, while the "throws"
keyword is used in method declarations to specify that the method may throw certain types of
exceptions.
42. What is the difference between checked exceptions and runtime
exceptions?
Checked exceptions are checked at compile-time and must be handled or declared, while
runtime exceptions (unchecked exceptions) are not required to be handled or declared.
46. What is the difference between the "equals()" method and the
"hashCode()" method?
The "equals()" method is used to compare the equality of objects based on their values, while
the "hashCode()" method is used to calculate a unique hash code value for an object, typically
used for efficient retrieval in hash-based data structures like HashMaps.
47. What is the difference between a shallow copy and a deep copy?
A shallow copy creates a new object that shares the same references as the original object,
while a deep copy creates a new object and recursively copies all the referenced objects as
well, resulting in separate copies.
61. What is the difference between a public class and a default (package-
private) class?
A public class in Java can be accessed from any other class, regardless of the package they
belong to. A default class, also known as a package-private class, is only accessible within
the same package and cannot be accessed from outside the package.
63. What is the purpose of the "break" and "continue" statements in Java?
The "break" statement in Java is used to terminate the execution of a loop or switch statement
and resume execution after the loop or switch block. The "continue" statement is used to skip
the current iteration of a loop and move to the next iteration.