0% found this document useful (0 votes)
3 views

Java_Interview_Questions

The document provides an overview of key Java concepts including interfaces, inheritance, exception handling, wrapper classes, thread deadlock, synchronization, and the differences between various classes and methods. It explains the purpose and functionality of each concept, such as the use of multiple catch statements, the significance of the CLASSPATH, and the distinctions between StringBuffer and StringBuilder. Additionally, it covers auto-boxing, auto-unboxing, and the differences between sleep() and wait() methods.

Uploaded by

VENU DINO
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Java_Interview_Questions

The document provides an overview of key Java concepts including interfaces, inheritance, exception handling, wrapper classes, thread deadlock, synchronization, and the differences between various classes and methods. It explains the purpose and functionality of each concept, such as the use of multiple catch statements, the significance of the CLASSPATH, and the distinctions between StringBuffer and StringBuilder. Additionally, it covers auto-boxing, auto-unboxing, and the differences between sleep() and wait() methods.

Uploaded by

VENU DINO
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1. What is an interface?

An interface in Java is a reference type that contains only abstract methods (until Java 8) and

constants. It is used to achieve abstraction and multiple inheritance.

2. What is the advantage of inheritance?

Inheritance promotes code reusability. A subclass can inherit the properties and methods of a

superclass, reducing code duplication.

3. Explain about multiple catch statements in Exception handling.

Multiple catch blocks allow handling different types of exceptions separately. They are evaluated top

to bottom, and only the first matching catch block runs.

4. Why do you need wrapper classes?

Wrapper classes convert primitive types into objects, allowing them to be used in collections and

with generics.

5. Define thread deadlock in Java with an example.

Deadlock occurs when two threads hold resources and wait for each other indefinitely.

Example:

synchronized (obj1) {

synchronized (obj2) {

// code

// Another thread

synchronized (obj2) {

synchronized (obj1) {
// deadlock risk

6. How many types of inheritance are there?

Java supports:

- Single

- Multilevel

- Hierarchical

(Java doesn't support multiple inheritance with classes due to ambiguity).

7. Why the methods of interface are public and abstract by default?

Interface methods must be implemented by classes, so they are public (accessible) and abstract (no

body) by default.

8. Explain the keyword throw and throws.

- throw: Used to explicitly throw an exception.

- throws: Declares the exceptions a method might throw.

9. Explain the concept of CLASSPATH in Java.

CLASSPATH tells the Java compiler and JVM where to find class files and libraries.

10. Define Synchronization?

Synchronization ensures that only one thread accesses a critical section (like a method or block) at

a time, preventing data inconsistency.

11. Describe the keyword super and its application in inheritance.


super refers to the immediate parent class. It's used to:

- Call the parent constructor

- Access parent methods/variables

12. Can you implement one interface from another?

Yes. An interface can extend another interface using the extends keyword.

13. What is the difference between StringBuffer and StringBuilder classes?

- StringBuffer: Thread-safe (synchronized), slower

- StringBuilder: Not thread-safe, faster

14. Define Auto-boxing and Auto-unboxing.

- Auto-boxing: Converting primitive to wrapper (e.g., int -> Integer)

- Auto-unboxing: Wrapper to primitive (e.g., Integer -> int)

15. What is the difference between sleep() and wait() methods?

- sleep(): Pauses the thread for a given time. Does not release the lock.

- wait(): Pauses the thread until notify() or notifyAll() is called. It releases the lock.

Easy trick to remember: sleep = timer pause, wait = coordination pause

You might also like