Interview Questions
Interview Questions
1. What is the objective of the project? (What are you trying to solve?)
2. What is the team size and your role in the team
3. Technologies you have used (IDEs, Version Control, CICD, Deployment platform)
4. What are some coding standards followed while developing
o Linting - pylint, flake8
o Formatting – black
o Type-checking – mypy
o Logging - logging, log4j
o Docstrings
o Testing – unit tests
o
Core Java
Which version of Java you have used?
A constructor has the same name as the class name, an ordinary method can have any name.
A constructor does not have a return type, not even void. A method has a return type. If a
method does not return any value, then the keyword void needs to be specified.
A constructor is automatically invoked when an object of the class is created. A method needs
to be invoked explicitly.
If a class does not have a constructor, Java automatically creates a default constructor. If a
class does not have a method, Java does not automatically add a method.
Nested class: Class is defined within the body of another class. It has access to all the
members of the outer class.
Static nested class: A nested class that is static is known as a static nested class. It cannot
access non–static members of the outer class.
Method local inner class: A class that is defined inside a method of another class is known as
a method local inner class. Such an inner class can only access final members of the outer
class.
Anonymous inner class: A class that has no name and can be instantiated only once when it
is defined is known as an anonymous inner class. It does not have a constructor as it does not
have a name. It cannot be static. The class definition ends with a semicolon.
Write a code sample that demonstrates how you can instantiate an inner class from an
outer class
What is multithreading
Multithreading is a situation in which multiple threads are executed simultaneously. Multithreading
consumes less memory. As threads are lightweight, they enhance the performance of an application.
Processes are independent, but the threads are the subset of a process.
Processes have different address space in the memory. However, the threads contain a shared
address space of the process.
The inter-thread communication is faster and easier than the inter-process communication.
The context switching is faster between the threads as compared to the processes.
A thread is a lightweight sub-process. It is a separate path of execution because each thread runs in a
different stack frame. A process may contain multiple threads. Threads share the process resources,
but still, they execute independently.
Advantages of multithreading
The thread is lightweight. So, it enhances the application performance.
Multithreading reduces more servers, as one server can execute multiple threads at a time.
Even though some background task is running, multithreading allows an application to be
always reactive to accept an input.
As multithreading includes execution of multiple threads independently, it allows the faster
execution of tasks.
The threads share the common memory resources. So, multithreading provides better
utilization of cache memory.
What is Synchronization?
When multiple threads try to access a shared resource at the same time, then they need some way for
the resource to be accessed by only one Thread at a time. The process which helps to achieve this is
called as synchronization. Java provides a keyword called synchronized which helps to achieve this.
What is a functional interface? How can you create a functional interface? Examples
(used in Lambda’s – Function, Predicate, Consumer etc.)
A functional interface is an interface that has only one abstract method. To create a functional
interface, you simply need to create an interface that has just one abstract method as shown below:
@FunctionalInterface
Public interface Multiplier {
Public int multiply(int a, int b);
}
This code defines an interface called Multiplier. It has only a multiply method. It has the
@FunctionalInterface annotation specified. This annotation is optional, it marks the
interface as a functional interface. So, if you try to add another abstract method to the interface, the
code causes a compilation error.
The java.util.Function is a new package added by Java 8. It has a lot of built–in functional interfaces.
Some of the interfaces in this package are as follows:
1. Predicate: This can be used to test a condition. It returns a Boolean value which indicates
whether the condition is true or false. It accepts an argument of any data type.
2. Consumer: This can be used to operate on a value. It accepts an argument of any data type
and operates on it. It returns a void.
3. Function: This can be used to transform an input value. It accepts an argument of any data
type, transforms it and returns a result.
4. Supplier: This can be used to produce a value. It does not accept any argument but produces a
result of any data type.
Creational patterns: These patterns are used to define and describe the ways of creating the
objects. They describe in depth on how objects are created at class instantiation time.
o Factory method
o Abstract factory
o Builder
o Prototype
o Singleton
Structural Patterns: The structural design patterns are concerned about how the classes and
objects can be composed together to form a larger structure. They offer an efficient solution
for the class compositions and object structures. The patterns are dependent on the concept of
inheritance, which allows multiple classes or objects to work together as a single working
unit. They simplify the structure by identifying the relationships in between them. These
patterns focus on how the classes are inherited from each other and how they are composed
from other classes
o Adapter
o Bridge
o Filter
o Composite
o Decorator
o Façade
o Flyweight
o Proxy
Behavioural patterns: The behavioural design patterns care about the interaction and
responsibility of objects. The patterns focus on the ease in the interaction between the objects.
However, the patterns make sure the communicating objects will be loosely coupled to avoid
hardcoding.
o Interpreter
o Template method/pattern
o Chain of responsibility
o Command pattern
o Iterator pattern
o Strategy pattern
o Visitor pattern
o
RxJava
WebFlux
Testing
Junit/Mocito
Spring
In Spring framework, which Dependency Injection is better? Constructor-based DI or
Setter-based DI?
Spring framework provides support for both Constructor-based and Setter-based Dependency
Injection. There are different scenarios in which these options can be used.
It is recommended to use Constructor-based DI for mandatory dependencies. Whereas Setter-based DI
is used for optional dependencies.
RestTemplate
Microservices Architecture
MySQL/Postgres/MongoDB
What are the Transient, Persistent and Detached states of an object in Hibernate?
When an object is just instantiated using the new operator but is not associated with a
Hibernate Session, then the object is in Transient state.
In Transient state, object does not have a persistent representation in database. Also, there is
no identifier assigned to an object in Transient state.
An object in Transient state can be garbage collected if there is no reference pointing to it.
An object is in detached state if it was persistent earlier, but its Session is closed now.
Any reference to this object is still valid. We can even update this object. Later on, we can
even attach an object in detached state to a new session and make it persistent.
Detached state is very useful in application transactions where a user takes some time to
finish the work.
https://www.geeksforgeeks.org/hibernate-lifecycle/
Git
Docker
Kubernetes
OpenShift