Question 1: What is Spring Boot, and how does it differ from the traditional Spring framework? Answer: Spring Boot is an extension of the Spring framework that simplifies the process of building and deploying production-ready applications. It provides a set of conventions, auto-configuration, and tools to streamline application development. The key difference between Spring Boot and the traditional Spring framework is that Spring Boot removes much of the manual configuration that is typically required in Spring applications, making it easier to set up and start a project. It also includes an embedded application server (like Tomcat, Jetty, or Undertow) for easy deployment. Example code if required: java // Traditional Spring Application Configuration @Configuration @EnableWebMvc public class MyApplicationConfig extends WebMvcConfigurerAdapter { // Configuration code here } // Equivalent Spring Boot Configuration @SpringBootApplication public class MyApplicatio...
To find the second-highest salary from a list of employees using Java 8 streams, you can follow these steps: Create a list of employees with their salaries. Use Java 8 streams to sort the employees by salary in descending order. Skip the first element (which is the employee with the highest salary). Get the first element of the remaining stream (which is the employee with the second-highest salary). Example code: java import java.util.ArrayList; import java.util.List; class Employee { private String name; private double salary; public Employee (String name, double salary) { this .name = name; this .salary = salary; } public double getSalary () { return salary; } } public class SecondHighestSalary { public static void main (String[] args) { List<Employee> employees = new ArrayList <>(); employees.add( new Employee ( "John" , 60000.0 )); employees.add( new Employe...