Reference Page: JAVA|SCALA|SWIFT|RUST|GO-Language|R-Language

Java Links : Learn     Interview Questions     Software IDE Java Jobs : Indeed.com     ZipRecruiter.com     Monster.com

Java Interview Questions - Page 3

< Previous Page              Next Page >
Question: What is the purpose of the 'transient' keyword in Java?
Answer: The 'transient' keyword in Java is used to indicate that a variable should not be serialized during object serialization. It is typically used for variables that hold temporary or sensitive data that should not be saved.

The transient keyword gives you some control over the serialization process and allows you to exclude some object properties from this process.

Question: What is the purpose of the 'volatile' keyword in Java?
Answer: The 'volatile' keyword in Java is used to indicate that a variable's value may be changed by multiple threads simultaneously.

The keyword 'volatile' ensures that any thread reading the variable always gets the latest updated value from memory.

Question: Can you explain the difference between Checked and Unchecked exceptions in Java?
Answer: Please find below the main difference:

Checked exceptions are checked at compile-time and must be either caught or declared in the method signature using throws.
Unchecked exceptions, also known as runtime exceptions, are not checked at compile-time and can occur at runtime without being caught or declared.

Generally, one would use checked exceptions for exceptions which should be handled by the calling code, while unchecked exceptions are for results of programming errors and should be fixed by correcting the code.

Question: What is the difference between 'instanceof' operator and 'getClass()' method in Java?
Answer: You can find the difference below:

• The instanceof operator checks whether an object is an instance of a particular class or interface.
• The getClass() method returns the runtime class of an object as a Class object.

Question: What is method chaining in Java?
Answer: In Java Method chaining, also known as cascading, is a design pattern where multiple methods are called in sequence on the same object. It is achieved by having each method return the object itself (this) after performing its operation.

Method chaining has following advantages:

• Chaining enables developers to keep their code organised by making it easy to read and understand multiple related instructions at once.
• Method Chaining has the potential to increase performance to a good extent, as chained methods are typically faster to execute than separate equivalent instructions.

Question: What is the 'finalize()' method used for?
Answer: The 'finalize()' method is called by the garbage collector before reclaiming the memory occupied by an object that is no longer reachable.

The 'finalize()' method can be overridden to perform cleanup operations or resource deallocation before the object is garbage collected.


< Previous Page Next Page >