What is the difference between final, finally and finalize

final” is the keyword to declare a constant AND prevents a class from producing subclasses. “finally” is a block of code that always executes when the try block is finished, unless System.exit() was called. “finalize()” is an method that is invoked before an object is discarded by the garbage collector. In Core Java, final, finally, and finalize … Read more

What is the wait/notify mechanism?

This deals with concurrent programming. The wait() and notify() methods are designed to provide a mechanism to allow a thread to be block until a specific condition is met. However, java.util.concurrent should be used instead of wait() and notify() to reduce complexity. The wait/notify mechanism in Java is a part of the synchronization features provided … Read more

When will you use Comparator and Comparable interfaces?

java.util.Comparator and java.lang.Comparable java.util.Comparator compares some other class’s instances, while java.lang.Comparable compares itself with another object. In Java, the Comparator and Comparable interfaces are both related to sorting objects, but they serve different purposes: Comparable Interface: The Comparable interface is used for natural ordering of objects. If a class implements the Comparable interface, it means … Read more

What is the difference between equals() and “==” ?

Equals is intended to check logical equality and == checks if both references point to same object. (Thanks Sandeep) a == b;// Compares references, not values. a.equals(b);// Compares values for equality. In Core Java, the difference between equals() and == lies in their functionality and what they compare: equals() method: equals() is a method defined … Read more

What is the difference between JDK and JRE?

Java Development Kit (JDK) is the most widely used Java Software Development Kit. Java Runtime Environment (JRE) is an implementation of the Java Virtual Machine which executes Java programs. In Java development, JDK (Java Development Kit) and JRE (Java Runtime Environment) are two essential components, and they serve distinct purposes: JDK (Java Development Kit): Definition: … Read more