Java (36) 

Welcome to our Core Java Interview Questions and Answers page!

Whether you’re a beginner or an experienced Java developer, this page will provide you with a comprehensive list of frequently asked questions and their detailed answers. Prepare yourself for your upcoming interviews and ace them with confidence. Happy reading and best of luck!

Top 20 Basic Core Java interview questions and answers

1. What is Java?
Java is a high-level programming language that is widely used for developing applications. It follows the principles of object-oriented programming and runs on the Java Virtual Machine (JVM).

2. What are the features of Java?
Some key features of Java include platform independence, object-oriented programming, automatic memory management, robustness, multithreading, and security.

3. What is the difference between JDK, JRE, and JVM?
JDK (Java Development Kit) is the software development kit used for developing Java applications. JRE (Java Runtime Environment) is the runtime environment that is required for running Java applications. JVM (Java Virtual Machine) is the virtual machine that executes Java byte code.

4. What is the difference between a class and an object?
A class is a blueprint or template from which objects are created. It defines the properties and behaviors that an object of that class will have. An object, on the other hand, is an instance of a class.

5. What is the difference between the stack and the heap?
The stack is used for storing local variables and method call information, while the heap is used for storing objects. Memory allocation in the stack is done in a last-in-first-out manner, while in the heap, it is managed by the garbage collector.

6. What is the difference between == and equals() method?
The == operator is used for comparing the reference or memory address of two objects, while the equals() method is used for comparing the content or values of two objects.

7. What is a constructor?
A constructor is a special method that is used for initializing objects of a class. It is called automatically when an object of the class is created and has the same name as the class.

8. What are the access modifiers in Java?
Java provides four access modifiers: public, private, protected, and default (no modifier). These modifiers control the visibility and accessibility of classes, methods, and variables.

9. What is the difference between final, finally, and finalize in Java?
The final keyword is used to declare a variable, method, or class as constant or unchangeable. The finally block is used to execute a set of statements regardless of whether an exception is thrown or not. The finalize() method is called by the garbage collector before reclaiming the memory occupied by an object.

10. What is an interface?
An interface is a collection of abstract methods that are used for achieving abstraction and defining contracts. It is implemented by classes and provides a way to achieve multiple inheritances in Java.

11. What is the difference between abstract class and interface?
An abstract class can have abstract and non-abstract methods, while an interface can only have abstract methods. Multiple inheritance is possible with interfaces but not with abstract classes.

12. What are the different types of inner classes in Java?
Java supports four types of inner classes: member inner class, static nested class, local inner class, and anonymous inner class.

13. What is method overloading?
Method overloading is the concept of defining multiple methods in a class with the same name but different parameters. It allows a class to have methods with similar functionality but with different input arguments.

14. What is method overriding?
Method overriding is the concept of defining a method in a subclass that is already defined in its superclass. The overridden method in the subclass has the same name, return type, and parameters as the method in the superclass.

15. What is the super keyword?
The super keyword is used to refer to the immediate parent class object. It is used to call the constructor, methods, and variables of the superclass.

16. What are the different types of loops in Java?
Java supports three types of loops: for loop, while loop, and do-while loop. These loops are used for executing a set of statements repeatedly as long as a condition is true.

17. What is the difference between checked and unchecked exceptions?
Checked exceptions are checked at compile-time and are required to be handled using try-catch blocks or by declaring them in the method signature. Unchecked exceptions, on the other hand, are not checked at compile-time and do not require mandatory exception handling.

18. What is a thread?
A thread is a lightweight unit of execution that allows multiple tasks to be performed concurrently. Java supports multithreading, which means multiple threads can execute concurrently within a program.

19. What is the difference between an applet and a servlet?
An applet is a small program that runs inside a web browser and requires a Java plugin to be installed. A servlet, on the other hand, is a server-side component that handles client requests and generates dynamic web content.

20. What is garbage collection in Java?
Garbage collection is the process of automatically reclaiming the memory occupied by objects that are no longer in use. Java uses a garbage collector to identify and free up memory occupied by unused objects.

Top 20 Advanced Core Java interview questions and answers

1. What is the difference between final, finally, and finalize in Java?
Final is a keyword used to restrict the user from changing the value of a variable, making a method unmodifiable, or inheriting a class. Finally is a block used in exception handling to execute important code regardless of whether an exception is caught or not. Finalize is a method that the garbage collector calls before an object is destroyed.

2. What is the difference between ClassNotFoundException and NoClassDefFoundError in Java?
ClassNotFoundException occurs when a class is being loaded using Class.forName() or ClassLoader.loadClass() methods, and the requested class is not found. NoClassDefFoundError occurs when a class is present during compilation but not found during runtime.

3. What is polymorphism in Java?
Polymorphism refers to the ability of an object to take on many forms. It allows methods to be written that can interact with objects of different classes, as long as they belong to the same inheritance hierarchy.

4. What is the difference between a static method and an instance method in Java?
A static method belongs to the class itself and can be called without creating an instance of the class. An instance method belongs to an instance of the class and can only be called on an object of that class.

5. What is the difference between Array and ArrayList in Java?
An Array is a fixed-size data structure that stores elements of the same type, while ArrayList is a dynamic data structure that can grow or shrink in size and can store elements of different types.

6. What are the access modifiers in Java?
Java provides four access modifiers: public, private, protected, and default. Public allows unrestricted access, private restricts access to the same class, protected allows access within the same package or subclass, and default restricts access to the same package.

7. What is the purpose of the ‘transient’ keyword in Java?
The ‘transient’ keyword is used to indicate that a variable should not be serialized when an object of the class is converted to a byte stream by the ObjectOutputStream.

8. What is the difference between an abstract class and an interface in Java?
An abstract class can have both abstract and concrete methods, while an interface can only have abstract methods. A class can implement multiple interfaces, but it can only extend one abstract class.

9. What is the purpose of the ‘volatile’ keyword in Java?
The ‘volatile’ keyword is used to indicate that a variable’s value may be modified by multiple threads. It ensures that any thread accessing the variable retrieves the latest value instead of using a cached value.

10. What is method overloading in Java?
Method overloading allows multiple methods with the same name but different parameters to coexist in a class. The appropriate method is called based on the arguments passed during invocation.

11. What is the purpose of the ‘this’ keyword in Java?
The ‘this’ keyword refers to the current instance of the class. It is used to access instance variables or methods, differentiate between local and instance variables, and invoke the current class’s constructor.

12. What is the difference between checked and unchecked exceptions in Java?
Checked exceptions are checked at compile-time and must be declared in the method signature or handled using a try-catch block. Unchecked exceptions are not checked at compile-time and can be handled if desired.

13. Can we override the ‘final’ method in Java?
No, a ‘final’ method cannot be overridden in Java. It is marked as final to prevent any modification by subclasses.

14. What is the purpose of the ‘clone()’ method in Java?
The ‘clone()’ method is used to create a copy of an object. It creates a new instance of the class with the same state as the original object.

15. What is the difference between ‘==’ and ‘equals()’ in Java?
‘==’ is used to compare the reference equality of two objects, while ‘equals()’ is used to compare the content equality of the objects, based on how the ‘equals()’ method is implemented.

16. What is the purpose of the ‘super’ keyword in Java?
The ‘super’ keyword is used to refer to the superclass or parent class of a subclass. It allows access to superclass members, calling of superclass constructors, and resolving any overridden method conflicts.

17. What is the difference between StringBuilder and StringBuffer in Java?
StringBuilder is not thread-safe and provides better performance, while StringBuffer is thread-safe but may have slightly lower performance due to synchronization.

18. What is the purpose of the ‘instanceof’ operator in Java?
The ‘instanceof’ operator is used to check if an object is an instance of a specific class, a subclass, or a class that implements a particular interface. It returns true or false based on the result.

19. What is a lambda expression in Java?
A lambda expression is a compact way of representing an anonymous function. It allows the implementation of functional interfaces using a concise syntax.

20. What are the different garbage collection algorithms in Java?
Java uses different garbage collection algorithms like Mark and Sweep, Copying, Mark and Compact, and Generational Garbage Collection to reclaim the memory of objects that are no longer referenced.

Java (36) 

Interview Questions and answers

Filter:AllUnanswered
What is the difference between ArrayList and LinkedList in Java?
suresh answered 3 months ago • 
30 views1 answers0 votes
What is the difference between Array and ArrayList in Java?
suresh answered 4 months ago • 
43 views1 answers0 votes
What are the differences between a class and an object in Java?
suresh answered 6 months ago • 
51 views1 answers0 votes