Tecnical Questions Java
Tecnical Questions Java
equals() method
In java equals() method is used to compare equality of two Objects. The equality can
hashCode() method
based collections like HashMap, HashSet, HashTable….etc. This method must be
time, in one JVM. A class can be made singleton by making its constructor
private.
boolean equals(Object o) is the method provided by the Object class. The default
can be overridden like String class. equals() method is used to compare the
Q10. What are the differences between Heap and Stack Memory?
The major difference between Heap and Stack memory are:
Memory Stack memory is used only by Heap memory is used by all the parts
one thread of execution. of the application.
Lifetime Exists until the end of Heap memory lives from the start till
execution of the thread. the end of application execution.
we can extend the GenericServlet class provided with the Java Servlet API.
The HttpServlet class provides methods, such as doGet() and doPost(), for
● Most of the times, web applications are accessed using HTTP protocol and
we can extend the GenericServlet class provided with the Java Servlet API.
The HttpServlet class provides methods, such as doGet() and doPost(), for
● Most of the times, web applications are accessed using HTTP protocol and
that can be HTML, JSP or another servlet in same application. We can also use
1.void forward()
2.void include()
SERVLET CYCLE
1. Servlet is loaded
2. Servlet is instantiated
3. Servlet is initialized
4. Service the request
5. Servlet is destroyed
● Creating connection
● Creating statement
● Executing queries
● Closing connection
Top 75 Java Interview Questions You
Must Prepare In 2018
Recommended by 521 users
Aayushi Johari
23 Comments
590.1K Views
Bookmark
Email Post
In this Java Interview Questions blog, I am going to list some of the most important Java Interview
Questions and Answers which will set you apart in the interview process. Java is used by approx
10 Million developers worldwide to develop applications for 15 Billion devices supporting Java. It
is also used to create applications for trending technologies like Big Data to household devices
like Mobiles and DTH boxes. And hence today, Java is used everywhere!
We have compiled a list of top Java interview questions which are classified into 7 sections,
namely:
As a Java professional, it is essential to know the right buzzwords, learn the right technologies
and prepare the right answers to commonly asked Java Interview Questions. Here’s a definitive
list of top Java Interview Questions that will guarantee a breeze-through to the next level.
In case you attended any Java interview recently, or have additional questions beyond what we
covered, we encourage you to post them in our QnA Forum. Our expert team will get back to you
at the earliest.
So let’s get started with the first set of basic Java Interview Questions.
It stands for Java It stands for Java Runtime It stands for Java Virtual
Development Kit. Environment. Machine.
It is the tool JRE refers to a runtime It is an abstract machine. It is a
necessary to environment in which java specification that provides
compile, document bytecode can be executed. run-time environment in which
and package Java java bytecode can be executed.
programs.
Along with JRE, it It implements the JVM JVM follows three notations:
includes an (Java Virtual Machine) and Specification(document that
interpreter/loader, a provides all the class describes the implementation
compiler (javac), an libraries and other support of the Java virtual machine),
archiver (jar), a files that JVM uses at Implementation(program that
documentation runtime. So JRE is a meets the requirements of JVM
generator (javadoc) software package that specification) and Runtime
and other tools contains what is required Instance(instance of JVM is
needed in Java to run a Java program. created whenever you write a
development. In Basically, it’s an java command on the
short, it contains implementation of the JVM command prompt and run
JRE + development which physically exists. class).
tools.
● public : Public is an access modifier, which is used to specify who can access this
method. Public means that this Method will be accessible by any Class.
● static : It is a keyword in java which identifies it is class based i.e it can be accessed
● void : It is the return type of the method. Void defines the method which will not return any
value.
● main: It is the name of the method which is searched by JVM as a starting point for an
application with a particular signature only. It is the method where the main execution
occurs.
Platform independent practically means “write once run anywhere”. Java is called so because of
its byte codes which can run on any system irrespective of its underlying operating system.
Java is not 100% Object-oriented because it makes use of eight primitive datatypes such as
boolean, byte, char, int, float, double, long, short which are not objects.
Wrapper classes converts the java primitives into the reference types (objects). Every primitive
data type has a class dedicated to it. These are known as wrapper classes because they “wrap”
the primitive data type into an object of that class. Refer to the below image which displays
In Java, constructor refers to a block of code which is used to initialize an object. It must have the
same name as that of the class. Also, it has no return type and it is automatically called when an
object is created.
1. Default constructor
2. Parameterized constructor
If an element is inserted into the Vector defaults to doubling size of its array.
Array List, it increases its Array size
by 50%.
Array List does not define the Vector defines the increment size.
increment size.
Array List can only use Iterator for Except Hashtable, Vector is the only other
traversing an Array List. class which uses both Enumeration and
Iterator.
Equals() method is defined in Object class in Java and used for checking equality of two objects
and used to compare primitives and objects. public boolean equals(Object o) is the method
provided by the Object class. The default implementation uses == operator to compare two
objects. For example: method can be overridden like String class. equals() method is used to
if(Str1 == str2)
5
{
6
System.out.println("String 1 == String 2 is true");
7
}
8
else
9
{
10
System.out.println("String 1 == String 2 is false");
13 {
14 System.out.println("String 2 == String 3 is true");
15 }
else
16
{
17
}
19
if(Str1.equals(str2))
20
{
21
System.out.println("String 1 equals string 2 is true");
22
}
23
else
24 {
26 }
}}
27
28
29
Q10. What are the differences between Heap and Stack Memory?
The major difference between Heap and Stack memory are:
Memory Stack memory is used only by Heap memory is used by all the parts
one thread of execution. of the application.
Access Stack memory can’t be accessed by Objects stored in the heap are
other threads.
globally accessible.
Lifetime Exists until the end of Heap memory lives from the start till
execution of the thread. the end of application execution.
In case you are facing any challenges with these java interview questions, please comment your
Get Certified With Industry Level Projects & Fast Track Your CareerTake A Look!
OOPS Java Interview Questions:
contexts – specifically, to allow an entity such as a variable, a function, or an object to have more
overridden method is called through the reference variable of a superclass. Let’s take a look at the
1 class Car {
2 void run()
{
3
System.out.println(“car is running”);
4
}
5
}
6
class Audi extends Car {
7
void run()
8
{
9
System.out.prinltn(“Audi is running safely with 100km”);
10 }
{
12
b.run();
14
}
15
}
16
17
An abstract class can have any An Interface visibility must be public (or)
visibility: public, private, protected. none.
Abstract classes are fast Interfaces are slow as it requires extra indirection
to find corresponding method in the actual class
Method Overloading :
● In Method Overloading, Methods of the same class shares the same name but each
method must have different number of parameters or parameters having different types
and order.
1 class Adder {
{
3
return a+b;
4
}
5
8
}
9
public static void main(String args[])
10
{
11 System.out.println(Adder.add(11,11));
12 System.out.println(Adder.add(12.3,12.6));
13 }}
14
Method Overriding:
● In Method Overriding, sub class have the same method with same name and exactly the
same number and type of parameters and same return type as a super class.
1 class Car {
2 void run(){
System.out.println(“car is running”);
3
}
4
void run()
6
{
7
System.out.prinltn(“Audi is running safely with 100km”);
8
}
9
public static void main( String args[])
10
{
13 }
}
14
15
You cannot override a private or static method in Java. If you create a similar method with same
return type and same method arguments in child class then it will hide the super class method;
this is known as method hiding. Similarly, you cannot override a private method in sub class
because it’s not accessible there. What you can do is create another private method with the same
name in the child class. Let’s take a look at the example below to understand it better.
1 class Base {
}
4
8
private static void display() {
9 System.out.println("Static or class method from Derived");
10 }
}
13
16
Base obj= new Derived();
17
obj1.display();
18
obj1.print();
19 }
20 }
21
22
known as multiple inheritance. Java does not allow to extend multiple classes.
The problem with multiple inheritance is that if multiple parent classes have a same method name,
then at runtime it becomes difficult for the compiler to decide which method to execute from the
child class.
Therefore, Java doesn’t support multiple inheritance. The problem is commonly referred as
Diamond Problem.
Association is a relationship where all object have their own lifecycle and there is no owner. Let’s
take an example of Teacher and Student. Multiple students can associate with a single teacher
and a single student can associate with multiple teachers but there is no ownership between the
objects and both have their own lifecycle. These relationship can be one to one, One to many,
Aggregation is a specialized form of Association where all object have their own lifecycle but
there is ownership and child object can not belongs to another parent object. Let’s take an
example of Department and teacher. A single teacher can not belongs to multiple departments,
Composition is again specialized form of Aggregation and we can call this as a “death”
relationship. It is a strong type of Aggregation. Child object dose not have their lifecycle and if
parent object deletes all child object will also be deleted. Let’s take again an example of
relationship between House and rooms. House can contain multiple rooms there is no
independent life of room and any room can not belongs to two different house if we delete the
In case you are facing any challenges with these java interview questions, please comment your
problems in the section below. Apart from this Java Interview Questions Blog, if you want to get
trained from professionals on this technology, you can opt for a structured training from edureka!
● Java Servlet is server side technologies to extend the capability of web servers by
● The javax.servlet and javax.servlet.http packages provide interfaces and classes for
● All servlets must implement the javax.servlet.Servlet interface, which defines servlet
GenericServlet class provided with the Java Servlet API. The HttpServlet class provides
● Most of the times, web applications are accessed using HTTP protocol and thats why we
mostly extend HttpServlet class. Servlet API hierarchy is shown in below image.
Q2. What are the differences between Get and Post methods?
Get Post
Limited amount of data can be sent Large amount of data can be sent
because data is sent in header. because data is sent in body.
Not Secured because data is exposed Secured because data is not exposed in
in URL bar. URL bar.
Idempotent Non-Idempotent
It is more efficient and used than Post It is less efficient and used
RequestDispatcher interface is used to forward the request to another resource that can be HTML,
JSP or another servlet in same application. We can also use this to include the content of another
1.void forward()
2.void include()
Q4. What are the differences between forward() method and
sendRedirect() methods?
forward() method works within the sendRedirect() method works within and
server only. outside the server.
1. Servlet is loaded
2. Servlet is instantiated
3. Servlet is initialized
4. Service the request
5. Servlet is destroyed
● Cookies are text data sent by server to the client and it gets saved at the client local
machine.
request, since there is no point of adding Cookie to request, there are no methods to set
The difference between ServletContext and ServletConfig in Servlets JSP is in below tabular
format.
ServletConfig ServletContext
Its like local parameter associated Its like global parameter associated with
with particular servlet whole application
It’s a name value pair defined inside ServletContext has application wide
the servlet section of web.xml file so it scope so define outside of servlet tag in
has servlet wide scope web.xml file.
Session is a conversational state between client and server and it can consists of multiple request
and response between client and server. Since HTTP and Web Server both are stateless, the only
way to maintain a session is when some unique information about the session (session id) is
1. User Authentication
2. HTML Hidden Field
3. Cookies
4. URL Rewriting
5. Session Management API
In case you are facing any challenges with these java interview questions, please comment your
problems in the section below. Apart from this Java Interview Questions Blog, if you want to get
trained from professionals on this technology, you can opt for a structured training from edureka!
JDBC Driver is a software component that enables java application to interact with the database.
● Creating connection
● Creating statement
● Executing queries
● Closing connection
The java.sql package contains interfaces and classes for JDBC API.
Interfaces:
● Connection
● Statement
● PreparedStatement
● ResultSet
● ResultSetMetaData
● DatabaseMetaData
● CallableStatement etc.
Classes:
● DriverManager
● Blob
● Clob
● Types
● SQLException etc.
register and unregister drivers. It provides factory method that returns the
instance of Connection.
DatabaseMetaData.
SPRING
● @Required
● @Autowired
● @Qualifier
● @Resource
● @PostConstruct
● @PreDestroy
23 Comments
590.1K Views
Bookmark
Email Post
In this Java Interview Questions blog, I am going to list some of the most important Java Interview
Questions and Answers which will set you apart in the interview process. Java is used by approx
10 Million developers worldwide to develop applications for 15 Billion devices supporting Java. It
is also used to create applications for trending technologies like Big Data to household devices
like Mobiles and DTH boxes. And hence today, Java is used everywhere!
We have compiled a list of top Java interview questions which are classified into 7 sections,
namely:
and prepare the right answers to commonly asked Java Interview Questions. Here’s a definitive
list of top Java Interview Questions that will guarantee a breeze-through to the next level.
In case you attended any Java interview recently, or have additional questions beyond what we
covered, we encourage you to post them in our QnA Forum. Our expert team will get back to you
at the earliest.
So let’s get started with the first set of basic Java Interview Questions.
It stands for Java It stands for Java Runtime It stands for Java Virtual
Development Kit. Environment. Machine.
● public : Public is an access modifier, which is used to specify who can access this
method. Public means that this Method will be accessible by any Class.
● static : It is a keyword in java which identifies it is class based i.e it can be accessed
● void : It is the return type of the method. Void defines the method which will not return any
value.
● main: It is the name of the method which is searched by JVM as a starting point for an
application with a particular signature only. It is the method where the main execution
occurs.
Platform independent practically means “write once run anywhere”. Java is called so because of
its byte codes which can run on any system irrespective of its underlying operating system.
Java is not 100% Object-oriented because it makes use of eight primitive datatypes such as
boolean, byte, char, int, float, double, long, short which are not objects.
Wrapper classes converts the java primitives into the reference types (objects). Every primitive
data type has a class dedicated to it. These are known as wrapper classes because they “wrap”
the primitive data type into an object of that class. Refer to the below image which displays
In Java, constructor refers to a block of code which is used to initialize an object. It must have the
same name as that of the class. Also, it has no return type and it is automatically called when an
object is created.
1. Default constructor
2. Parameterized constructor
If an element is inserted into the Vector defaults to doubling size of its array.
Array List, it increases its Array size
by 50%.
Array List does not define the Vector defines the increment size.
increment size.
Array List can only use Iterator for Except Hashtable, Vector is the only other
traversing an Array List. class which uses both Enumeration and
Iterator.
Equals() method is defined in Object class in Java and used for checking equality of two objects
and used to compare primitives and objects. public boolean equals(Object o) is the method
provided by the Object class. The default implementation uses == operator to compare two
objects. For example: method can be overridden like String class. equals() method is used to
if(Str1 == str2)
5
{
6
System.out.println("String 1 == String 2 is true");
7
}
8
else
9
{
10
System.out.println("String 1 == String 2 is false");
13 {
14 System.out.println("String 2 == String 3 is true");
15 }
else
16
{
17
}
19
if(Str1.equals(str2))
20
{
21
System.out.println("String 1 equals string 2 is true");
22
}
23
else
24 {
26 }
}}
27
28
29
Q10. What are the differences between Heap and Stack Memory?
The major difference between Heap and Stack memory are:
Memory Stack memory is used only by Heap memory is used by all the parts
one thread of execution. of the application.
Access Stack memory can’t be accessed by Objects stored in the heap are
other threads.
globally accessible.
Lifetime Exists until the end of Heap memory lives from the start till
execution of the thread. the end of application execution.
In case you are facing any challenges with these java interview questions, please comment your
Get Certified With Industry Level Projects & Fast Track Your CareerTake A Look!
OOPS Java Interview Questions:
contexts – specifically, to allow an entity such as a variable, a function, or an object to have more
overridden method is called through the reference variable of a superclass. Let’s take a look at the
1 class Car {
2 void run()
{
3
System.out.println(“car is running”);
4
}
5
}
6
class Audi extends Car {
7
void run()
8
{
9
System.out.prinltn(“Audi is running safely with 100km”);
10 }
{
12
b.run();
14
}
15
}
16
17
An abstract class can have any An Interface visibility must be public (or)
visibility: public, private, protected. none.
Abstract classes are fast Interfaces are slow as it requires extra indirection
to find corresponding method in the actual class
Method Overloading :
● In Method Overloading, Methods of the same class shares the same name but each
method must have different number of parameters or parameters having different types
and order.
1 class Adder {
{
3
return a+b;
4
}
5
8
}
9
public static void main(String args[])
10
{
11 System.out.println(Adder.add(11,11));
12 System.out.println(Adder.add(12.3,12.6));
13 }}
14
Method Overriding:
● In Method Overriding, sub class have the same method with same name and exactly the
same number and type of parameters and same return type as a super class.
1 class Car {
2 void run(){
System.out.println(“car is running”);
3
}
4
void run()
6
{
7
System.out.prinltn(“Audi is running safely with 100km”);
8
}
9
public static void main( String args[])
10
{
13 }
}
14
15
You cannot override a private or static method in Java. If you create a similar method with same
return type and same method arguments in child class then it will hide the super class method;
this is known as method hiding. Similarly, you cannot override a private method in sub class
because it’s not accessible there. What you can do is create another private method with the same
name in the child class. Let’s take a look at the example below to understand it better.
1 class Base {
}
4
8
private static void display() {
9 System.out.println("Static or class method from Derived");
10 }
}
13
16
Base obj= new Derived();
17
obj1.display();
18
obj1.print();
19 }
20 }
21
22
known as multiple inheritance. Java does not allow to extend multiple classes.
The problem with multiple inheritance is that if multiple parent classes have a same method name,
then at runtime it becomes difficult for the compiler to decide which method to execute from the
child class.
Therefore, Java doesn’t support multiple inheritance. The problem is commonly referred as
Diamond Problem.
Association is a relationship where all object have their own lifecycle and there is no owner. Let’s
take an example of Teacher and Student. Multiple students can associate with a single teacher
and a single student can associate with multiple teachers but there is no ownership between the
objects and both have their own lifecycle. These relationship can be one to one, One to many,
Aggregation is a specialized form of Association where all object have their own lifecycle but
there is ownership and child object can not belongs to another parent object. Let’s take an
example of Department and teacher. A single teacher can not belongs to multiple departments,
Composition is again specialized form of Aggregation and we can call this as a “death”
relationship. It is a strong type of Aggregation. Child object dose not have their lifecycle and if
parent object deletes all child object will also be deleted. Let’s take again an example of
relationship between House and rooms. House can contain multiple rooms there is no
independent life of room and any room can not belongs to two different house if we delete the
In case you are facing any challenges with these java interview questions, please comment your
problems in the section below. Apart from this Java Interview Questions Blog, if you want to get
trained from professionals on this technology, you can opt for a structured training from edureka!
● Java Servlet is server side technologies to extend the capability of web servers by
● The javax.servlet and javax.servlet.http packages provide interfaces and classes for
● All servlets must implement the javax.servlet.Servlet interface, which defines servlet
GenericServlet class provided with the Java Servlet API. The HttpServlet class provides
● Most of the times, web applications are accessed using HTTP protocol and thats why we
mostly extend HttpServlet class. Servlet API hierarchy is shown in below image.
Q2. What are the differences between Get and Post methods?
Get Post
Limited amount of data can be sent Large amount of data can be sent
because data is sent in header. because data is sent in body.
Not Secured because data is exposed Secured because data is not exposed in
in URL bar. URL bar.
Idempotent Non-Idempotent
It is more efficient and used than Post It is less efficient and used
RequestDispatcher interface is used to forward the request to another resource that can be HTML,
JSP or another servlet in same application. We can also use this to include the content of another
1.void forward()
2.void include()
Q4. What are the differences between forward() method and
sendRedirect() methods?
forward() method works within the sendRedirect() method works within and
server only. outside the server.
1. Servlet is loaded
2. Servlet is instantiated
3. Servlet is initialized
4. Service the request
5. Servlet is destroyed
● Cookies are text data sent by server to the client and it gets saved at the client local
machine.
request, since there is no point of adding Cookie to request, there are no methods to set
The difference between ServletContext and ServletConfig in Servlets JSP is in below tabular
format.
ServletConfig ServletContext
Its like local parameter associated Its like global parameter associated with
with particular servlet whole application
It’s a name value pair defined inside ServletContext has application wide
the servlet section of web.xml file so it scope so define outside of servlet tag in
has servlet wide scope web.xml file.
Session is a conversational state between client and server and it can consists of multiple request
and response between client and server. Since HTTP and Web Server both are stateless, the only
way to maintain a session is when some unique information about the session (session id) is
1. User Authentication
2. HTML Hidden Field
3. Cookies
4. URL Rewriting
5. Session Management API
In case you are facing any challenges with these java interview questions, please comment your
problems in the section below. Apart from this Java Interview Questions Blog, if you want to get
trained from professionals on this technology, you can opt for a structured training from edureka!
JDBC Driver is a software component that enables java application to interact with the database.
● Creating connection
● Creating statement
● Executing queries
● Closing connection
The java.sql package contains interfaces and classes for JDBC API.
Interfaces:
● Connection
● Statement
● PreparedStatement
● ResultSet
● ResultSetMetaData
● DatabaseMetaData
● CallableStatement etc.
Classes:
● DriverManager
● Blob
● Clob
● Types
● SQLException etc.
The DriverManager class manages the registered drivers. It can be used to register and unregister
The ResultSet object represents a row of a table. It can be used to change the cursor pointer and
The ResultSetMetaData interface returns the information of table such as total number of
The DatabaseMetaData interface returns the information of the database such as username, driver
instead of executing a single query. By using batch processing technique in JDBC, you can
Statement execute(String query) is used to execute any SQL query and it returns TRUE if the
result is an ResultSet such as running Select queries. The output is FALSE when there is no
ResultSet object such as running Insert or Update queries. We can use getResultSet() to get the
Statement executeQuery(String query) is used to execute Select queries and returns the
ResultSet. ResultSet returned is never null even if there are no records matching the query. When
executing select queries we should use executeQuery method so that if someone tries to execute
or DDL statements that returns nothing. The output is int and equals to the row count for SQL
Data Manipulation Language (DML) statements. For DDL statements, the output is 0.
You should use execute() method only when you are not sure about the type of statement else use
be inherited, final method can’t be overridden and final variable value can’t be
1
class FinalVarExample {
{
3
5
}
Finally
Finally is used to place important code, it will be executed whether exception is
handled or not. Let’s take a look at the example below to understand it better.
1
class FinallyExample {
try {
3
int x=100;
4
}
5
catch(Exception e) {
6 System.out.println(e);
}
7
finally {
8
System.out.println("finally block is executing");}
9
}}
10 }
11
12
Finalize
Finalize is used to perform clean up processing just before object is garbage
1
class FinalizeExample {
System.out.println("Finalize is called");
3
}
4
public static void main(String args[])
5
{
f1= NULL;
8
f2=NULL;
9
System.gc();
10
}
11 }
12
13
an exception.
threads, two or more threads may access the same fields or objects.
What is REST?
REST is web standards based architecture and uses HTTP Protocol for data communication. It
revolves around resource where every component is a resource and a resource is accessed by
a common interface using HTTP standard methods. REST was first introduced by Roy Fielding
in 2000.
In REST architecture, a REST Server simply provides access to resources and REST client
accesses and presents the resources. Here each resource is identified by URIs/ global IDs.
REST uses various representations to represent a resource like text, JSON and XML. Now a
days JSON is the most popular format being used in web services.
Name some of the commonly used HTTP methods used in REST based architecture?
Following well known HTTP methods are commonly used in REST based architecture −
● Verb − Indicate HTTP methods such as GET, POST, DELETE, PUT etc.
● Status/Response Code − Indicate Server status for the requested resource. For
example 404 means resource not found and 200 means response is ok.
key-value pairs. For example, content length, content type, response date,
What is URI?
URI stands for Uniform Resource Identifier. Each resource in REST architecture is
identified by its URI.
Purpose of an URI is to locate a resource(s) on the server hosting the web service.
<protocol>://<service-name>/<ResourceType>/<ResourceID>
Idempotent operations means their result will always same no matter how many times
these operations are invoked.
PUT and POST operation are nearly same with the difference lying only in the result
where PUT operation is idempotent and POST operation can cause different result.
It should list down the supported operations in a web service and should be read only.
Idempotent operations means their result will always same no matter how many times
these operations are invoked.
It should list down the supported operations in a web service and should be read only.
What is JAX-RS?
JAX-RS stands for JAVA API for RESTful Web Services. JAX-RS is a JAVA based
programming language API and specification to provide support for created RESTful
Webservices. Its 2.0 version was released in 24 May 2013. JAX-RS makes heavy use of
services creation and deployment. It also provides supports for creating clients for
Wikipedia defines the Spring framework as “an application framework and inversion of control
container for the Java platform. The framework’s core features can be used by any Java
application, but there are extensions for building web applications on top of the Java EE
platform.” Spring is essentially a lightweight, integrated framework that can be used for
services etc.
Q3. List some of the important annotations in annotation-based
Spring configuration.
● @Required
● @Autowired
● @Qualifier
● @Resource
● @PostConstruct
● @PreDestroy
Q4. Explain Bean in Spring and List the different Scopes of
Spring bean.
Beans are objects that form the backbone of a Spring application. They are managed by the
Spring IoC container. In other words, a bean is an object that is instantiated, assembled, and
● Singleton: Only one instance of the bean will be created for each container.
This is the default scope for the spring beans. While using this scope,
make sure spring bean doesn’t have shared instance variables otherwise it
● Prototype: A new instance will be created every time the bean is requested.
for web applications. A new instance of the bean will be created for each
HTTP request.
● Session: A new bean will be created for each HTTP session by the
container.
applications.
as it loads the spring bean configuration file and initializes all the beans that have
@Service annotations.
need to write explicit injection logic. Let’s see the code to inject bean using
dependency injection.
2) byName Injects the bean based on the property name. It uses setter
method.
3) byType Injects the bean based on the property type. It uses setter
method.
4) It injects the bean using constructor
constructor
@PathVariable – for mapping dynamic values from the URI to handler method
arguments.
you are using Hibernate 3+ where SessionFactory provides current session, then
you should avoid using HibernateTemplate or HibernateDaoSupport classes and
better to use DAO pattern with dependency injection for the integration.
Spring Framework
When DI or IOC is used properly, we can develop loosely
coupled applications. And loosely coupled applications can be
easily unit tested.
Spring MVC
Spring Boot
The problem with Spring and Spring MVC is the amount of
configuration that is needed.
<bean
class="org.springframework.web.servlet.view.Internal
ResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<mvc:resources mapping="/webjars/**"
location="/webjars/"/>
For example, if you want to get started using Spring and JPA for
database access, just include the spring-boot-starter-data-jpa
dependency in your project, and you are good to go.
Q : What are the other Starter Project Options that Spring Boot provides?
Create a folder called static under resources folder. You can put
your static content in that folder.
<script src="/js/myapp.js"></script>
Spring Data REST can be used to expose HATEOAS RESTful
resources around Spring Data repositories.
@RepositoryRestResource(c ollectionResourceRel =
"todos", path = "todos")
public interface T odoRepository
e
xtends PagingAndSortingRepository< Todo,
Long> {
Without writing a lot of code, we can expose RESTful API around
Spring Data Repositories.
POST
● URL : http://localhost:8080/todos
● Use Header : Content-Type:application/json
● Request Content
{
"user": "Jill",
"desc": "Learn Hibernate",
"done": false
}
Response Content
{
"user": "Jill",
"desc": "Learn Hibernate",
"done": false,
"_links": {
"self": {
"href": "http://localhost:8080/todos/1"
},
"todo": {
"href": "http://localhost:8080/todos/1"
}
}
}
@RepositoryRestResource(collectionResourceRel =
"users", path = "users")
● path - The path segment under which this resource is to be
exported.
● collectionResourceRel - The rel value to use when generating
links to the collection resource. This is used when generating
HATEOAS links.
HIBERNATE
Hibernate first level cache is associated with the Session object. Hibernate first
level cache is enabled by default and there is no way to disable it. However
hibernate provides methods through which we can delete selected objects from
the cache or clear the cache completely.
Any object cached in a session will not be visible to other sessions and when the
session is closed, all the cached objects will also be lost.
How to configure Hibernate Second Level Cache
using EHCache?
EHCache is the best choice for utilizing hibernate second level cache. Following
steps are required to enable EHCache in hibernate application.
Ordered list is better than sorted list because the actual sorting is done at
database level, that is fast and doesn’t cause memory issues.
LINUX
3. Describe BASH.
Answer: BASH stands for Bourne Again Shell. BASH is the UNIX shell for the GNU
operating system. So, BASH is the command language interpreter that helps you to enter
your input, and thus you can retrieve information
CLI is an acronym for Command Line Interface. We have to provide the information to the
computer so that it can perform the function accordingly.
in Linux is stored in/etc/passwd that is a compatible format. But this file is used to get the
user information by several tools. Here, security is at risk. So, we have to make it secured.
To improve the security of the password file, instead of using a compatible format we can
use shadow password format. So, in shadow password format, the password will be stored
as single “x” character which is not the same file (/etc/passwd). This information is stored in
another file instead with a file name /etc/shadow.
grep command in Linux is used to search a specific pattern. Grep command will
help you to explore the string in a file or multiple files.
tail: to check the ending of the file. It is the reverse of head command.
less: used to view the text in the backward direction and also provides
single line movement.
ANGULAR
called ng-stats can help track your watch count and digest cycles.
Create an AngularJS service that will hold the data and inject it inside of the
controllers.
Using a service is the cleanest, fastest and easiest way to test. However,
there are couple of other ways to implement data sharing between controllers,
like:
– Using events
The methods above are all correct, but are not the most efficient and easy to
test.
● 0
● Q8.
● What is BSON?
● BSON is the superset of JSON, which used by M ongoDB.BSON
supports the embedding of documents and arrays within other
documents and arrays. BSON also contains extensions that allow
representation of data types that are not part of the JSON spec.
● 0
● Q9.
● How to convert an Object into JSON? What is the
full syntax of JSON.stringify?
● JSON.stringify method is used to convert an Javascript Object into
JSON.
● Syntax:
● let json = JSON.stringify(value[, replacer, space])
● 0
● Q10.
● What JS-specific properties are skipped by
JSON.stringify method?
● Following JS-specific properties are skipped by JSON.stringify
method
○ Function properties (methods).
○ Symbolic properties.
○ Properties that store undefined.
● 0
● Q11.
● What is JSON? For what is used for?
● JSON (JavaScript Object Notation) is a data storage and
communication format based on key-value pair of JavaScript object
literals. It is a lightweight text-based open standard designed for
human-readable data interchange which is derived from the
JavaScript programming language for representing simple data
structures and associative arrays, called objects.
● In JSON
○ all property names are surrounded by double quotes.
○ values are restricted to simple data: no function calls,
variables, comments, or computations.
● JSON is used for communication between javascript and serverside
technologies.
● 0
● Q12.
● How to convert Javascript objects into JSON?
● JSON.stringify(value); is used to convert Javascript objects into JSON.
● Example Usage:
● var obj={"website":"Onlineinterviewquestions"};
JSON.stringify(obj); //
'{"website":"Onlineinterviewquestions"}'
● 0
● Q13.
● List types Natively supported by JSON?
● JSON supports Objects, Arrays, Primitives (strings, numbers, boolean
values (true/false), null) data types.
● 0
● Q14.
● What does Object.create do?
● Object.create creates a new object with the specified prototype
object and properties.
● 0
● Q15.
● What does hasOwnProperty method do?
● It returns true if the property was set on an actual object rather than
inherited.
● 0
● Q16.
● What does $.parseJSON() do ?
● $.parseJSON() takes a well-formed JSON string and returns the
resulting JavaScript value.
● 0
● Q17.
● How do you decode a JSON string?
● Use JSON.parse method to decode a JSON string into a Javascript
object.
● 0
● Q18.
● How to delete an index from JSON Obj?
● Deleting an Element from JSON Obj
● var exjson = {'key':'value'};
delete exjson['key'];