Test your knowledge of fundamental Java interview questions designed for freshers. This quiz covers core concepts such as OOP, exception handling, Java features, and basic syntax to help you prepare for entry-level Java programming roles.
Which statement best describes Java as a programming language?
Explanation: Java is a high-level language that lets developers write code that can run on various platforms due to its platform independence. Java is not limited to web pages and is often used in mobile, desktop, and server environments, while option B is inaccurate. Option C incorrectly defines Java as a markup language, which it is not. Option D is also incorrect because Java has automatic memory management through garbage collection.
Which of the following is NOT a main feature of Java?
Explanation: Java provides automatic memory management via garbage collection, reducing the need for developers to manually manage memory. Platform independence and object-oriented principles are core features of Java, making options A and B correct features. Option D is a correct feature as Java manages memory automatically, so only option C is not a main feature.
Which of these is NOT one of the four main object-oriented programming concepts in Java?
Explanation: The four main OOP concepts in Java are encapsulation, abstraction, inheritance, and polymorphism. Iteration refers to repeating actions in programming, but it is not an OOP principle, making C the correct answer. Encapsulation, abstraction, and inheritance are all foundational to object-oriented programming.
What is the purpose of the Java Virtual Machine (JVM) in Java development?
Explanation: The JVM allows Java programs (in the form of bytecode) to run on any platform, ensuring platform independence. The source code compilation is handled by the Java compiler, not the JVM, so option A is incorrect. Option C is a function of development tools, and option D is not accurate because memory management is handled dynamically and not permanent.
Which of the following is an example of a primitive data type in Java?
Explanation: int is a primitive data type representing an integer in Java. String, ArrayList, and Scanner are reference data types (objects or classes), not primitives. Primitives in Java also include types like char, boolean, and double, but not custom or class-based types.
What is the main purpose of a constructor in a Java class?
Explanation: Constructors are special methods that automatically run when a new object is created, setting up its initial state. Static variables are declared separately within a class, so option A is incorrect. Destroying objects is handled by the garbage collector, not by constructors, making option C wrong. Option D refers to the import keyword, not constructors.
Which scenario best represents method overloading in Java?
Explanation: Method overloading occurs when multiple methods have the same name within a class but differ in parameters. Option B actually describes method overriding, not overloading. Accessing methods from other packages (option C) and changing access modifiers (option D) do not represent overloading.
In Java, which keywords are commonly used for exception handling?
Explanation: Java uses the try, catch, and finally keywords for handling exceptions, allowing programs to manage errors gracefully. Options B and C list unrelated keywords, and option D does not include any standard Java exception handling terms. Only option A directly relates to Java's exception handling structure.
What is the primary distinction between the '==' operator and the equals() method when comparing objects in Java?
Explanation: The '==' operator checks if two references point to the exact same object, while equals() checks if the objects' values are logically equivalent. Option B is incorrect because both are used for various objects, not just strings or numbers. Option C and D describe unrelated or incorrect functionalities.
What is the primary use of Java Collections?
Explanation: Java Collections are frameworks designed to help programmers handle, store, and manage groups of objects with ease. Mathematical calculations (option A) and user interface design (option C) are not the main focus of Collections. Option D is incorrect because Collections do not create new primitive data types.