100 Core and Advanced Java Objective Type Quiz & MCQs with Answers for Interview Preparation | Gyansetu

Gyansetu Team Web Development/Programming
Microservice Course

Practice these MCQs to strengthen your Java and Microservices knowledge and prepare confidently for job interviews or certification exams.
Whether you’re aiming to become a backend specialist, a full-stack developer, or simply sharpen your skills in Java, Spring Boot, REST APIs, and microservices architecture — you’re in the right place.
100+ Java Microservices MCQs covering everything from OOP concepts, Spring Boot, RESTful services, service discovery, security, testing, and deployment — complete with answers to help you test and solidify your understanding, no guesswork involved.

✅ Section 1: Core Java Fundamentals – 15 MCQs

  1. Which OOP principle allows a class to have multiple forms?
    A. Inheritance
    B. Abstraction
    C. Polymorphism
    D. Encapsulation
    Answer: C
  2. Which keyword is used to inherit a class in Java?
    A. this
    B. super
    C. extends
    D. implements
    Answer: C
  3. What is the output of this code?

int a = 5, b = 2;

System.out.println(a / b);

A. 2.5
B. 2
C. 3
D. Compilation error
Answer: B

  1. Which access modifier allows access only within the same class?
    A. public
    B. private
    C. protected
    D. default
    Answer: B
  2. Java is:
    A. Compiled and interpreted
    B. Interpreted only
    C. Compiled only
    D. Scripting language
    Answer: A
  3. What is the size of an int in Java?
    A. 2 bytes
    B. 4 bytes
    C. 8 bytes
    D. Platform dependent
    Answer: B
  4. Which collection guarantees unique elements and maintains insertion order?
    A. HashMap
    B. TreeSet
    C. HashSet
    D. LinkedHashSet
    Answer: D
  5. What does static keyword indicate in Java?
    A. Non-inheritable
    B. Belongs to class rather than instance
    C. Constant value
    D. Temporary object
    Answer: B
Java Spring Course in Gurgaon

Master Java Microservices & Build Scalable Futures with Gyansetu

  1. What is the result of 10 % 3 in Java?
    A. 1
    B. 3
    C. 0.3
    D. Error
    Answer: A
  2. Which interface does ArrayList implement?
    A. Set
    B. Queue
    C. List
    D. Map
    Answer: C
  3. Which method is used to start a thread in Java?
    A. execute()
    B. start()
    C. run()
    D. launch()
    Answer: B
  4. Which exception is a checked exception?
    A. NullPointerException
    B. IOException
    C. ArithmeticException
    D. IllegalArgumentException
    Answer: B
  5. Which statement defines a generic class?

public class Box<T> { … }

A. True
B. False
Answer: A

  1. What is the default value of a boolean variable?
    A. true
    B. false
    C. null
    D. 0
    Answer: B
  2. Which method is called during garbage collection?
    A. destroy()
    B. delete()
    C. finalize()
    D. gc()
    Answer: C

✅ Section 2: Java REST APIs & HTTP – 15 MCQs

  1. What is a RESTful Web Service?
    A. Uses only SOAP
    B. Stateless client-server architecture
    C. JavaScript frontend service
    D. Java EE monolith
    Answer: B
  2. Which HTTP method is idempotent?
    A. POST
    B. PUT
    C. PATCH
    D. DELETE
    Answer: B
  3. What HTTP code means “Not Found”?
    A. 200
    B. 400
    C. 404
    D. 500
    Answer: C
  4. What is the correct annotation for a GET request in Spring?
    A. @GetMapping
    B. @RequestMapping(method = GET)
    C. Both
    D. None
    Answer: C
  5. What will this endpoint return?

@GetMapping(“/hello”)

public String sayHello() {

  return “Hello!”;

}

A. JSON
B. Plain text
C. HTML
D. XML
Answer: B

  1. Which annotation binds a URL parameter?
    A. @PathParam
    B. @RequestParam
    C. @QueryParam
    D. @Value
    Answer: B
  2. What is the output type of @RestController methods by default?
    A. JSON
    B. XML
    C. Plain text
    D. HTML
    Answer: A
  3. What does @RequestBody do?
    A. Maps URL
    B. Parses request headers
    C. Binds HTTP request body to method parameter
    D. Encodes parameters
    Answer: C
  4. Which HTTP method is used to create a resource?
    A. GET
    B. POST
    C. PUT
    D. DELETE
    Answer: B
Java Spring Course in Gurgaon

Unlock the Power of Java Microservices—Master Modern Development!

  1. What does @ResponseStatus(HttpStatus.CREATED) mean?
    A. Return 200
    B. Return 201
    C. Return 204
    D. Return 500
    Answer: B
  2. Which annotation marks a class as a Spring REST controller?
    A. @Controller
    B. @RestController
    C. @Service
    D. @Component
    Answer: B
  3. Which Spring module is used to create REST APIs?
    A. Spring Security
    B. Spring REST
    C. Spring MVC
    D. Spring Data
    Answer: C
  4. Which tool is commonly used to test REST APIs?
    A. Tomcat
    B. Postman
    C. Git
    D. Maven
    Answer: B
  5. Which annotation maps the entire controller to a base path?
    A. @RestMapping
    B. @Path
    C. @RequestMapping
    D. @Endpoint
    Answer: C
  6. What is the purpose of Swagger/OpenAPI in Microservices?
    A. Logging
    B. Auto-generating frontend
    C. API documentation and testing
    D. Caching
    Answer: C

✅ Section 3: Spring Boot Essentials – 20 MCQs

  1. Which annotation marks a Spring Boot main class?
    A. @SpringBoot
    B. @SpringBootApplication
    C. @EnableSpringBoot
    D. @Configuration
    Answer: B
  2. Which file is used for Spring Boot configuration?
    A. app.conf
    B. application.properties
    C. spring.conf
    D. boot.properties
    Answer: B
  3. What is the purpose of @EnableAutoConfiguration?
    A. Disables configuration
    B. Enables component scanning
    C. Auto-configures beans based on classpath
    D. Enables REST API
    Answer: C
  4. What is the default port of a Spring Boot app?
    A. 3000
    B. 5000
    C. 8080
    D. 80
    Answer: C
  5. How do you start a Spring Boot application?
    A. Spring.run()
    B. Application.start()
    C. SpringApplication.run()
    D. Boot.start()
    Answer: C
  6. Which dependency is needed for a REST API in Spring Boot?
    A. spring-boot-starter-web
    B. spring-boot-starter-rest
    C. spring-rest
    D. spring-boot-starter-core
    Answer: A
  7. Which annotation maps a Java class to a database table?
    A. @Entity
    B. @Table
    C. @Database
    D. @Model
    Answer: A
  8. Which annotation is used to inject dependencies in Spring?
    A. @Inject
    B. @Autowired
    C. @Bind
    D. @Configure
    Answer: B
  9. What does spring-boot-devtools provide?
    A. Manual reload
    B. Automatic restart and caching disablement
    C. Logging only
    D. Testing support
    Answer: B
  10. Which command runs Spring Boot from command line?
    A. java run App.java
    B. java -jar app.jar
    C. springboot app.java
    D. boot -run
    Answer: B
  11. Which annotation is used to define a REST API method in Spring Boot?
    A. @RestCall
    B. @RequestMapping
    C. @ApiCall
    D. @Service
    Answer: B
  12. What does @ComponentScan do?
    A. Scans HTML templates
    B. Finds configuration classes
    C. Detects Spring beans automatically
    D. Enables AOP
    Answer: C
  13. How do you disable a specific auto-configuration class?
    A. @DisableConfig
    B. @EnableAutoConfig(false)
    C. @SpringBootApplication(exclude = …)
    D. @NoConfig
    Answer: C
  14. Which annotation is used to create a repository in Spring Boot?
    A. @Repo
    B. @Repository
    C. @Store
    D. @DataRepo
    Answer: B
  15. What is a benefit of Spring Boot starters?
    A. Bootstraps database
    B. Configures YAML
    C. Aggregates useful dependencies
    D. Starts Tomcat
    Answer: C
  16. Which server is embedded by default in Spring Boot?
    A. Jetty
    B. Tomcat
    C. Netty
    D. WebLogic
    Answer: B
  17. How is a custom error page defined in Spring Boot?
    A. customError.jsp
    B. error-page.html
    C. resources/templates/error.html
    D. main/error.html
    Answer: C
  18. Which annotation is used for exception handling in Spring controllers?
    A. @HandleException
    B. @ErrorHandler
    C. @ControllerAdvice
    D. @Catch
    Answer: C
  19. What annotation is used to create RESTful web services?
    A. @RestService
    B. @RestApi
    C. @RestController
    D. @WebController
    Answer: C
.NET MVC course

Join the Leading Java Microservices Program Backed by Industry Experts.

  1. Which tool is used to build and manage Spring Boot projects?
    A. Postman
    B. Maven/Gradle
    C. Docker
    D. IntelliJ
    Answer: B

✅ Section 4: Microservices Architecture – 20 MCQs

  1. What is the primary advantage of Microservices?
    A. Monolithic design
    B. Shared memory
    C. Scalability and modularity
    D. Global configuration
    Answer: C
  2. Which principle do microservices follow?
    A. Centralized architecture
    B. Shared database
    C. Single-responsibility
    D. Coupled modules
    Answer: C
  3. What protocol is commonly used for communication between microservices?
    A. TCP
    B. UDP
    C. HTTP/REST
    D. SMTP
    Answer: C
  4. Which tool is used for service discovery in Spring Cloud?
    A. RabbitMQ
    B. Eureka
    C. Feign
    D. Kafka
    Answer: B
  5. Which annotation enables a Spring Boot application as Eureka client?
    A. @EnableDiscovery
    B. @EnableEurekaClient
    C. @EnableMicroservices
    D. @Client
    Answer: B
  6. What is Feign used for?
    A. Load balancing
    B. Declarative REST clients
    C. Authentication
    D. Configuration
    Answer: B
  7. What does Hystrix provide in microservices?
    A. Load balancing
    B. Security
    C. Circuit breaker pattern
    D. API gateway
    Answer: C
  8. Which annotation is used for a Feign client interface?
    A. @FeignClient
    B. @FeignService
    C. @RestClient
    D. @FeignEndpoint
    Answer: A
  9. Which annotation enables a Spring Cloud config client?
    A. @EnableConfig
    B. @ConfigClient
    C. @EnableConfigClient
    D. @RefreshScope
    Answer: D
  10. Which pattern handles service-to-service security in Microservices?
    A. API Gateway
    B. JWT/OAuth2
    C. Monolithic security
    D. Load balancing
    Answer: B
  11. What is the function of an API Gateway?
    A. Manages static files
    B. Database sync
    C. Entry point to multiple microservices
    D. Compiles services
    Answer: C
  12. Which tool helps with centralized configuration?
    A. Postman
    B. Spring Cloud Config
    C. Swagger
    D. JPA
    Answer: B
  13. What is a drawback of tightly coupled microservices?
    A. Faster development
    B. Reusability
    C. Deployment complexity
    D. Code readability
    Answer: C
  14. Which design pattern allows delayed service response with fallback?
    A. Singleton
    B. Builder
    C. Circuit Breaker
    D. Adapter
    Answer: C
  15. Which tool provides distributed tracing?
    A. Log4j
    B. Kafka
    C. Sleuth + Zipkin
    D. RabbitMQ
    Answer: C
  16. What is service registry?
    A. Component to load logs
    B. Central store of APIs
    C. List of available services
    D. Configuration file
    Answer: C
  17. What does load balancing do in Microservices?
    A. Encrypts messages
    B. Shares database
    C. Evenly distributes requests
    D. Scales logs
    Answer: C
  18. What annotation registers a service with Eureka?
    A. @RegisterWithEureka
    B. @ServiceRegistry
    C. @EnableDiscoveryClient
    D. @EurekaConnect
    Answer: C
  19. Which tool is often used for message queuing in microservices?
    A. Redis
    B. Kafka
    C. Swagger
    D. Eureka
    Answer: B
  20. Which annotation allows automatic refresh of Spring Cloud configs?
    A. @EnableAutoConfig
    B. @RefreshScope
    C. @ReloadConfig
    D. @EnableConfigClient
    Answer: B

✅ Section 5: Security & Authorization – 10 MCQs

  1. Which Spring module provides authentication and authorization?
    A. Spring Boot
    B. Spring Data
    C. Spring Security
    D. Spring Auth
    Answer: C
  2. What does OAuth2 provide in Microservices?
    A. Logging
    B. Authorization framework
    C. Service discovery
    D. Testing
    Answer: B
  3. Which annotation enables method-level security in Spring?
    A. @EnableMethodSecurity
    B. @SecureMethod
    C. @Authorize
    D. @Secure
    Answer: A
  4. Which annotation restricts a method to admin users only?
    A. @Roles(“admin”)
    B. @Secured(“ROLE_ADMIN”)
    C. @Allowed(“ADMIN”)
    D. @RestrictTo(“admin”)
    Answer: B
  5. What is the purpose of JWT in Microservices?
    A. Session-based authentication
    B. Token-based stateless authentication
    C. Load balancing
    D. Distributed tracing
    Answer: B
  6. What does the .antMatchers() method do in Spring Security?
    A. Defines CORS rules
    B. Matches URL paths for access control
    C. Filters REST controllers
    D. Scans components
    Answer: B
  7. What is the purpose of the SecurityFilterChain in Spring Security 6?
    A. Apply AOP
    B. Define bean injection
    C. Configure HTTP security rules
    D. Control data validation
    Answer: C
  8. How is password encryption commonly handled in Spring Security?
    A. BCryptPasswordEncoder
    B. MD5Hash
    C. SHA1Util
    D. CryptoPassword
    Answer: A
  9. Which header is used to pass JWT tokens in HTTP requests?
    A. Authorization
    B. JWT-Token
    C. Access-Token
    D. X-Auth-Token
    Answer: A
  10. What does @PreAuthorize(“hasRole(‘ADMIN’)”) do?
    A. Blocks access to admin
    B. Allows method execution only if user has role ADMIN
    C. Executes regardless of user role
    D. Encrypts method output
    Answer: B

✅ Section 6: Testing & CI/CD – 10 MCQs

  1. Which library is commonly used for unit testing in Spring Boot?
    A. JUnit
    B. Mocha
    C. Jasmine
    D. Robot
    Answer: A
  2. Which annotation is used for Spring Boot test classes?
    A. @SpringTest
    B. @BootTest
    C. @SpringBootTest
    D. @TestConfig
    Answer: C
  3. What is Mockito used for?
    A. Integration testing
    B. Mocking dependencies
    C. Database testing
    D. Performance monitoring
    Answer: B
  4. Which annotation is used to mock a bean in Spring tests?
    A. @MockBean
    B. @MockService
    C. @InjectMock
    D. @TestMock
    Answer: A
  5. Which CI/CD tool is widely used in Java microservices projects?
    A. Postman
    B. Docker
    C. Jenkins
    D. Maven
    Answer: C
  6. What does a Jenkins pipeline typically include?
    A. Database design
    B. Class structure
    C. Build, Test, Deploy stages
    D. HTML templates
    Answer: C
  7. Which file is used to define a Jenkins pipeline?
    A. jenkins.yaml
    B. pipeline.xml
    C. Jenkinsfile
    D. build.gradle
    Answer: C
  8. What is the purpose of unit tests in microservices?
    A. UI validation
    B. Test individual components in isolation
    C. Check load balancers
    D. API security
    Answer: B
  9. Which HTTP status code is verified in integration tests for a successful GET call?
    A. 404
    B. 500
    C. 200
    D. 401
    Answer: C
  10. Which assertion library is used in Java unit tests?
    A. AssertJ
    B. Mocha
    C. Pytest
    D. Jest
    Answer: A

Section 7: Deployment, Docker, and Real-World Use – 10 MCQs

  1. What is the purpose of Docker in Microservices?
    A. Database server
    B. Logging system
    C. Containerize applications for consistent deployment
    D. Load balancer
    Answer: C
  2. Which file defines a Docker image configuration?
    A. Dockerfile
    B. docker.xml
    C. container.yaml
    D. image.config
    Answer: A
  3. Which command builds a Docker image?
    A. docker build -t <image-name> .
    B. docker start
    C. docker deploy
    D. docker make
    Answer: A
  4. What does EXPOSE 8080 do in Dockerfile?
    A. Block port 8080
    B. Install Tomcat
    C. Listen on port 8080
    D. Bind to host
    Answer: C
  5. Which tool is used to orchestrate containers?
    A. Maven
    B. Kubernetes
    C. Swagger
    D. RabbitMQ
    Answer: B
  6. What is application.yml used for?
    A. HTML templating
    B. API docs
    C. Spring Boot config
    D. CI/CD scripts
    Answer: C
  7. Which platform is widely used for deploying microservices?
    A. Heroku
    B. WordPress
    C. AWS ECS / EKS
    D. MongoDB
    Answer: C
  8. What is the purpose of health check endpoints in microservices?
    A. Load HTML
    B. Monitor service status
    C. Test database
    D. Generate logs
    Answer: B
  9. Which tool is used to monitor distributed microservices?
    A. Prometheus + Grafana
    B. Swagger
    C. Maven
    D. Jenkins
    Answer: A
  10. What’s the biggest challenge in microservices architecture?
    A. CSS styling
    B. UI testing
    C. Service coordination and communication
    D. Writing unit tests
    Answer: C
gyansetu-logo

Accelerate Your Career with Industry-Ready Java Microservices Skills.

Mastering these Java Microservices MCQs is a valuable step toward building a strong foundation in object-oriented programming, RESTful APIs, Spring Boot, and scalable backend architectures.
If you’re ready to elevate your career with hands-on projects and expert-led instruction, join our Java Microservices course in Gurgaon at Gyansetu and become industry-ready for high-demand backend and full-stack development roles.

Gyansetu Team

Leave a Comment

Your email address will not be published. Required fields are marked *

Categories
Drop us a Query
+91-9999201478

Available 24x7 for your queries

Please enable JavaScript in your browser to complete this form.