Java Fresher Interview Questions and Answers

Practice every question in this topic using expandable answers and interview tips. Answer aloud first, then open the explanation.

Back to the complete interview hub

Read question Answer aloud Review
Q1. What is Java? [Easy]

Answer: Java is a high-level, object-oriented programming language developed by Sun Microsystems. It is widely used for web, mobile, desktop, and enterprise applications.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q2. What are the main features of Java? [Easy]

Answer: Main features of Java include: Object-oriented, Platform independent, Secure, Robust, Portable, Multithreaded, Simple, and High performance with JIT compiler.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q3. Why is Java platform-independent? [Easy]

Answer: Java source code is compiled into bytecode by javac. This bytecode runs on the Java Virtual Machine (JVM), enabling the 'Write Once, Run Anywhere' principle across different operating systems.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q4. What is the difference between JDK, JRE, and JVM? [Easy]

Answer: JDK (Java Development Kit) is used to develop Java apps and contains JRE plus tools. JRE (Java Runtime Environment) provides libraries and the JVM to run apps. JVM (Java Virtual Machine) executes the bytecode into machine code.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q5. What is JVM? [Easy]

Answer: JVM stands for Java Virtual Machine. It is an abstract computing machine that enables a computer to run Java bytecode and converts it into native machine code.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q6. What is the difference between Java and C++? [Medium]

Answer: Java is platform-independent through JVM while C++ is platform-dependent native code. Java has automatic garbage collection, does not support pointers directly, and avoids multiple inheritance through classes.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q7. What are primitive and non-primitive data types in Java? [Easy]

Answer: Primitive types include byte, short, int, long, float, double, char, and boolean. Non-primitive types include Classes, Objects, Arrays, Interfaces, and Strings.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q8. What is a variable and its types in Java? [Easy]

Answer: A variable is a named memory location used to store values. Java variable types include Local variables, Instance variables, and Static variables.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q9. What is type casting in Java? [Easy]

Answer: Type casting is converting one data type into another. Widening casting converts a smaller type to a larger type automatically, while narrowing casting requires explicit conversion.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q10. What is a class in Java? [Easy]

Answer: A class is a user-defined blueprint or template for creating objects. It defines fields, attributes, and methods that objects instantiated from it will possess.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q11. What is an object in Java? [Easy]

Answer: An object is an instance of a class that has state and behavior. It represents a real-world entity and accesses class variables and methods.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q12. What is a constructor in Java? [Easy]

Answer: A constructor is a special method used to initialize objects. It shares the exact same name as its class and has no explicit return type.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q13. What is the difference between a constructor and a method? [Medium]

Answer: A constructor initializes objects, has the class name, no return type, and is called automatically on instantiation. A method performs actions, can have any name, return type, and is invoked explicitly.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q14. What is inheritance in Java? [Easy]

Answer: Inheritance is an OOP mechanism where one class inherits fields and methods from a parent class using the extends keyword, promoting code reusability.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q15. What are the types of inheritance in Java? [Medium]

Answer: Java supports Single, Multilevel, and Hierarchical inheritance. Multiple inheritance with classes is not supported to avoid ambiguity, but can be achieved via interfaces.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q16. What is polymorphism in Java? [Medium]

Answer: Polymorphism means 'many forms'. It includes Compile-time polymorphism (Method Overloading) and Runtime polymorphism (Method Overriding).

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q17. What is method overloading? [Easy]

Answer: Method overloading occurs when multiple methods in the same class share the same name but have different parameter lists (type, count, or sequence).

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q18. What is method overriding? [Medium]

Answer: Method overriding happens when a subclass provides a specific implementation for a method already defined in its superclass using the @Override annotation.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q19. What is encapsulation in Java? [Medium]

Answer: Encapsulation is wrapping data (variables) and code (methods) into a single unit (class) while restricting direct access to variables using private modifiers and getter/setter methods.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q20. What is abstraction in Java? [Medium]

Answer: Abstraction is hiding internal complexity and showing only essential functionality to the user, achieved through abstract classes and interfaces.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q21. What is the difference between an abstract class and an interface? [Hard]

Answer: Abstract classes can have instance variables, concrete methods, and constructors. Interfaces define contracts with constant fields, abstract methods, and default/static methods.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q22. What is the 'this' keyword in Java? [Easy]

Answer: The 'this' keyword is a reference variable that refers to the current class object instance, used to resolve naming conflicts between local variables and instance fields.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q23. What is the 'super' keyword in Java? [Easy]

Answer: The 'super' keyword is a reference variable used to access parent class members, methods, or invoke parent class constructors.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q24. What is the 'static' keyword in Java? [Medium]

Answer: The 'static' keyword indicates that a variable or method belongs to the class itself rather than individual instances, shared across all objects.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q25. What is the 'final' keyword in Java? [Medium]

Answer: The 'final' keyword prevents modification: a final variable cannot be reassigned, a final method cannot be overridden, and a final class cannot be extended.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q26. What is exception handling in Java? [Medium]

Answer: Exception handling manages runtime errors to maintain normal application flow using try, catch, finally, throw, and throws keywords.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q27. What is the difference between checked and unchecked exceptions? [Medium]

Answer: Checked exceptions (e.g. IOException, SQLException) are verified at compile time. Unchecked exceptions (e.g. NullPointerException, ArithmeticException) occur at runtime.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q28. What is the difference between == and .equals() in Java? [Easy]

Answer: The == operator compares memory reference equality (whether objects share the same memory location), while .equals() compares the logical contents/value of objects.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q29. What are ArrayList, LinkedList, HashSet, and HashMap? [Medium]

Answer: ArrayList is a dynamic resizable array. LinkedList uses doubly-linked nodes. HashSet stores unique unordered elements. HashMap stores unique key-value pairs.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Q30. What is multithreading in Java? [Hard]

Answer: Multithreading is executing two or more threads concurrently within a program to maximize CPU utilization and improve application responsiveness.

Interview tip: Define it clearly, give a small example, and mention one practical use or limitation.

Study checklist

  1. Explain the answer without reading.
  2. Write one small example.
  3. Compare framework or database version differences in official documentation.

Java Fresher Interview Questions and Answers

Practice one question at a time. Read the question, answer aloud, then compare your explanation with the answer.

← Back to the complete interview hub

Study method: define the concept, give a small example, and mention one practical use or limitation.

Q1. What is Java?

Easy

Answer: Java is a high-level, object-oriented programming language developed by Sun Microsystems. It is widely used for web, mobile, desktop, and enterprise applications.

Interview tip: Use a short example and connect the answer to real project work.

Q2. What are the main features of Java?

Easy

Answer: Main features of Java include: Object-oriented, Platform independent, Secure, Robust, Portable, Multithreaded, Simple, and High performance with JIT compiler.

Interview tip: Use a short example and connect the answer to real project work.

Q3. Why is Java platform-independent?

Easy

Answer: Java source code is compiled into bytecode by javac. This bytecode runs on the Java Virtual Machine (JVM), enabling the 'Write Once, Run Anywhere' principle across different operating systems.

Interview tip: Use a short example and connect the answer to real project work.

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

Easy

Answer: JDK (Java Development Kit) is used to develop Java apps and contains JRE plus tools. JRE (Java Runtime Environment) provides libraries and the JVM to run apps. JVM (Java Virtual Machine) executes the bytecode into machine code.

Interview tip: Use a short example and connect the answer to real project work.

Q5. What is JVM?

Easy

Answer: JVM stands for Java Virtual Machine. It is an abstract computing machine that enables a computer to run Java bytecode and converts it into native machine code.

Interview tip: Use a short example and connect the answer to real project work.

Q6. What is the difference between Java and C++?

Medium

Answer: Java is platform-independent through JVM while C++ is platform-dependent native code. Java has automatic garbage collection, does not support pointers directly, and avoids multiple inheritance through classes.

Interview tip: Use a short example and connect the answer to real project work.

Q7. What are primitive and non-primitive data types in Java?

Easy

Answer: Primitive types include byte, short, int, long, float, double, char, and boolean. Non-primitive types include Classes, Objects, Arrays, Interfaces, and Strings.

Interview tip: Use a short example and connect the answer to real project work.

Q8. What is a variable and its types in Java?

Easy

Answer: A variable is a named memory location used to store values. Java variable types include Local variables, Instance variables, and Static variables.

Interview tip: Use a short example and connect the answer to real project work.

Q9. What is type casting in Java?

Easy

Answer: Type casting is converting one data type into another. Widening casting converts a smaller type to a larger type automatically, while narrowing casting requires explicit conversion.

Interview tip: Use a short example and connect the answer to real project work.

Q10. What is a class in Java?

Easy

Answer: A class is a user-defined blueprint or template for creating objects. It defines fields, attributes, and methods that objects instantiated from it will possess.

Interview tip: Use a short example and connect the answer to real project work.

Q11. What is an object in Java?

Easy

Answer: An object is an instance of a class that has state and behavior. It represents a real-world entity and accesses class variables and methods.

Interview tip: Use a short example and connect the answer to real project work.

Q12. What is a constructor in Java?

Easy

Answer: A constructor is a special method used to initialize objects. It shares the exact same name as its class and has no explicit return type.

Interview tip: Use a short example and connect the answer to real project work.

Q13. What is the difference between a constructor and a method?

Medium

Answer: A constructor initializes objects, has the class name, no return type, and is called automatically on instantiation. A method performs actions, can have any name, return type, and is invoked explicitly.

Interview tip: Use a short example and connect the answer to real project work.

Q14. What is inheritance in Java?

Easy

Answer: Inheritance is an OOP mechanism where one class inherits fields and methods from a parent class using the extends keyword, promoting code reusability.

Interview tip: Use a short example and connect the answer to real project work.

Q15. What are the types of inheritance in Java?

Medium

Answer: Java supports Single, Multilevel, and Hierarchical inheritance. Multiple inheritance with classes is not supported to avoid ambiguity, but can be achieved via interfaces.

Interview tip: Use a short example and connect the answer to real project work.

Q16. What is polymorphism in Java?

Medium

Answer: Polymorphism means 'many forms'. It includes Compile-time polymorphism (Method Overloading) and Runtime polymorphism (Method Overriding).

Interview tip: Use a short example and connect the answer to real project work.

Q17. What is method overloading?

Easy

Answer: Method overloading occurs when multiple methods in the same class share the same name but have different parameter lists (type, count, or sequence).

Interview tip: Use a short example and connect the answer to real project work.

Q18. What is method overriding?

Medium

Answer: Method overriding happens when a subclass provides a specific implementation for a method already defined in its superclass using the @Override annotation.

Interview tip: Use a short example and connect the answer to real project work.

Q19. What is encapsulation in Java?

Medium

Answer: Encapsulation is wrapping data (variables) and code (methods) into a single unit (class) while restricting direct access to variables using private modifiers and getter/setter methods.

Interview tip: Use a short example and connect the answer to real project work.

Q20. What is abstraction in Java?

Medium

Answer: Abstraction is hiding internal complexity and showing only essential functionality to the user, achieved through abstract classes and interfaces.

Interview tip: Use a short example and connect the answer to real project work.

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

Hard

Answer: Abstract classes can have instance variables, concrete methods, and constructors. Interfaces define contracts with constant fields, abstract methods, and default/static methods.

Interview tip: Use a short example and connect the answer to real project work.

Q22. What is the 'this' keyword in Java?

Easy

Answer: The 'this' keyword is a reference variable that refers to the current class object instance, used to resolve naming conflicts between local variables and instance fields.

Interview tip: Use a short example and connect the answer to real project work.

Q23. What is the 'super' keyword in Java?

Easy

Answer: The 'super' keyword is a reference variable used to access parent class members, methods, or invoke parent class constructors.

Interview tip: Use a short example and connect the answer to real project work.

Q24. What is the 'static' keyword in Java?

Medium

Answer: The 'static' keyword indicates that a variable or method belongs to the class itself rather than individual instances, shared across all objects.

Interview tip: Use a short example and connect the answer to real project work.

Q25. What is the 'final' keyword in Java?

Medium

Answer: The 'final' keyword prevents modification: a final variable cannot be reassigned, a final method cannot be overridden, and a final class cannot be extended.

Interview tip: Use a short example and connect the answer to real project work.

Q26. What is exception handling in Java?

Medium

Answer: Exception handling manages runtime errors to maintain normal application flow using try, catch, finally, throw, and throws keywords.

Interview tip: Use a short example and connect the answer to real project work.

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

Medium

Answer: Checked exceptions (e.g. IOException, SQLException) are verified at compile time. Unchecked exceptions (e.g. NullPointerException, ArithmeticException) occur at runtime.

Interview tip: Use a short example and connect the answer to real project work.

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

Easy

Answer: The == operator compares memory reference equality (whether objects share the same memory location), while .equals() compares the logical contents/value of objects.

Interview tip: Use a short example and connect the answer to real project work.

Q29. What are ArrayList, LinkedList, HashSet, and HashMap?

Medium

Answer: ArrayList is a dynamic resizable array. LinkedList uses doubly-linked nodes. HashSet stores unique unordered elements. HashMap stores unique key-value pairs.

Interview tip: Use a short example and connect the answer to real project work.

Q30. What is multithreading in Java?

Hard

Answer: Multithreading is executing two or more threads concurrently within a program to maximize CPU utilization and improve application responsiveness.

Interview tip: Use a short example and connect the answer to real project work.

Quick revision checklist

  1. Explain the answer without reading.
  2. Write one small example.
  3. Review platform or version differences in official documentation.

logoblog

No comments:

Post a Comment

Please do not enter any spam link in the comment box.