Boost your Java basics and get interview-ready with these easy, must-know questions covering core Java features, OOP concepts, data structures, and exception handling.
Which of the following is NOT a main feature of Java?
Explanation: Java is known for being platform independent, not platform dependent. Object-Oriented, Multithreaded, and Robust are listed as main features in the context, making Platform Dependent incorrect.
What does the JDK (Java Development Kit) include that the JRE (Java Runtime Environment) does NOT?
Explanation: JDK includes all of JRE plus development tools and a compiler, which JRE does not provide. The JVM and class libraries are parts of JRE, and the bytecode interpreter is handled by the JVM.
In Java, what does the == operator do when used with objects?
Explanation: == checks if two references point to the same memory address. Comparing string content should use .equals(). Sorting and copying values are unrelated to ==.
Which OOP concept involves hiding implementation details and showing only functionality?
Explanation: Abstraction is about hiding implementation details and showing only what is necessary. Inheritance deals with property transfer, polymorphism with varied behavior, and encapsulation with data wrapping.
According to the context, when is LinkedList preferred over ArrayList?
Explanation: LinkedList is best for frequent insertions and deletions. ArrayList is better for fast searching by index. LinkedList does not specifically use hash functions, and it is not preferred for slow operations.
In Java, what is the use of the 'throws' keyword?
Explanation: 'throws' is used in method declarations to state what exceptions might be thrown. 'throw' triggers an exception inside a method. Closing resources and ignoring exceptions are not related to 'throws'.
Which term refers to a method called before object destruction by the garbage collector?
Explanation: 'finalize()' is called by the garbage collector before destroying an object. 'final' is a keyword for constants or inheritance control, 'finally' is a block in exception handling, and 'finish' is not a Java term.
What is a key advantage of using multithreading in Java applications?
Explanation: Multithreading allows multiple tasks to run concurrently, maximizing CPU utilization. It does not directly reduce code size, prevent all exceptions, or enforce single-tasking—in fact, it enables multitasking.
What is true about an abstract class compared to an interface (Java 8+)?
Explanation: Abstract classes can have both abstract and concrete methods, as well as constructors and variables. Interfaces (Java 8+) can't have constructors but can have static/default methods.
Which exception must be handled at compile-time in Java?
Explanation: Checked exceptions, like IOException, are checked at compile-time and must be handled. Unchecked exceptions (including RuntimeException and NullPointerException) occur at runtime and don't require explicit handling.