Java MCQ Quiz Last Updated on May 17th, 2025This page is useful for those who are looking for : “Java MCQ quiz”, “Java programming questions”, “Java multiple-choice questions”, “Spring Boot Annotations MCQs”, “Java test for beginners”, “Java interview questions MCQ”, “Free Java quiz online”, “MCQ on Java”, “Online Java Quiz”, “Java Quiz Online”, “Java Online Quiz”, etc. Welcome to your one-stop destination for mastering Java through focused MCQs! Here you will find the link of most important Java questions grouped by topic (Core Java, Spring, Hibernate, Spring Boot, Microservices, Design Patterns, System Design etc.). Questions are presented in a variety of formats (single-select, multi-select, code-based, concept-based, and scenario-based). If you are brushing up on fundamentals like OOP and collections, diving into Spring’s dependency injection, exploring Hibernate’s ORM mappings, or architecting scalable microservices, each section offers targeted practice. We have also included design-pattern puzzles inspired by the Gang of Four and high-level system-design MCQs to test your architectural thinking. Scroll through clear explanations under every question to understand why an option is correct or incorrect, and see real-world examples in action. Ready to challenge yourself and elevate your Java expertise? Let’s get started! Answers & Explanations for each set of MCQs have been provided. Click on links below to go through the respective topic: Table of Contents Toggle MCQs on Spring, Hibernate, JPAMCQs on Core Java MCQs on Java Microservices MCQs on Java Design Patterns/Principles MCQs on System Design & Principles FAQs: Java MCQ Quiz MCQs on Spring, Hibernate, JPA Spring Boot Annotations MCQs & Practice Test MCQs on Spring & Hibernate MCQs on JPA & Hibernate MCQs on Hibernate MCQs on Spring Core MCQs on Spring Framework MCQs on Spring Framework - Part 2 MCQs on Spring Boot Annotations MCQs on Core Java MCQs on Java 8 Features MCQs on Java 17 Features MCQs on Java Stream API MCQs on Collections in Java (Intermediate to expert level) MCQs on Collections in Java (Beginner to intermediate level) MCQs on Exceptional Handling in Java MCQs on Object Oriented Programming (OOP) Fundamentals MCQs on Java Microservices MCQs on Java Microservices Java Microservices Practice Tests MCQs on Java Design Patterns/Principles MCQs on Java Design Patterns MCQs on SOLID Design Principles Udemy course: Java Design Patterns Practice Test & Interview Questions. Amazon eBook: Utilize the free access to kindle unlimited reading. For amazon.in users: Master Java Design Patterns with 500+ Solved MCQs & 1000+ Concepts Explanations For amazon.com users: Master Java Design Patterns with 500+ Solved MCQs & 1000+ Concepts Explanations MCQs on System Design & Principles MCQs on System Design FAQs: Java MCQ Quiz Q#1 (Multi-select, Concept-based) Which of these statements about Java packages are true? A) Every class belongs to a package. B) If no package is declared, classes go to the default package. C) Packages prevent name clashes. D) Packages force all classes in a file to share the same package. Explanation **A) Correct**: Java classes always reside in some package. – **B) Correct**: Absence of a `package` statement → default (unnamed) package. – **C) Correct**: Packages group classes and avoid naming conflicts. – **D) Incorrect**: You can have multiple classes in a file, but they share the same declared package. – **Answer: A, B, C** (1, 2 & 3). Q#2 (Single-select, Code-based) What does this program print? abstract class Vehicle { abstract void run(); } class Car extends Vehicle { void run() { System.out.println("Vroom"); } } public class Test { public static void main(String[] args) { Vehicle v = new Car(); v.run(); } } A) Compilation error B) No output C) Vroom D) Runtime exception Explanation **A) Incorrect**: No error—Car correctly implements `run()`. – **B) Incorrect**: `System.out.println` executes. – **C) Correct**: It prints `Vroom`. – **D) Incorrect**: No exception thrown. Q#3 (Single-select, Concept-based) Which method in Hibernate returns a proxy without hitting the database immediately? A) get() B) load() C) openSession() D) createQuery() Explanation – **A) Incorrect**: `get()` always hits DB. – **B) Correct**: `load()` returns a lazy proxy. – **C) Incorrect** – **D) Incorrect** Q#4 (Multi-select, Scenario-based) Which statements about Hibernate’s entity states are true? 1. Transient: not associated with a session. 2. Persistent: associated and tracked by the session. 3. Detached: no longer tracked after session close. 4. Immutable: cannot be updated. A) 1 & 2 B) 2 & 3 C) 1, 2 & 3 D) 3 & 4 Explanation – **1) Correct**: Newly created object, no session. – **2) Correct**: Managed by session. – **3) Correct**: After session close or clear. – **4) Incorrect**: Hibernate entities can be mutable. – **Answer: C** (1, 2 & 3). Q#5 (Multi-select, Scenario-based) Which practices help prevent cascading failures? A) Load balancing B) Circuit breaker C) Bulkhead isolation D) Monolithic deployment Explanation – **A) Correct**: Distributes traffic. – **B) Correct**: Stops calls on failure. – **C) Correct**: Isolates resources per service. – **D) Incorrect**: Increases blast radius. – **Answer: A, B & C**. Q#6 (Multi-select, Concept-based) Which statements about Java’s transient keyword in serialization are true? A) It prevents the field from being serialized via default mechanism. B) It makes the field invisible to reflection APIs. C) You can still serialize it manually in writeObject. D) It forces the field’s value to null after deserialization. Explanation – **A) Correct**: `transient` fields are skipped by default serialization. – **B) Incorrect**: Reflection can still access transient fields. – **C) Correct**: You can write them manually in `private void writeObject(ObjectOutputStream out)`. – **D) Incorrect**: After deserialization, non-initialized transient primitives are defaulted (`0`/`false`), object references become `null`, but that’s a side-effect, not a “force.” – **Answer: A & C**. Q#7 (Single-select, Code-based) Observe the below configuration: spring: application: name: user-service eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka/ This YAML config is for registering a service with: A) Consul B) Eureka C) Zookeeper D) Kubernetes Explanation – **A) Incorrect** – **B) Correct**: `eureka.client.serviceUrl`. – **C) Incorrect** – **D) Incorrect** Q#8 (Single-select, Concept-based) Which GoF pattern provides a simple interface to a complex subsystem? A) Adapter B) Decorator C) Facade D) Proxy Explanation – **A) Incorrect**: Adapts interface. – **B) Incorrect**: Adds behavior. – **C) Correct**: Facade simplifies subsystem. – **D) Incorrect**: Controls access. Q#9 (Multi-select, Concept-based) Which are characteristics of a good system design? A) Modularity B) Tight coupling C) High availability D) Single point of failure Explanation – **A) Correct**: Encapsulation of components. – **B) Incorrect**: Increases fragility. – **C) Correct**: System stays up under load. – **D) Incorrect**: Should be avoided. – **Answer: (A & C). Q#10. (Single-select, Scenario-based) You need to access a private field in a third-party class via reflection. Which sequence is required to modify its value at runtime? A) getDeclaredField() → setAccessible(true) → get() → set() B) getField() → setAccessible(true) → set() C) getDeclaredField() → get() → setAccessible(true) → set() D) getField() → set() Explanation – **A) Correct**: `getDeclaredField` finds private fields; you must call `setAccessible(true)` before any `get`/`set`. – **B) Incorrect**: `getField` only returns public fields. – **C) Incorrect**: You must set accessibility **before** calling `get` or `set`. – **D) Incorrect**: `getField` won’t locate private fields; accessibility must be changed first.