Java_SpringBoot_Interview_Prep
Java_SpringBoot_Interview_Prep
Yes, you can add or remove elements from a final List like 'final List<Integer> list = new ArrayList<>()'. The
'final' keyword only means that the reference variable 'list' cannot be reassigned to point to a different list.
However, the contents of the list can still be modified. So, methods like add(), remove(), and clear() are
allowed.
@Qualifier is used in Spring to resolve the ambiguity when multiple beans of the same type are available.
When you annotate a field with @Autowired, Spring looks for a matching bean to inject. If there are multiple
beans, you can specify which one to use using @Qualifier. For example:
@Autowired
@Qualifier("beanName")
Spring Boot simplifies database connection through auto-configuration. You only need to add the appropriate
starter dependency (e.g., spring-boot-starter-data-jpa for JPA or spring-boot-starter-jdbc for JDBC), and
spring.datasource.url=jdbc:mysql://localhost:3306/mydb
spring.datasource.username=root
Java & Spring Boot Interview Prep
spring.datasource.password=pass
Spring Boot automatically configures a DataSource bean and manages connections. You can also use
Singleton is a design pattern that restricts the instantiation of a class to a single object. It ensures that only
one instance exists and provides a global point of access to it. This is useful for stateless services, config
Example:
private Singleton() {}
return instance;
A Functional Interface is an interface that has exactly one abstract method. It enables the use of lambda
expressions and method references in Java. Examples include Runnable, Callable, Comparator, etc. You can
define your own using the @FunctionalInterface annotation. It promotes cleaner code and functional
programming features.
Java & Spring Boot Interview Prep
Example:
@FunctionalInterface
interface Calculator {
Encapsulation is one of the core concepts of object-oriented programming. It refers to the bundling of data
(variables) and methods that operate on the data into a single unit called a class. It restricts direct access to
some of an object's components, which is a way of preventing accidental interference and misuse. This is
achieved using access modifiers, typically making fields private and providing public getters/setters.
Example:
class Employee {
return name;
this.name = name;