0% found this document useful (0 votes)
4 views3 pages

Java_SpringBoot_Interview_Prep

The document provides key concepts and interview preparation tips for Java and Spring Boot, including the use of final lists, the @Qualifier annotation for bean injection, and creating database connections in Spring Boot. It also explains the Singleton Design Pattern, the definition and use of Functional Interfaces, and the concept of Encapsulation in Java. Each topic is accompanied by examples to illustrate the concepts clearly.

Uploaded by

Himanshu Rane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Java_SpringBoot_Interview_Prep

The document provides key concepts and interview preparation tips for Java and Spring Boot, including the use of final lists, the @Qualifier annotation for bean injection, and creating database connections in Spring Boot. It also explains the Singleton Design Pattern, the definition and use of Functional Interfaces, and the concept of Encapsulation in Java. Each topic is accompanied by examples to illustrate the concepts clearly.

Uploaded by

Himanshu Rane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Java & Spring Boot Interview Prep

Can we add values to a final List?

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.

What is @Qualifier in Spring?

@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")

private Service myService;

This tells Spring exactly which bean to inject.

How to create a database connection in Spring Boot?

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

provide properties in 'application.properties':

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

JdbcTemplate or JPA repositories for interacting with the database.

What is Singleton Design Pattern?

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

classes, logging, etc.

Example:

public class Singleton {

private static Singleton instance = new Singleton();

private Singleton() {}

public static Singleton getInstance() {

return instance;

Use of Functional Interface in Java

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 {

int operate(int a, int b);

What is Encapsulation in Java?

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 {

private String name;

public String getName() {

return name;

public void setName(String name) {

this.name = name;

You might also like