Infosys Interview Preparation
Infosys Interview Preparation
6
spring boot-3.2.5
java-22
----------------------------------------------------------------------
DATA JPA
----------------------------------------------------------------------
->What is ORM ?
ORM stands for Object Relational Mapping
It is a technique used to creating "Bridge" between Object Oriented
Programmes and reational database
It is mainly for database operations
->Explaining mapping rule in JPA
We define Entity(POJO) class for one table
We define one variable for one column
Then one object converted to one row(even reverse)
->Difference between JPA and Hibernate
JPA is Specification given by sun micro systems,now it is part of oracle
Hibernate is a JPA implementation
->Difference between PagingAndSortingRepository and JpaRepository ?
JpaRepository only work with relational databases
Ex:- mysql,oracle
PagingAndSortingRepository and crudRepository are work for both sql
and nosql databases
->hash , bucket
A HashMap in Java uses buckets to store key-value pairs. Keys are hashed to
determine the bucket index,
handling collisions with linked lists or binary trees for efficient
retrieval, insertion, and deletion of entries.
->When should i go for hashmap and when should i go for concurrent hasmap ?
choose HashMap for single-threaded environments and
ConcurrentHashMap for multi-threaded environments where thread safety and
concurrency are required
->How do you connect database in spring boot ?
Add dependencies for Spring Data JPA and your database driver.
Configure the database connection in application.properties or
application.yml.
Create entity classes annotated with @Entity.
Create repository interfaces extending JpaRepository.
Use the repositories in service or controller classes to perform CRUD
operations.
Create a REST controller to handle HTTP requests.
->which layer managing transactions ?
DAO
->I want to monitor the springboot applications,what are libraries can i use ?
Spring Boot Actuator provides built-in monitoring features.
Micrometer offers a consistent API for application metrics.
Prometheus and Grafana are powerful for metrics collection, storage, and
visualization.
Zipkin facilitates distributed tracing for microservices.
ELK Stack is commonly used for centralized logging and log analysis.
-> Which among String or String Buffer should be preferred when there are lot of
updates required to be done in the data?
StringBuffer is mutable and dynamic in nature whereas String is immutable. Every
updation / modification of String creates a new String thereby overloading the
string pool with unnecessary objects. Hence, in the cases of a lot of updates,
it is always preferred to use StringBuffer as it will reduce the overhead of the
creation of multiple String objects in the string pool.
->What is Singleton in java and create your own singleton class countering all
breakable conditions?
Singleton pattern ensures a class has only one instance and provides a global
point of access to it.
->What is Auto Configuration?
Auto Configuration in Spring Boot automatically configures the Spring application
based on dependencies present in the classpath.
->@Primary vs @Qualifier
@Primary annotation is used to give higher preference to a bean when multiple
beans of the same type are present,
while @Qualifier is used to specify which bean to autowire.
->What is class loader?
Class loader is responsible for loading classes into memory.
->Types of class loader
Types include Bootstrap, Extension, System, and Custom class loaders.
->Heap memory and stack memory ?
Heap memory is used for dynamic memory allocation,
while stack memory is used for static memory allocation and method calls.
->What is @Configuration and @bean?
@Configuration annotation is used to define a configuration class in Spring,
while @Bean annotation is used to define a bean in the Spring container.
->How Hashmap works internally?
HashMap works internally using an array of buckets to store key-value pairs.
The key's hash code is used to determine the bucket location.
->I want to add element inside a collection where duplicates won't be allowed and
insertion order also be preserved. What should I use?
To add elements in a collection without duplicates and preserve insertion order,
use LinkedHashSet.
->Limit vs Skip
Limit is used to restrict the number of elements in a stream,
while Skip is used to skip a specified number of elements.
->Stream vs Parallel stream
Stream processes elements sequentially,
while Parallel stream processes elements concurrently.
->Lock vs Synchronisation
Locks provide exclusive access to a shared resource,
while Synchronization ensures only one thread can access a shared resource at a
time
or
Synchronisation is a process of controlling shared resource accessibility by
multiple thread requests at a time,They are two types of synchronization
1.process synchronization
2.thread synchronization
->Monolithic vs Microservices
Monolithic architecture is a single unit with all components tightly coupled,
while Microservices architecture breaks down the application into smaller,
independent services.
->How Eureka works?
Eureka is a service registry and discovery server in Netflix OSS for
Microservices architecture.
->Why static and defaults methods are added inside interfaces?
Static and default methods in interfaces were added in Java 8 to provide backward
compatibility and allow interfaces to have concrete methods.
->What is the @Controller annotation used for? How can you create a controller
without an annotation?
The @Controller is a Spring MVC annotation to define Controller but in reality,
it's just a stereotype annotation.
You can even create a controller without @Controller by annotating the Spring MVC
Controller classes using @Component annotation.
The real job of request mapping to the handler method is done using
@RequestMapping annotation.
->How to enable debugging log in the spring boot application?
1) We can start the application with --debug switch.
2) We can set the logging.level.root=debug property in application.property file.
3) We can set the logging level of the root logger to debug in the supplied
logging configuration file.
->What is thread starvation?
Thread starvation is basically a situation or condition where a thread won’t be
able to have regular access to shared resources and therefore is unable to proceed
or make progress.
This is because other threads have high priority and occupy the resources for too
long.
This usually happens with low-priority threads that do not get CPU for its
execution to carry on.
->Differentiate between .ear, .jar and .war files.
.jar files : These files are with the .jar extension. The .jar files contain the
libraries, resources and accessories files like property files.
.war files : These files are with the .war extension. The .war file contains JSP,
HTML, javascript and other files necessary for the development of web applications.
.ear files : The .ear file contains the EJB modules of the application.
->String s1=new String(null); what is the answer
The code will throw a NullPointerException.
The code tries to create a new String object with a null value, which is not
allowed.
spring.main.web-application-type=none
The transient keyword in Java is used to indicate that a variable should not be
serialized.
->Difference between constructor and setter Injection ?
By the constructor injection partial injection is not possible but we can
achieve partial injection by setter
In the constructor injection new instance will created if any modification
but it is not possible in the setter injection we can't achieve any new instance.
-> What is the difference between @Autowired and @Inject
Both are used for same purpose
@Autowired used for Spring framework
@Inject used for java EE 6(JSR-299)
->How many types of IOC containers are there in spring ?
1.BeanFactory
2.ApplicationContext
->How to map controller class and its methods url in springMVC ?
The @RequestMapping annotation is used to map controller class and its methods
-----------------------------------------------------------------------------------
-------
200: OK - Request successful
These codes are the most commonly used and are a good starting point for
understanding HTTP status codes.
301 and 302 indicate redirects (resource has moved or is temporarily located
elsewhere).
-----------------------------------------------------------------------------------
------
These annotations are used in Spring MVC to handle web requests and responses. They
help to simplify the process of extracting data from requests and sending data in
responses.
Here's a summary:
@RequestParam:
- Used to extract a value from the request parameters (query parameters or form
data)
- Example: /users?name=John -> @RequestParam("name") String name
- Can be used to extract optional parameters (using required=false)
@RequestBody:
@ResponseBody:
- Used to indicate that the method return value should be written to the response
body
- Example: GET /users -> @ResponseBody List<User> getUsers()
- Used for returning data in the response body
-----------------------------------------------------------------------------------
----------------
-----------------------------------------------------------------------------------
--------
Configuration and Component Scanning
- @Bean: Defines a bean, which is a managed object that can be injected into other
beans.
- @Autowired: Injects a bean into another bean.
- @Value: Injects a value into a bean.
- @Qualifier: Qualifies a bean, allowing multiple beans of the same type to be
distinguished.
Web and REST
Security
Data Access
Testing
------------------------------------------------------------------------------
OR---------------------------------------------------------------------------------
--------
Configuration and Component Scanning
- @Bean: Defines a bean, which is a managed object that can be injected into other
beans.
- @Autowired: Injects a bean into another bean.
- @Value: Injects a value into a bean.
- @Qualifier: Qualifies a bean, allowing multiple beans of the same type to be
distinguished.
- @Primary: Marks a bean as the primary candidate for autowiring.
- @Profile: Activates a bean only when a specific profile is active.
Security
Data Access
Testing
Other