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

Core_Java_Interview_Questions_Answers

The document provides a comprehensive list of core Java interview questions and answers covering key concepts such as JDK, JRE, JVM, OOP principles, exception handling, and differences between various Java classes and data structures. It addresses topics like method overloading, synchronization, multithreading, and the Java Collections Framework. The content is structured to aid in preparing for Java-related interviews by summarizing essential Java concepts and terminologies.

Uploaded by

mayurhatwargpt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Core_Java_Interview_Questions_Answers

The document provides a comprehensive list of core Java interview questions and answers covering key concepts such as JDK, JRE, JVM, OOP principles, exception handling, and differences between various Java classes and data structures. It addresses topics like method overloading, synchronization, multithreading, and the Java Collections Framework. The content is structured to aid in preparing for Java-related interviews by summarizing essential Java concepts and terminologies.

Uploaded by

mayurhatwargpt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Core Java Interview Questions & Answers

1. What are the key differences between JDK, JRE, and JVM?
JDK is the full Java development kit including compiler, debugger, and tools. JRE provides the
runtime environment to run Java applications including JVM and libraries. JVM is the Java Virtual
Machine that runs bytecode and provides platform independence.

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


'==' checks reference equality (if two references point to the same object). '.equals()' checks logical
equality of object content and can be overridden.

3. What is the difference between an abstract class and an interface?


Abstract classes can have both abstract and concrete methods, can have constructors, but do not
support multiple inheritance. Interfaces define abstract methods (and default/static methods in Java
8+), cannot have constructors, and support multiple inheritance.

4. Explain method overloading and method overriding.


Method overloading allows multiple methods with the same name but different parameters in the
same class (compile-time polymorphism). Method overriding means a subclass provides its own
implementation of a method defined in the superclass (runtime polymorphism).

5. What are the four main OOP principles in Java?


1. Encapsulation - wrapping data and methods into a single unit.
2. Abstraction - hiding complex details and showing essential features.
3. Inheritance - acquiring properties and behaviors from another class.
4. Polymorphism - ability to perform actions in different forms (method overloading and overriding).

6. What are access modifiers in Java?


Access modifiers define visibility:
- private: accessible only within the class.
- default (no modifier): accessible within the same package.
- protected: accessible within the package and subclasses.
- public: accessible from anywhere.

7. What is the difference between ArrayList and LinkedList?


ArrayList is backed by a dynamic array and allows fast random access but slow insertion/deletion.
LinkedList uses a doubly linked list allowing fast insertions/deletions but slower random access.
8. What is a constructor in Java?
A constructor is a special method with the same name as the class used to initialize objects. It has
no return type and can be default or parameterized.

9. What is the difference between final, finally, and finalize()?


final is a keyword to declare constants or prevent inheritance/method overriding. finally is a block
that executes after try/catch regardless of exceptions. finalize() is a method called by the garbage
collector before object destruction.

10. What are 'this' and 'super' keywords?


'this' refers to the current object instance. 'super' refers to the immediate parent class object.

11. What is exception handling in Java?


Exception handling manages runtime errors using try, catch, finally, throw, and throws to prevent
crashes.

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


String is immutable. StringBuilder is mutable and not synchronized (faster). StringBuffer is mutable
and synchronized (thread-safe).

13. What is the Java Collections Framework?


A set of classes and interfaces that implement commonly used data structures such as List, Set,
Map, and Queue.

14. What is multithreading in Java?


Multithreading allows concurrent execution of two or more threads for better CPU utilization.

15. What is the difference between throw and throws?


throw is used to explicitly throw an exception. throws declares the exceptions a method can throw.

16. What is garbage collection in Java?


Automatic process of reclaiming memory by deleting unreachable objects to free heap space.

17. What is synchronization in Java?


A mechanism to control access to shared resources by multiple threads to avoid inconsistent data.

18. What are wrapper classes in Java?


Classes that encapsulate primitive data types as objects, e.g., Integer, Double, Character.

19. What is the difference between static and instance variables?


Static variables belong to the class and shared by all objects, instance variables belong to individual
objects.

20. What is the difference between checked and unchecked exceptions?


Checked exceptions are checked at compile time and must be handled or declared. Unchecked
exceptions occur at runtime and don't need explicit handling.

21. What is the use of the transient keyword?


Marks a variable so it is ignored during serialization.

22. What is a package in Java?


A namespace for organizing classes and interfaces into directories.

23. What is the difference between HashMap and Hashtable?


HashMap is unsynchronized and allows one null key and multiple null values, while Hashtable is
synchronized and doesn't allow null keys or values.

24. What is the purpose of the final keyword for a method?


To prevent the method from being overridden by subclasses.

25. Explain the concept of Java Beans.


Java Beans are reusable software components following conventions like having a no-arg
constructor, getter/setter methods, and being serializable.

26. What is the difference between shallow copy and deep copy?
Shallow copy copies object references, so both point to the same objects. Deep copy duplicates
objects and nested objects.

27. What is a classloader in Java?


A part of the JVM that loads classes into memory dynamically.

28. What are annotations in Java?


Metadata added to code elements to provide information to the compiler or runtime.

29. What is the difference between StringBuffer and StringBuilder?


StringBuffer is synchronized (thread-safe) but slower. StringBuilder is not synchronized but faster.

30. How does Java achieve platform independence?


By compiling code into bytecode which runs on the JVM available on any platform.
31. What is the difference between interface and abstract class?
Interfaces provide full abstraction (all abstract methods), support multiple inheritance. Abstract
classes can have both abstract and concrete methods, but do not support multiple inheritance.

32. What is the default value of an instance variable in Java?


Depends on the type, e.g., 0 for int, null for objects, false for boolean.

33. What is a thread-safe class?


A class that ensures safe access to its members when used by multiple threads concurrently.

34. What is method synchronization?


Marking methods with 'synchronized' to allow only one thread at a time to execute them.

35. What is an enum in Java?


A special data type to define collections of constants.

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


wait() releases the lock and waits to be notified, sleep() pauses thread without releasing the lock.

37. What is the purpose of the volatile keyword?


Ensures visibility of variable changes across threads.

38. What is a lambda expression?


A concise way to represent anonymous functions introduced in Java 8.

39. What is functional interface?


An interface with a single abstract method, used with lambda expressions.

40. What is the difference between List and Set?


List allows duplicates and maintains insertion order; Set does not allow duplicates and has no
guaranteed order.

You might also like