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
- Which OOP principle allows a class to have multiple forms?
A. Inheritance
B. Abstraction
C. Polymorphism
D. Encapsulation
✅ Answer: C - Which keyword is used to inherit a class in Java?
A. this
B. super
C. extends
D. implements
✅ Answer: C - 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
- Which access modifier allows access only within the same class?
A. public
B. private
C. protected
D. default
✅ Answer: B - Java is:
A. Compiled and interpreted
B. Interpreted only
C. Compiled only
D. Scripting language
✅ Answer: A - What is the size of an int in Java?
A. 2 bytes
B. 4 bytes
C. 8 bytes
D. Platform dependent
✅ Answer: B - Which collection guarantees unique elements and maintains insertion order?
A. HashMap
B. TreeSet
C. HashSet
D. LinkedHashSet
✅ Answer: D - 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
Master Java Microservices & Build Scalable Futures with Gyansetu
- What is the result of 10 % 3 in Java?
A. 1
B. 3
C. 0.3
D. Error
✅ Answer: A - Which interface does ArrayList implement?
A. Set
B. Queue
C. List
D. Map
✅ Answer: C - Which method is used to start a thread in Java?
A. execute()
B. start()
C. run()
D. launch()
✅ Answer: B - Which exception is a checked exception?
A. NullPointerException
B. IOException
C. ArithmeticException
D. IllegalArgumentException
✅ Answer: B - Which statement defines a generic class?
public class Box<T> { … }
A. True
B. False
✅ Answer: A
- What is the default value of a boolean variable?
A. true
B. false
C. null
D. 0
✅ Answer: B - 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
- 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 - Which HTTP method is idempotent?
A. POST
B. PUT
C. PATCH
D. DELETE
✅ Answer: B - What HTTP code means “Not Found”?
A. 200
B. 400
C. 404
D. 500
✅ Answer: C - What is the correct annotation for a GET request in Spring?
A. @GetMapping
B. @RequestMapping(method = GET)
C. Both
D. None
✅ Answer: C - What will this endpoint return?
@GetMapping(“/hello”)
public String sayHello() {
return “Hello!”;
}
A. JSON
B. Plain text
C. HTML
D. XML
✅ Answer: B
- Which annotation binds a URL parameter?
A. @PathParam
B. @RequestParam
C. @QueryParam
D. @Value
✅ Answer: B - What is the output type of @RestController methods by default?
A. JSON
B. XML
C. Plain text
D. HTML
✅ Answer: A - What does @RequestBody do?
A. Maps URL
B. Parses request headers
C. Binds HTTP request body to method parameter
D. Encodes parameters
✅ Answer: C - Which HTTP method is used to create a resource?
A. GET
B. POST
C. PUT
D. DELETE
✅ Answer: B
Unlock the Power of Java Microservices—Master Modern Development!
- What does @ResponseStatus(HttpStatus.CREATED) mean?
A. Return 200
B. Return 201
C. Return 204
D. Return 500
✅ Answer: B - Which annotation marks a class as a Spring REST controller?
A. @Controller
B. @RestController
C. @Service
D. @Component
✅ Answer: B - Which Spring module is used to create REST APIs?
A. Spring Security
B. Spring REST
C. Spring MVC
D. Spring Data
✅ Answer: C - Which tool is commonly used to test REST APIs?
A. Tomcat
B. Postman
C. Git
D. Maven
✅ Answer: B - Which annotation maps the entire controller to a base path?
A. @RestMapping
B. @Path
C. @RequestMapping
D. @Endpoint
✅ Answer: C - 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
- Which annotation marks a Spring Boot main class?
A. @SpringBoot
B. @SpringBootApplication
C. @EnableSpringBoot
D. @Configuration
✅ Answer: B - Which file is used for Spring Boot configuration?
A. app.conf
B. application.properties
C. spring.conf
D. boot.properties
✅ Answer: B - 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 - What is the default port of a Spring Boot app?
A. 3000
B. 5000
C. 8080
D. 80
✅ Answer: C - How do you start a Spring Boot application?
A. Spring.run()
B. Application.start()
C. SpringApplication.run()
D. Boot.start()
✅ Answer: C - 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 - Which annotation maps a Java class to a database table?
A. @Entity
B. @Table
C. @Database
D. @Model
✅ Answer: A - Which annotation is used to inject dependencies in Spring?
A. @Inject
B. @Autowired
C. @Bind
D. @Configure
✅ Answer: B - What does spring-boot-devtools provide?
A. Manual reload
B. Automatic restart and caching disablement
C. Logging only
D. Testing support
✅ Answer: B - 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 - Which annotation is used to define a REST API method in Spring Boot?
A. @RestCall
B. @RequestMapping
C. @ApiCall
D. @Service
✅ Answer: B - What does @ComponentScan do?
A. Scans HTML templates
B. Finds configuration classes
C. Detects Spring beans automatically
D. Enables AOP
✅ Answer: C - How do you disable a specific auto-configuration class?
A. @DisableConfig
B. @EnableAutoConfig(false)
C. @SpringBootApplication(exclude = …)
D. @NoConfig
✅ Answer: C - Which annotation is used to create a repository in Spring Boot?
A. @Repo
B. @Repository
C. @Store
D. @DataRepo
✅ Answer: B - What is a benefit of Spring Boot starters?
A. Bootstraps database
B. Configures YAML
C. Aggregates useful dependencies
D. Starts Tomcat
✅ Answer: C - Which server is embedded by default in Spring Boot?
A. Jetty
B. Tomcat
C. Netty
D. WebLogic
✅ Answer: B - 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 - Which annotation is used for exception handling in Spring controllers?
A. @HandleException
B. @ErrorHandler
C. @ControllerAdvice
D. @Catch
✅ Answer: C - What annotation is used to create RESTful web services?
A. @RestService
B. @RestApi
C. @RestController
D. @WebController
✅ Answer: C
Join the Leading Java Microservices Program Backed by Industry Experts.
- 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
- What is the primary advantage of Microservices?
A. Monolithic design
B. Shared memory
C. Scalability and modularity
D. Global configuration
✅ Answer: C - Which principle do microservices follow?
A. Centralized architecture
B. Shared database
C. Single-responsibility
D. Coupled modules
✅ Answer: C - What protocol is commonly used for communication between microservices?
A. TCP
B. UDP
C. HTTP/REST
D. SMTP
✅ Answer: C - Which tool is used for service discovery in Spring Cloud?
A. RabbitMQ
B. Eureka
C. Feign
D. Kafka
✅ Answer: B - Which annotation enables a Spring Boot application as Eureka client?
A. @EnableDiscovery
B. @EnableEurekaClient
C. @EnableMicroservices
D. @Client
✅ Answer: B - What is Feign used for?
A. Load balancing
B. Declarative REST clients
C. Authentication
D. Configuration
✅ Answer: B - What does Hystrix provide in microservices?
A. Load balancing
B. Security
C. Circuit breaker pattern
D. API gateway
✅ Answer: C - Which annotation is used for a Feign client interface?
A. @FeignClient
B. @FeignService
C. @RestClient
D. @FeignEndpoint
✅ Answer: A - Which annotation enables a Spring Cloud config client?
A. @EnableConfig
B. @ConfigClient
C. @EnableConfigClient
D. @RefreshScope
✅ Answer: D - Which pattern handles service-to-service security in Microservices?
A. API Gateway
B. JWT/OAuth2
C. Monolithic security
D. Load balancing
✅ Answer: B - 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 - Which tool helps with centralized configuration?
A. Postman
B. Spring Cloud Config
C. Swagger
D. JPA
✅ Answer: B - What is a drawback of tightly coupled microservices?
A. Faster development
B. Reusability
C. Deployment complexity
D. Code readability
✅ Answer: C - Which design pattern allows delayed service response with fallback?
A. Singleton
B. Builder
C. Circuit Breaker
D. Adapter
✅ Answer: C - Which tool provides distributed tracing?
A. Log4j
B. Kafka
C. Sleuth + Zipkin
D. RabbitMQ
✅ Answer: C - What is service registry?
A. Component to load logs
B. Central store of APIs
C. List of available services
D. Configuration file
✅ Answer: C - What does load balancing do in Microservices?
A. Encrypts messages
B. Shares database
C. Evenly distributes requests
D. Scales logs
✅ Answer: C - What annotation registers a service with Eureka?
A. @RegisterWithEureka
B. @ServiceRegistry
C. @EnableDiscoveryClient
D. @EurekaConnect
✅ Answer: C - Which tool is often used for message queuing in microservices?
A. Redis
B. Kafka
C. Swagger
D. Eureka
✅ Answer: B - 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
- Which Spring module provides authentication and authorization?
A. Spring Boot
B. Spring Data
C. Spring Security
D. Spring Auth
✅ Answer: C - What does OAuth2 provide in Microservices?
A. Logging
B. Authorization framework
C. Service discovery
D. Testing
✅ Answer: B - Which annotation enables method-level security in Spring?
A. @EnableMethodSecurity
B. @SecureMethod
C. @Authorize
D. @Secure
✅ Answer: A - Which annotation restricts a method to admin users only?
A. @Roles(“admin”)
B. @Secured(“ROLE_ADMIN”)
C. @Allowed(“ADMIN”)
D. @RestrictTo(“admin”)
✅ Answer: B - 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 - 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 - 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 - How is password encryption commonly handled in Spring Security?
A. BCryptPasswordEncoder
B. MD5Hash
C. SHA1Util
D. CryptoPassword
✅ Answer: A - 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 - 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
- Which library is commonly used for unit testing in Spring Boot?
A. JUnit
B. Mocha
C. Jasmine
D. Robot
✅ Answer: A - Which annotation is used for Spring Boot test classes?
A. @SpringTest
B. @BootTest
C. @SpringBootTest
D. @TestConfig
✅ Answer: C - What is Mockito used for?
A. Integration testing
B. Mocking dependencies
C. Database testing
D. Performance monitoring
✅ Answer: B - Which annotation is used to mock a bean in Spring tests?
A. @MockBean
B. @MockService
C. @InjectMock
D. @TestMock
✅ Answer: A - Which CI/CD tool is widely used in Java microservices projects?
A. Postman
B. Docker
C. Jenkins
D. Maven
✅ Answer: C - What does a Jenkins pipeline typically include?
A. Database design
B. Class structure
C. Build, Test, Deploy stages
D. HTML templates
✅ Answer: C - Which file is used to define a Jenkins pipeline?
A. jenkins.yaml
B. pipeline.xml
C. Jenkinsfile
D. build.gradle
✅ Answer: C - 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 - Which HTTP status code is verified in integration tests for a successful GET call?
A. 404
B. 500
C. 200
D. 401
✅ Answer: C - 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
- 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 - Which file defines a Docker image configuration?
A. Dockerfile
B. docker.xml
C. container.yaml
D. image.config
✅ Answer: A - Which command builds a Docker image?
A. docker build -t <image-name> .
B. docker start
C. docker deploy
D. docker make
✅ Answer: A - 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 - Which tool is used to orchestrate containers?
A. Maven
B. Kubernetes
C. Swagger
D. RabbitMQ
✅ Answer: B - What is application.yml used for?
A. HTML templating
B. API docs
C. Spring Boot config
D. CI/CD scripts
✅ Answer: C - Which platform is widely used for deploying microservices?
A. Heroku
B. WordPress
C. AWS ECS / EKS
D. MongoDB
✅ Answer: C - 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 - Which tool is used to monitor distributed microservices?
A. Prometheus + Grafana
B. Swagger
C. Maven
D. Jenkins
✅ Answer: A - 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
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.