Enhance your understanding of Java Microservices with these 30 MCQs covering key concepts in microservice architecture, including building microservices with Spring Boot, creating RESTful web services, and implementing service discovery and API gateways.
MCQs on Java Microservices
Introduction to Microservices
What is a microservice in software architecture?
a) A small function in Java
b) A single-service architecture
c) A loosely coupled, independently deployable service
d) A user interface component
Which of the following is an advantage of microservices over monolithic architecture?
a) High dependency on a central database
b) Easier scalability and independent deployment
c) Higher complexity in development
d) Harder to manage and maintain
Which protocol is most commonly used for communication between microservices?
a) FTP
b) SMTP
c) HTTP/HTTPS
d) SNMP
Microservices are often organized around:
a) Technical functions
b) Business capabilities
c) Security layers
d) File storage
What is a major challenge of using microservices in Java?
a) Easier deployment
b) Simplified code maintenance
c) Managing inter-service communication
d) Enhanced user interface
Building Microservices with Spring Boot
Which Java framework is commonly used to build microservices?
a) Struts
b) Spring Boot
c) Hibernate
d) JSP
In Spring Boot, which annotation is used to mark a class as a Spring Boot application?
a) @SpringService
b) @SpringApplication
c) @SpringBootApplication
d) @SpringComponent
Which of the following annotations is used in Spring Boot to create a RESTful web service?
a) @Controller
b) @RestController
c) @Service
d) @Repository
How can you define a port number for a Spring Boot application?
a) In the pom.xml file
b) Using @PortNumber annotation
c) By setting server.port in application.properties
d) By setting spring.port in config.xml
Which Spring Boot feature is used to bundle the dependencies and the application into a single executable JAR file?
a) spring-boot-loader
b) spring-boot-maven-plugin
c) spring-boot-jar
d) spring-boot-cli
RESTful Web Services in Java
What does REST stand for in RESTful web services?
a) Representational State Transfer
b) Real-Time Service Transfer
c) Relational Service Technology
d) Remote State Technology
Which HTTP method is used to create a new resource in RESTful web services?
a) GET
b) POST
c) DELETE
d) PUT
Which HTTP method is commonly used to update an existing resource?
a) GET
b) POST
c) PUT
d) DELETE
What is the purpose of @RequestMapping in Spring Boot?
a) To start the application
b) To handle HTTP requests
c) To secure the application
d) To manage database connections
In RESTful services, what format is most commonly used for data exchange?
a) XML
b) JSON
c) CSV
d) HTML
In a RESTful API, what does the HTTP status code 404 indicate?
a) Successful request
b) Unauthorized request
c) Resource not found
d) Server error
Which of the following is used to define the endpoint of a RESTful service in Spring Boot?
a) @RestEndpoint
b) @GetMapping, @PostMapping, etc.
c) @WebService
d) @RestService
In Spring Boot, what annotation is used to inject dependencies automatically?
a) @Autowired
b) @Inject
c) @Resource
d) @Controller
What is the purpose of @PathVariable in Spring Boot?
a) To retrieve values from URL path segments
b) To define HTTP headers
c) To create a new HTTP session
d) To define request parameters
Which annotation is used to retrieve data from the URL query parameters in Spring Boot?
a) @PathVariable
b) @RequestParam
c) @GetParam
d) @Param
Service Discovery and API Gateway
What is the purpose of service discovery in microservices?
a) To enhance data security
b) To allow services to find and communicate with each other
c) To simplify user interface design
d) To connect the database with the application
Which tool is commonly used for service discovery in Spring Boot applications?
a) Spring Tool Suite
b) Eureka Server
c) Hibernate
d) JPA Repository
What role does an API Gateway play in microservices architecture?
a) It handles inter-service authentication
b) It directs requests to the appropriate microservices
c) It serves as a data storage solution
d) It enhances code readability
Which of the following is NOT a responsibility of an API Gateway?
a) Load balancing
b) Service discovery
c) Logging and monitoring
d) Managing business logic
Which of the following patterns can be implemented using an API Gateway?
a) Circuit breaker pattern
b) Singleton pattern
c) Observer pattern
d) Command pattern
How does Spring Cloud Eureka facilitate service discovery?
a) By setting up database connections
b) By registering and locating services dynamically
c) By creating RESTful services
d) By managing client requests
Which framework in Java helps implement API Gateway functionality?
a) Spring Cloud Gateway
b) JPA Repository
c) Hibernate
d) Spring Data JPA
In Spring Boot, which annotation registers a microservice with Eureka Server?
a) @EnableEurekaServer
b) @EnableDiscoveryClient
c) @EnableRestController
d) @EnableMicroservice
What is a primary benefit of using API Gateway in microservices architecture?
a) Easier user management
b) Centralized routing and request handling
c) Improved database performance
d) Faster data storage
Which protocol is commonly used by Eureka Server for service registration and discovery?
a) HTTP
b) RMI
c) UDP
d) SMTP
Answer Table
Qno
Answer
1
c) A loosely coupled, independently deployable service
2
b) Easier scalability and independent deployment
3
c) HTTP/HTTPS
4
b) Business capabilities
5
c) Managing inter-service communication
6
b) Spring Boot
7
c) @SpringBootApplication
8
b) @RestController
9
c) By setting server.port in application.properties
10
b) spring-boot-maven-plugin
11
a) Representational State Transfer
12
b) POST
13
c) PUT
14
b) To handle HTTP requests
15
b) JSON
16
c) Resource not found
17
b) @GetMapping, @PostMapping, etc.
18
a) @Autowired
19
a) To retrieve values from URL path segments
20
b) @RequestParam
21
b) To allow services to find and communicate with each other
22
b) Eureka Server
23
b) It directs requests to the appropriate microservices
24
d) Managing business logic
25
a) Circuit breaker pattern
26
b) By registering and locating services dynamically