Answer:
3. Spring Boot is an opinionated framework built on Spring that auto-configures the application, provides embedded servers (Tomcat/Jetty), starter dependencies, actuator metrics and production-ready defaults. Benefits: minimal XML, fast setup, standalone executable JAR, easy microservices.
4. RESTful API with Spring Boot: annotate a class with @RestController, map URLs with @RequestMapping/@GetMapping/@PostMapping, bind data with @PathVariable/@RequestBody, return objects that Jackson converts to JSON.
@SpringBootApplication public class App { public static void main(String[] a) { SpringApplication.run(App.class, a); } }
@RestController class Hello {
@GetMapping("/hello") public String hi(@RequestParam(defaultValue="world") String n) { return "Hello " + n; }
}
GET /hello?n=Java -> Hello Java
Spring Boot and REST in practice. Spring Boot is an opinionated layer over Spring that removes most setup work. It provides starter dependencies that bundle compatible libraries, auto configuration that creates beans when certain classes are present, an embedded servlet container so an application runs as a standalone executable jar, and production features through Actuator. A RESTful web service exposes resources addressed by URLs and uses HTTP verbs with their standard meanings: GET reads, POST creates, PUT replaces, PATCH modifies and DELETE removes. Requests are stateless, and responses usually carry JSON with an appropriate status code. In Spring Boot, DispatcherServlet receives the request, consults handler mappings and invokes a method on a class annotated RestController. Path variables come from the URL with at sign PathVariable, query parameters with at sign RequestParam and request bodies with at sign RequestBody. The returned Java object is converted to JSON by an HttpMessageConverter backed by Jackson. A simple hello endpoint can accept a name parameter and return a greeting; a student endpoint can return a Student object for a given id. A good answer explains Boot benefits, maps HTTP verbs to operations, traces the request path through DispatcherServlet and converter, writes a small controller and states what the client receives. Mentioning that controllers should stay thin and delegate to a service layer, and that status codes such as 200, 201, 404 and 400 communicate the result, shows practical API design. Noting that REST is stateless and resource oriented ties the implementation back to the architectural style.
Result: Spring Boot removes boilerplate configuration and makes REST endpoints quick to build and run.
For n≥1 elements the operation uses O(1) extra space.
Tip from Examiner: State the principle or language rule, write the code or structure with key terms defined, explain the execution or design decision and support the answer with a labelled diagram or comparison where useful.