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

Java Interview Questions (1)

Uploaded by

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

Java Interview Questions (1)

Uploaded by

Nithin Kudupudi
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

1. What is the difference between JDK, JRE, and JVM?

- JDK (Java Development Kit) includes JRE + development tools.


- JRE (Java Runtime Environment) includes JVM + libraries.
- JVM (Java Virtual Machine) executes Java bytecode.

2. What is the difference between == and equals() in Java?


- '==' checks reference equality.
- equals() checks content equality.

3. What are wrapper classes in Java?


- Wrapper classes convert primitives to objects (e.g., int to Integer).

4. What is the use of the 'final' keyword?


- Final variable: constant value.
- Final method: cannot be overridden.
- Final class: cannot be inherited.

5. What is the difference between String, StringBuilder, and StringBuffer?


- String: immutable.
- StringBuilder: mutable, not thread-safe.
- StringBuffer: mutable, thread-safe.

6. What are checked and unchecked exceptions?


- Checked: Checked at compile-time (e.g., IOException).
- Unchecked: Checked at runtime (e.g., NullPointerException).

7. What is polymorphism in Java?


- Compile-time (method overloading).
- Runtime (method overriding).

8. How does HashMap work internally?


- Uses an array of linked lists (buckets).
- Uses hashCode() to find the bucket.
- Uses equals() to check key equality.

9. What is a constructor in Java?


- A block of code invoked when an object is created.
- Types: Default, Parameterized.

10. What is the difference between ArrayList and LinkedList?


- ArrayList: dynamic array, faster for accessing elements.
- LinkedList: doubly linked list, faster for insertion/deletion.

11. What is the purpose of the 'transient' keyword?


- Prevents serialization of variables.

12. What is the use of the 'volatile' keyword?


- Ensures visibility and ordering of variables in multithreading.

13. What is method overloading and method overriding?


- Overloading: Same method name, different parameters (compile-time).
- Overriding: Same method name and parameters, different class (runtime).

14. What is a Singleton class?


- A class with a single instance using private constructor and static method.

15. What is the 'super' keyword used for?


- Access parent class members and constructors.
16. What is the difference between abstract class and interface?
- Abstract class: partial abstraction, can have concrete methods.
- Interface: full abstraction, no concrete methods (before Java 8).

17. What is a marker interface?


- An interface with no methods (e.g., Serializable).

18. What is garbage collection in Java?


- Automatic memory management by JVM to deallocate unused objects.

19. How to create a thread in Java?


- Implement Runnable interface or extend Thread class.

20. What are functional interfaces in Java?


- An interface with a single abstract method (e.g., Runnable, Callable).

You might also like