0% found this document useful (0 votes)
9 views

JAVA VIVA ??

Java is a robust, object-oriented programming language developed by Sun Microsystems in 1995, known for its platform independence through the Java Runtime Environment (JRE) and Java Virtual Machine (JVM). It supports various application types, including standalone, web, enterprise, and mobile applications, and has multiple editions such as Java SE, EE, ME, and FX. Key concepts include OOP principles, variable types, data types, operator precedence, and the use of frameworks like Spring Boot for rapid application development.

Uploaded by

himani dewangan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

JAVA VIVA ??

Java is a robust, object-oriented programming language developed by Sun Microsystems in 1995, known for its platform independence through the Java Runtime Environment (JRE) and Java Virtual Machine (JVM). It supports various application types, including standalone, web, enterprise, and mobile applications, and has multiple editions such as Java SE, EE, ME, and FX. Key concepts include OOP principles, variable types, data types, operator precedence, and the use of frameworks like Spring Boot for rapid application development.

Uploaded by

himani dewangan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 74

Basics:

What is Java?
Java is a programming language and a platform. Java is a high level, robust, object-oriented and
secure programming language.

Java was developed by Sun Microsystems (which is now the subsidiary of Oracle) in the year 1995.
James Gosling is known as the father of Java. Before Java, its name was Oak. Since Oak was already a
registered company, so James Gosling and his team changed the name from Oak to Java.

Platform: Any hardware or software environment in which a program runs, is known as a


platform. Since Java has a runtime environment (JRE) and API, it is called a platform.

Types of Java Applications


There are mainly 4 types of applications that can be created using Java programming:

1) Standalone Application

Standalone applications are also known as desktop applications or window-based applications.


These are traditional software that we need to install on every machine. Examples of standalone
application are Media player, antivirus, etc. AWT and Swing are used in Java for creating standalone
applications.

2) Web Application

An application that runs on the server side and creates a dynamic page is called a web application.
Currently, Servlet, JSP, Struts, Spring, Hibernate, JSF, etc. technologies are used for creating web
applications in Java.

3) Enterprise Application

An application that is distributed in nature, such as banking applications, etc. is called an enterprise
application. It has advantages like high-level security, load balancing, and clustering. In Java, EJB is
used for creating enterprise applications.

4) Mobile Application

An application which is created for mobile devices is called a mobile application. Currently, Android
and Java ME are used for creating mobile applications.

Java Platforms / Editions


There are 4 platforms or editions of Java:

1) Java SE (Java Standard Edition) It is a Java programming platform. It includes Java programming
APIs such as java.lang, java.io, java.net, java.util, java.sql, java.math etc. It includes core topics like
OOPs, String, Regex, Exception, Inner classes, Multithreading, I/O Stream, Networking, AWT, Swing,
Reflection, Collection, etc.
2) Java EE (Java Enterprise Edition)

It is an enterprise platform that is mainly used to develop web and enterprise applications. It is built
on top of the Java SE platform. It includes topics like Servlet, JSP, Web Services, EJB, JPA, etc.

3) Java ME (Java Micro Edition)

It is a micro platform that is dedicated to mobile applications.

4) JavaFX

It is used to develop rich internet applications. It uses a lightweight user interface API.

JVM (Java Virtual Machine) is an abstract machine. It is a


specification that provides runtime environment in which java
bytecode can be executed.
A Java virtual machine is a virtual machine that enables a computer to run Java programs as well as
programs written in other languages that are also compiled to Java bytecode.

The JVM performs following operation:

Loads code

Verifies code

Executes code

Provides runtime environment

JVM Architecture
1) Classloader

Classloader is a subsystem of JVM which is used to load class files. Whenever we run the java
program, it is loaded first by the classloader. There are three built-in classloaders in Java.

Bootstrap ClassLoader: This is the first classloader which is the super class of Extension classloader.
It loads the rt.jar file which contains all class files of Java Standard Edition like java.lang package
classes, java.net package classes, java.util package classes, java.io package classes, java.sql package
classes etc.

Extension ClassLoader: This is the child classloader of Bootstrap and parent classloader of System
classloader. It loades the jar files located inside $JAVA_HOME/jre/lib/ext directory.

System/Application ClassLoader: This is the child classloader of Extension classloader. It loads the
classfiles from classpath. By default, classpath is set to current directory. You can change the
classpath using "-cp" or "-classpath" switch. It is also known as Application classloader.

2) Class(Method) Area

Class (Method) Area stores per-class structures such as the runtime constant pool, field and method
data, the code for methods.

3) Heap
It is the runtime data area in which objects are allocated.

4) Stack

Java Stack stores frames. It holds local variables and partial results, and plays a part in method
invocation and return.

Each thread has a private JVM stack, created at the same time as thread.

A new frame is created each time a method is invoked. A frame is destroyed when its method
invocation completes.

5) Program Counter Register

PC (program counter) register contains the address of the Java virtual machine instruction currently
being executed.

6) Native Method Stack

It contains all the native methods used in the application.

7) Execution Engine

It contains:

A virtual processor

Interpreter: Read bytecode stream then execute the instructions.

Just-In-Time(JIT) compiler: It is used to improve the performance. JIT compiles parts of the byte code
that have similar functionality at the same time, and hence reduces the amount of time needed for
compilation. Here, the term "compiler" refers to a translator from the instruction set of a Java virtual
machine (JVM) to the instruction set of a specific CPU.

8) Java Native Interface

Java Native Interface (JNI) is a framework which provides an interface to communicate with another
application written in another language like C, C++, Assembly etc. Java uses JNI framework to send
output to the Console or interact with OS libraries.

JDK contains JRE + development tools. The Java Development Kit (JDK) is a software development
environment which is used to develop java applications and applets. It physically exists.

The JRE is the on-disk system that takes your Java code, combines it with the necessary libraries, and
starts the JVM to execute it JRE is the container, JVM is the content
Java Variables
A variable is a container which holds the value while the Java program is executed. A variable is
assigned with a data type.

Variable is a name of memory location. There are three types of variables in java: local, instance and
static.

A variable is the name of a reserved area allocated in memory.

1) Local Variable

A variable declared inside the body of the method is called local variable. You can use this variable
only within that method and the other methods in the class aren't even aware that the variable
exists.

A local variable cannot be defined with "static" keyword.

2) Instance Variable

A variable declared inside the class but outside the body of the method, is called an instance
variable. It is not declared as static.

It is called an instance variable because its value is instance-specific and is not shared among
instances.

3) Static variable

A variable that is declared as static is called a static variable. It cannot be local. You can create a
single copy of the static variable and share it among all the instances of the class. Memory allocation
for static variables happens only once when the class is loaded in the memory.

Data Types in Java


Data types specify the different sizes and values that can be stored in the variable. There are two
types of data types in Java:

Primitive data types: The primitive data types include boolean, char, byte, short, int, long, float and
double.

Non-primitive data types: The non-primitive data types include Classes, Interfaces, and Arrays.
Java Operator Precedence

Operator Type Category Precedence

Unary postfix expr++ expr--

prefix ++expr --expr +expr -expr ~ !

Arithmetic multiplicative * / %

additive + -

Shift shift << >> >>>

Relational comparison < > <= >= instanceof

equality == !=

Bitwise bitwise AND &

bitwise exclusive OR ^

bitwise inclusive OR |

Logical logical AND &&

logical OR ||

Ternary ternary ? :

Assignment assignment = += -= *= /= %= &= ^= |= <<= >>= >>>=


List of Java Keywords

A list of Java keywords or reserved words are given below:

1. abstract: Java abstract keyword is used to declare an abstract class. An abstract


class can provide the implementation of the interface. It can have abstract and
non-abstract methods.
2. boolean: Java boolean keyword is used to declare a variable as a boolean type.
It can hold True and False values only.
3. break: Java break keyword is used to break the loop or switch statement. It
breaks the current flow of the program at specified conditions.
4. byte: Java byte keyword is used to declare a variable that can hold 8-bit data
values.
5. case: Java case keyword is used with the switch statements to mark blocks of
text.
6. catch: Java catch keyword is used to catch the exceptions generated by try
statements. It must be used after the try block only.
7. char: Java char keyword is used to declare a variable that can hold unsigned
16-bit Unicode characters
8. class: Java class keyword is used to declare a class.
9. continue: Java continue keyword is used to continue the loop. It continues the
current flow of the program and skips the remaining code at the specified
condition.
10. default: Java default keyword is used to specify the default block of code in a
switch statement.
11. do: Java do keyword is used in the control statement to declare a loop. It can
iterate a part of the program several times.
12. double: Java double keyword is used to declare a variable that can hold 64-bit
floating-point number.
13. else: Java else keyword is used to indicate the alternative branches in an if
statement.
14. enum: Java enum keyword is used to define a fixed set of constants. Enum
constructors are always private or default.
15. extends: Java extends keyword is used to indicate that a class is derived from
another class or interface.
16. final: Java final keyword is used to indicate that a variable holds a constant
value. It is used with a variable. It is used to restrict the user from updating the
value of the variable.
17. finally: Java finally keyword indicates a block of code in a try-catch structure.
This block is always executed whether an exception is handled or not.
18. float: Java float keyword is used to declare a variable that can hold a 32-bit
floating-point number.
19. for: Java for keyword is used to start a for loop. It is used to execute a set of
instructions/functions repeatedly when some condition becomes true. If the
number of iteration is fixed, it is recommended to use for loop.
20. if: Java if keyword tests the condition. It executes the if block if the condition is
true.
21. implements: Java implements keyword is used to implement an interface.
22. import: Java import keyword makes classes and interfaces available and
accessible to the current source code.
23. instanceof: Java instanceof keyword is used to test whether the object is an
instance of the specified class or implements an interface.
24. int: Java int keyword is used to declare a variable that can hold a 32-bit signed
integer.
25. interface: Java interface keyword is used to declare an interface. It can have
only abstract methods.
26. long: Java long keyword is used to declare a variable that can hold a 64-bit
integer.
27. native: Java native keyword is used to specify that a method is implemented in
native code using JNI (Java Native Interface).
28. new: Java new keyword is used to create new objects.
29. null: Java null keyword is used to indicate that a reference does not refer to
anything. It removes the garbage value.
30. package: Java package keyword is used to declare a Java package that includes
the classes.
31. private: Java private keyword is an access modifier. It is used to indicate that a
method or variable may be accessed only in the class in which it is declared.
32. protected: Java protected keyword is an access modifier. It can be accessible
within the package and outside the package but through inheritance only. It
can't be applied with the class.
33. public: Java public keyword is an access modifier. It is used to indicate that an
item is accessible anywhere. It has the widest scope among all other modifiers.
34. return: Java return keyword is used to return from a method when its execution
is complete.
35. short: Java short keyword is used to declare a variable that can hold a 16-bit
integer.
36. static: Java static keyword is used to indicate that a variable or method is a class
method. The static keyword in Java is mainly used for memory management.
37. strictfp: Java strictfp is used to restrict the floating-point calculations to ensure
portability.
38. super: Java super keyword is a reference variable that is used to refer to parent
class objects. It can be used to invoke the immediate parent class method.
39. switch: The Java switch keyword contains a switch statement that executes
code based on test value. The switch statement tests the equality of a variable
against multiple values.
40. synchronized: Java synchronized keyword is used to specify the critical sections
or methods in multithreaded code.
41. this: Java this keyword can be used to refer the current object in a method or
constructor.
42. throw: The Java throw keyword is used to explicitly throw an exception. The
throw keyword is mainly used to throw custom exceptions. It is followed by an
instance.
43. throws: The Java throws keyword is used to declare an exception. Checked
exceptions can be propagated with throws.
44. transient: Java transient keyword is used in serialization. If you define any data
member as transient, it will not be serialized.
45. try: Java try keyword is used to start a block of code that will be tested for
exceptions. The try block must be followed by either catch or finally block.
46. void: Java void keyword is used to specify that a method does not have a return
value.
47. volatile: Java volatile keyword is used to indicate that a variable may change
asynchronously.
48. while: Java while keyword is used to start a while loop. This loop iterates a part
of the program several times. If the number of iteration is not fixed, it is
recommended to use the while loop.

OOPs (Object-Oriented Programming System)


Object-Oriented Programming is a methodology or paradigm to design a program
using classes and objects. It simplifies software development and maintenance by
providing some concepts:

Object
Class
Inheritance
Polymorphism
Abstraction
Encapsulation

Object: Any entity that has state and behavior is known as an object.
Class:Collection of objects is called class. It is a logical entity.
A class can also be defined as a blueprint from which you can create an individual
object.
Inheritance: When one object acquires all the properties and behaviors of a parent
object, it is known as inheritance. It provides code reusability. It is used to achieve
runtime polymorphism.
Polymorphism: If one task is performed in different ways, it is known as
polymorphism.
Abstraction: Hiding internal details and showing functionality is known as
abstraction.
Encapsulation: Binding (or wrapping) code and data together into a single
unit are known as encapsulation
Coupling
Coupling refers to the knowledge or information or dependency of
another class. It arises when classes are aware of each other.
Cohesion
Cohesion refers to the level of a component which performs a single well-
defined task. A single well-defined task is done by a highly cohesive
method. The weakly cohesive method will split the task into separate
parts.
------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------
---------------- ------------------------ ------------------------- --------------------------

1.Spring Boot :

Spring Boot is an open-source micro framework maintained by a company called


Pivotal. It provides Java developers with a platform to get started with an auto configurable
production-grade Spring application
Or

Spring Boot makes it easy to create stand-alone, production-grade Spring based


Applications that you can "just run".
Or

Spring Boot is a Spring module which provides RAD (Rapid Application Development)
feature to Spring framework.

It is used to create stand alone spring based application that you can just run because
it needs very little spring configuration.
2. what is DispatcherServlet and how it works?
DispatcherServlet acts as front controller for Spring based web applications. It creates
DispatcherServletWebApplicationContext and this will instantiates the backend controller and
based on the response
from the backend controller it identifies the view and send it to the client.(dispatches requests to
the handler methods
present in controller class).

3.Rest Template :
Rest Template is used to create applications that consume RESTful Web Services. You
can use the exchange() method to consume the web services for all HTTP methods.
0r
RestTemplate. is the central class within the Spring framework for executing
synchronous HTTP requests on the client side. Like Spring JdbcTemplate,
RestTemplate. is also a high-level API, which in turn is based on an HTTP client
or
Rest Template is used to create applications that consume RESTful Web Services. You
can use the exchange() method to consume the web services for all HTTP methods. The
code given below shows how to create Bean for Rest Template to auto wiring the Rest
Template object.

4. Bean autowriting concept


Spring container is able to autowire relationships between collaborating beans. ... This
is called spring bean autowiring.

5.@Component is used for?


@Component is an annotation that allows Spring to automatically detect our custom
beans. In other words, without having to write any explicit code, Spring will: Scan our
application for classes annotated with @Component. Instantiate them and inject any
specified dependencies into them

6. what is maven and sonarqube

Maven is a project management tool. It is based on POM (Project Object


Model).

or
The ability to execute the SonarQube analysis via a regular Maven
goal makes it available anywhere Maven is available (developer build, CI
server, etc.), without the need to manually download, setup, and
maintain a SonarQube Runner installation

or

Maven is a powerful project management tool that is based on POM (project object
model). It is used for projects build, dependency and documentation. It simplifies
the build process like ANT. ... In short terms we can tell maven is a tool that can be
used for building and managing any Java-based project.

Sonarqube: SonarQube is an open-source tool for continuous code inspection. It


collects and analyzes source code and provides reports on the code quality of your
projects. With regular use, SonarQube guarantees a universal standard of coding
within your organization while ensuring application sustainability.

8.Which model is used in spring mvc?


In Spring MVC, the model works a container that contains the data of the
application. Here, a data can be in any form such as objects, strings, information from
the database, etc. It is required to place the Model interface in the controller part of
the application.

Or

A Spring MVC is a Java framework which is used to build web applications. It follows
the Model-View-Controller design pattern. It implements all the basic features of a
core spring framework like Inversion of Control, Dependency Injection.

7.What is spring
Spring is an open source development framework for enterprise Java. ... Basically
Spring is a framework for dependency-injection which is a pattern that allows to build
very decoupled systems. Spring is a good framework for web development.

Or

It is a lightweight, loosely coupled and integrated framework for developing


enterprise applications in java.
8.For which technology is a JSP alternative for?
JSP provided by Sun Microsystems (now oracle) is an alternative for Microsoft’s ASP
(Active Server Pages).

9.What are the different types of JSP tags?


(Scriplet,directive,declaration tags)
JSP tags:
• Presentation tags
• JSP standard tags
• Custom tags

JSP standard tags:

• Directive tags
• Standard action tags
• Scriplet tags

Directive tags:

• Page directive
• Include directive
• Taglib directive

Standard action tags:

• Forward action
• Include action
• Use bean action

Scriplet tags:

• Scriplet tag
• Expression tag
• Declaration tag
10.Explain life cycle of a JSP?

JSP lifecycle has 7 phases


1. Translation
2. Compilation
3. Loading
4. Instantiation
5. Initialization using jsp Init() method
6. jspService() method invocation
7. Jsp destroy() method invocation.

*JSP life cycle:- client request-webs server for jsp


web server-frwds-req-to-web container
jasper engine in container converts jsp to java class(servlet)
servlet compiled to .class
web container creates obj of servelt class
req is processed by service() and response is sent to client

11. What is JSP technology used for? (Why we use JSP)


For creating web application.
Or
Java Server Pages technology (JSP) is a server-side programming language used
to create a dynamic web page in the form of HyperText Markup Language (HTML).
It is an extension to the servlet technology.

A JSP page is internally converted into the servlet. JSP has access to the entire
family of the Java API including JDBC API to access enterprise database. Hence,
Java language syntax has been used in the java server pages (JSP). The JSP pages
are more accessible to maintain than Servlet because we can separate designing
and development. It provides some additional features such as Expression
Language, Custom Tags, etc.

12.What is meant by method overloading?


Method overloading refers to the process of creating multiple methods all with
the same name. It is used to achieve virtual polymorphism in java.

13.What is the difference between method overloading and method


overriding?

Method Overloading Method Overriding

It would be performed within the same It would occur in two classes which
class. have parent-child relationship.

Number of parameters should be Number of parameters, datatypes of


different or datatypes of parameters parameters, order of occurrence of the
should be different or the order of parameters must be same.
occurrence of the parameters should
be different.
It is an example of compile time It is an example of run time
polymorphism. polymorphism.

Return type of the methods can be Overriding method should have same
different. return type as that of the parent or it
can have co-variant return type.

It is used to increase the readability of It is used to modify the method in the


the program. child class to suit its specific
requirements which is already provided
in the parent class.

14.Spring mvc implementation


A Spring MVC is a Java framework which is used to build web
applications. It follows the Model-View-Controller design pattern. It
implements all the basic features of a core spring framework like
Inversion of Control, Dependency Injection.

*Inversion of Control: it is the process of creating objects by giving


control to spring.

*Dependency Injection:are of two types setter and getter injections


type of dependency injection in which the framework injects the dependent objects
into the client using a setter method
The container is injecting a method, such as a getter method, rather than a reference or primitive
as in Setter Injection.

{ Pojo stands for plan old java objects: it will have it’s own behaviour along
with some variables setter & getters}

15.what is meant by model, view and controller?


Model :- it includes POJOs(class in which we have variables declare and getter
and setters methods.)/DTO(data transmission object), business logic and
database related operations.
View :- it include UI and it presents data to the end user.
Controller :- it acts as a link/bridge between view and model. It wil take request
from view and passes it to model and presents
the obtained result/data to the view. Simply controller gives model to view.

or

→MVC stands for Model view controller

1.It is an architecture which tells that model part should communicate with
database

2.View part should communicate with the client where as controller should
establish communication in between model and view
3.model contains java beans file,java beans is a normal java class which should
contain a constructor, setter & getter.

4.view part contains html for jsp files

5.controller contains filter & servlets.

16.Spring framework mein kaunse modules(spring frameworks


contains modules)
The Spring framework comprises of many modules such as core, beans, context,
expression language, AOP, Aspects, Instrumentation, JDBC, ORM, OXM, JMS,
Transaction, Web, Servlet, Struts etc.

Spring core, spring jpa data, mvc, rest.


Java Database Connectivity (JDBC)
Object-Relational Mapping (ORM)
Object XML Mappers
Java Message Service

Spring mvc,Core ,Data Jpa,Security,Spring rest,Spring test

Or

17.What are the modules of spring framework?

1. Test
2. Spring Core Container
3. AOP, Aspects and Instrumentation
4. Data Access/Integration
5. Web

18.View resolver:
All the handler methods in the controller returns the logical view name in String,View or
ModelAndView.
These logical views are mapped to actual views by using view resolver.
19.what is spring jpa data
It is one of the modules in the spring frameworks. spring data jpa provides jpa
template class to integrate spring application with jpa.

20.What is object?
Object − Objects have states and behaviors. ... An object is an instance of a class. Class −
A class can be defined as a template/blueprint that describes the behavior/state that the
object of its type support.
Or

Object is nothing but instance of class. It has its own state, behaviour and identity

Or

The Object is the real-time entity having some state and behavior. In Java, Object is an
instance of the class having the instance variables as the state of the object and the methods
as the behavior of the object. The object of a class can be created by using the new keyword.

21.Aggregation & Composition


In this real world there are 2types of relation ships
Which exists: is-a relationship
Has a relationship
1.to deal with is-a relationship extends keyword is used4
2.To deal with has-a relationship aggreagation &composition is used.
Has – arelationship is of two types.
Aggregation: It is the process of having has-a relationship in between
aggregate object & enclosing object. Aggregate objects are such objects which
will not be destroy automatically if enclosing object will be destroy.
Composition: It is the process of having has- a relationship in b/w composite &
enclosing object.Composite object are such objects which will be destroy if
enclosing will be destroy.
22.Spring core annotations? (di : dependency injection)

@component @bean @autowired @Value @Required @ComponentScan @Configuration


@Primary @Bean @Qualifier etc

23.Bean life cycle –

24.Isolation Level:
The Isolation level determines what happens during the concurrent (simultaneous) use
of the same transaction. Dirty Reads return different results within a single transaction
when an SQL operation accesses an uncommitted or modified record created by another
transaction.

25.how we specify relationship between entities in spring jpa


A one-to-many relationship between two entities is defined by using the @OneToMany
annotation in Spring Data JPA. It declares the mappedBy element to indicate the entity
that owns the bidirectional relationship

26.Spring MVC
Spring MVC stands for Spring Model-View-Controller is a framework that is designed with the
help of dispatcher servlet which dispatches requests to the specific controllers with the help
of annotations and that controller will return the response again to the dispatcher servlet i.e. it
will get data and view name and the view technology will fetch the data from the controller
then that page goes from dispatcher servlet to the client.

Or

A Spring MVC is a Java framework which is used to build web applications. It


follows the Model-View-Controller design pattern. It implements all the basic features
of a core spring framework like Inversion of Control, Dependency Injection.

Or

A Spring MVC is a Java Framework which is used to develop dynamic web applications.
It implements all the basic features of a core spring framework like Inversion of Control
and Dependency Injection. It follows the Model-View-Controller design pattern.
Here,

Model - A model contains the data of the application. Data can be a single object or
a collection of objects.

Controller - A controller contains the business logic of an application. Here, the


@Controller annotation is used to mark the class as the controller.

View - A view represents the provided information in a particular format. So, we can
create a view page by using view technologies like JSP+JSTL, Apache Velocity,
Thymeleaf, and FreeMarker.

27. Spring JPA Data


Spring Data JPA aims to significantly improve the implementation of data access
layers by reducing the effort to the amount that's actually needed. ... As a developer you
write your repository interfaces, including custom finder methods, and Spring will provide the
implementation automatically.

28.Constructor Injection
Constructor Injection is the act of statically defining the list of required Dependencies
by specifying them as parameters to the class's constructor. ... The class that needs
the Dependency must expose a public constructor that takes an instance of the required
Dependency as a constructor argument

29. JPA:

Java Persistence API (Application Programming Interface)


JPA is an abbreviation that stands for Java Persistence API. It's a specification
which is part of Java EE and defines an API for object-relational mappings and for
managing persistent objects.

30. Interface:
An interface in the Java programming language is an abstract type that is used to specify
a behavior that classes must implement. They are similar to protocols. Interfaces are
declared using the interface keyword, and may only contain method signature and
constant declarations.

31. Dispatcher servlet


The DispatcherServlet is an actual Servlet (it inherits from the HttpServlet base class), and
as such is declared in the web.xml of your web application. You need to map requests that
you want the DispatcherServlet to handle, by using a URL mapping in the same web.xml file.

Or
It will get the request find the appropriate controller and do send back that response to the
client it as a role of dispatcher servlet
--file name should be servlet name hyphen servlet. ispatcher servlet is also some files within
our Applications so here that file will consist of some configurations within that.

32. Encapsulation
Is an attribute of an object it contains all data which is hidden.That hidden data can be restricted to
the members of that class. Levels are public,protected,private,internal and protected internal.

Ex: It is wrapped with diff medicines in a capsule,all meedeicine is encapsulated inside a capsule.

In java we can also say that

A java class is an example of encapsulation java bean is fully encapsulated class becoz all the data
members are private here.

33.Object:
Object − Objects have states and behaviors. Example: A dog has states - color, name,
breed as well as behaviors – wagging the tail, barking, eating. An object is an instance of a
class. Class − A class can be defined as a template/blueprint that describes the
behavior/state that the object of its type support.
Or
Object:Is nothing but an instance of class.It has its own state ,behaviour and identity.
Class: a class is simply a representation of atype of object.It is blueprint or plan or template
that describes the detail of an object.
34.Inheritance and example
Inheritance is a concept where one class shares the structure and behaviour defined in another
class . if inheritance applied to one class is called single inheritance and if it depends on multiple
classes,then it is called multiple inheritance.

Ex: where as inheritance is a relationship b/w a superclass and subclass.

Superclass : the class whose features are inherited is known as superclass {parent class}

Subclass : The class that inherits the other class is known as subclass { child class}

The subclass can add its own fields and methods.

Ex:

In real -life example of inheritance is child and parents,all the properties of a father are inherited by
his son/

In java: in java library you can see extensive use of inheritance.

The number class abstracts various(numerical)or reference types such as


bytes,integer,float,double,short and big decimal.

Where here: object->extends ->number-> extends: byte,integer,float,doble.

35. Method overriding with real life example


Declaring a method in sub class which is already present in parent class is known as
method overriding. Overriding is done so that a child class can give its own implementation
to a method which is already provided by the parent class.
Or
Method overriding in java with simple example. Lets consider an example that, A Son
inherits his Father's public properties e.g. home and car and using it. At later point of
time, he decided to buy and use his own car, but, still he wants to use his father's home.

36. Spring rest


Spring RestController annotation is used to create RESTful web services using Spring
MVC. Spring RestController takes care of mapping request data to the defined request
handler method. Once response body is generated from the handler method, it converts it to
JSON or XML response.

37. What is constructor

*What is the constructor?


The constructor can be defined as the special type of method that is used to initialize
the state of an object. It is invoked when the class is instantiated, and the memory is
allocated for the object. Every time, an object is created using the new keyword, the
default constructor of the class is called. The name of the constructor must be similar
to the class name. The constructor must not have an explicit return type.

*What is Maven?
Maven is an automation and management tool developed by Apache Software
Foundation. It is written in Java Language to build projects written in C#, Ruby,
Scala, and other languages. It allows developers to create projects, dependency,
and documentation using Project Object Model and plugins. It has a similar
development process as ANT, but it is more advanced than ANT.
Maven can also build any number of projects into desired output such as jar,
war, metadata.

It was initially released on 13 July 2004. In the Yiddish language, the meaning of
Maven is “accumulator of knowledge.”

ANT stands for Another Neat Tool. It is a Java-based build tool from computer
software development company Apache.

38.HTTP:

HTTP stands for Hypertext Transfer Protocol. It is a set of rule which is used for
transferring the files like, audio, video, graphic image, text and other multimedia files
on the WWW (World Wide Web). HTTP is a protocol that is used to transfer the
hypertext from the client end to the server end, but HTTP does not have any security.
Whenever a user opens their Web Browser, that means the user indirectly uses HTTP.

39. Httpservlet
The HttpServlet class extends the GenericServlet class and implements Serializable interface.
-It provides http specific methods such as doGet, doPost, doHead, doTrace etc.

Methods of HttpServlet class


The HttpServlet class extends the GenericServlet class and implements Serializable interface.
It provides http specific methods such as doGet, doPost, doHead, doTrace etc.

There are many methods in HttpServlet class. They are as follows:


1. public void service(ServletRequest req,ServletResponse res) dispatches the
request to the protected service method by converting the request and
response object into http type.
2. protected void service(HttpServletRequest req, HttpServletResponse
res) receives the request from the service method, and dispatches the request
to the doXXX() method depending on the incoming http request type.
3. protected void doGet(HttpServletRequest req, HttpServletResponse
res) handles the GET request. It is invoked by the web container.
4. protected void doPost(HttpServletRequest req, HttpServletResponse
res) handles the POST request. It is invoked by the web container.
5. protected void doHead(HttpServletRequest req, HttpServletResponse
res) handles the HEAD request. It is invoked by the web container.
6. protected void doOptions(HttpServletRequest req, HttpServletResponse
res) handles the OPTIONS request. It is invoked by the web container.
7. protected void doPut(HttpServletRequest req, HttpServletResponse
res) handles the PUT request. It is invoked by the web container.
8. protected void doTrace(HttpServletRequest req, HttpServletResponse
res) handles the TRACE request. It is invoked by the web container.
9. protected void doDelete(HttpServletRequest req, HttpServletResponse
res) handles the DELETE request. It is invoked by the web container.
10. protected long getLastModified(HttpServletRequest req) returns the time
when HttpServletRequest was last modified since midnight January 1, 1970
GMT.

40.Why do we use MVC?


Faster development process: MVC supports rapid and parallel development. If an MVC
model is used to develop any particular web application then it is possible that one
programmer can work on the view while the other can work on the controller to create the
business logic of the web application.

41.Spring Security
Spring Security is a powerful and highly customizable authentication and access-
control framework. It is the de-facto standard for securing Spring-based applications.

Or
Spring security with example:-------------

Spring Security provides ways to perform authentication and authorization in a web


application. We can use spring security in any servlet based web application.

Or

Introduction
Spring Security is a framework which provides various security features like:
authentication, authorization to create secure Java Enterprise Applications.

It is a sub-project of Spring framework which was started in 2003 by Ben Alex. Later
on, in 2004, It was released under the Apache License as Spring Security 2.0.0.

It overcomes all the problems that come during creating non spring security
applications and manage new server environment for the application.

This framework targets two major areas of application are authentication and
authorization. Authentication is the process of knowing and identifying the user that
wants to access.

42.Develop Platform:
Java is a general-purpose, class-based, object-oriented programming language designed for
having lesser implementation dependencies. It is a computing platform for application
development. Java is fast, secure, and reliable, therefore.

43. @ModelAttribute
@ModelAttribute is a Spring-MVC specific annotation used for preparing the model data.
It is also used to define the command object that would be bound with the HTTP request data.
The annotation works only if the class is a Controller class (i.e. annotated with @Controller).

44. Reponsebody
The response body consists of the resource data requested by the client. In our example,
we requested the book's data, and the response body consists of the different books present
in the database along with their information
45. Exceptions in java
In Java “an event that occurs during the execution of a program that disrupts the
normal flow of instructions” is called an exception. This is generally an unexpected or
unwanted event which can occur either at compile-time or run-time in application code.

46. Types of collections


There are three generic types of collection: ordered lists, dictionaries/maps, and sets.
Ordered lists allows the programmer to insert items in a certain order and retrieve those
items in the same order. An example is a waiting list. The base interfaces for ordered lists
are called List and Queue.

47.List

The Java. util. List is a child interface of Collection. It is an ordered collection of objects in
which duplicate values can be stored. ... List Interface is implemented by ArrayList,
LinkedList, Vector and Stack classes.

48 JDBC

Java Database Connectivity (JDBC) is an application programming interface (API) for the
programming language Java, which defines how a client may access a database. ... It
provides methods to query and update data in a database, and is oriented toward relational
databases.

49.JPA
JPA is just a specification that facilitates object-relational mapping to manage
relational data in Java applications. It provides a platform to work directly with objects
instead of using SQL statements
Or
The Java Persistence API (JPA) is a specification that defines how to persist data in Java
applications. The primary focus of JPA is the ORM layer. mvc is one of the most popular
Java ORM frameworks in use today.

50.Spring MVC
A Spring MVC is a Java framework which is used to build web applications. It follows the
Model-View-Controller design pattern. It implements all the basic features of a core spring
framework like Inversion of Control, Dependency Injection.
51.Difference between ArrayList and LinkedList

52. Difference between List and Set:


Difference between List and Set:
List Set

1. The List is an ordered sequence. 1. The Set is an unordered sequence.

2. Set doesn’t allow duplicate


2. List allows duplicate elements elements.

3. Elements by their position can be 3. Position access to elements is not


accessed. allowed.

4. Multiple null elements can be stored. 4. Null element can store only once.

5. List implementations are ArrayList, 5. Set implementations are HashSet,


LinkedList, Vector, Stack LinkedHashSet.

53.Collection
The Collection in Java is a framework that provides an architecture to store and
manipulate the group of objects. Java Collections can achieve all the operations that you
perform on a data such as searching, sorting, insertion, manipulation, and deletion. Java
Collection means a single unit of objects.

54. Spring model


In Spring MVC, the model works a container that contains the data of the application.
Here, a data can be in any form such as objects, strings, information from the database, etc.
It is required to place the Model interface in the controller part of the application.

55. View resolver


Spring provides view resolvers, which enable you to render models in a browser without
tying you to a specific view technology. ... The two interfaces which are important to the way
Spring handles views are ViewResolver and View . The ViewResolver provides a mapping
between view names and actual views

56. Flow of Spring MVC


Spring MVC is a Java framework that is used to develop web applications. It is built on a
Model-View-Controller (MVC) pattern and possesses all the basic features of a spring
framework, such as Dependency Injection, Inversion of Control.

57. Advantages of a Spring Boot application


• Fast and easy development of Spring-based applications;
• No need for the deployment of war files;
• The ability to create standalone applications;
• Helping to directly embed Tomcat, Jetty, or Undertow into an application;
• No need for XML configuration;
• Reduced amounts of source code;
Or

200.What is spring? What are its adavantages?


Spring is one of the most popular open source framework for developing enterprise
applications. It provides comprehensive infrastructure support for developing Java based
applications. Spring also enables the developer to create high performing, reusable, easily
testable and loose coupling enterprise Java application.

58. Difference between front end and back end controller


Frontend - are the parts, which are visible to users: HTML, CSS, client-side Javascript. ... In
a desktop application frontend would be the GUI. Backend - is the invisible part. In web
applications that is your java, ruby, php or any other serverside code

59.Collection

The Collection in Java is a framework that provides an architecture to store and


manipulate the group of objects.
Java Collections can achieve all the operations that you perform on a data such as
searching, sorting, insertion, manipulation, and deletion.

Java Collection means a single unit of objects. Java Collection framework provides
many interfaces (Set, List, Queue, Deque) and classes (ArrayList,
Vector, LinkedList, PriorityQueue, HashSet, LinkedHashSet, TreeSet)

Collection vs Collections in Java with Example


Collection Collections

It is an interface. It is a utility class.

It is used to represent a group of individual It defines several utility methods that are used to
objects as a single unit. operate on collection.

60.What is comparator and comparable


Comparable is meant for objects with natural ordering which means the object itself must
know how it is to be ordered. For example Roll Numbers of students. ... Logically,
Comparable interface compares “this” reference with the object specified and Comparator in
Java compares two different class objects provided.

61. Why backend controller


The main aim of the controller is to help simplify the most common tasks that you need
to do when setting up routes and functions/classes to handle them

62. Jstl core tags


The JavaServer Pages Standard Tag Library (JSTL) is a collection of useful JSP
tags which encapsulates the core functionality common to many JSP applications. JSTL has
support for common, structural tasks such as iteration and conditionals, tags for
manipulating XML documents, internationalization tags, and SQL tags.

63. How will you create servlet? Explain flow


How do you create a servlet?
The steps are as follows:
1. Create a directory structure.
2. Create a Servlet.
3. Compile the Servlet.
4. Create a deployment descriptor.
5. Start the server and deploy the project.
6. Access the servlet.
Or

There are given 6 steps to create a servlet example. These steps are required for all
the servers.

The servlet example can be created by three ways:

1. By implementing Servlet interface,


2. By inheriting GenericServlet class, (or)
3. By inheriting HttpServlet class

The mostly used approach is by extending HttpServlet because it provides http request
specific method such as doGet(), doPost(), doHead() etc.

What is doGet and doPost?

The doGet() method is used for getting the information from server while the doPost()
method is used for sending information to the server.

Here, we are going to use apache tomcat server in this example. The steps are as
follows:

1. Create a directory structure


2. Create a Servlet
3. Compile the Servlet
4. Create a deployment descriptor
5. Start the server and deploy the project
6. Access the servlet

GenericServlet
GenericServlet is an abstract class which implements Servlet and
ServletConfig interface. GenericServlet class can also be used to create a
Servlet. GenericServlet class is part of the Servlet API and the full path to import
this class is javax. servlet. GenericServlet.
64.What is servlet workflow?
Web container is responsible for managing execution of servlets and JSP
pages for Java EE application. When a request comes in for a servlet, the
server hands the request to the Web Container. Web Container is responsible
for instantiating the servlet or creating a new thread to handle the request.

65. How to implement crud operations in jpa


How are CRUD operations implemented?

CRUD is an acronym that stands for Create, Read, Update, and Delete. These are the four
most basic operations that can be performed with most traditional database systems and
they are the backbone for interacting with any database.
Search for: How are CRUD operations implemented?

201.What is JPA CRUD?


The CRUD stands for Create, Retrieve (Read), Update and Delete operations on an
Entity. ... The EntityManager, em represents a JPA link to the relational database which can
be used to perform CRUD operations on the Entity objects. In JPA the EntityManager is an
interface which is associated with a persistence context.

66. What is Scenario technology?


Technology scenarios represent a holistic approach for managing innovation processes
and technologies efficiently. A multidimensional requirement catalogue for specific
product- market- combinations represents the fundamental building block for the ranking of
particular material- components and technologies.

67. What is a HTTP verb?


HTTP defines a set of request methods to indicate the desired action to be
performed for a given resource. Although they can also be nouns, these request
methods are sometimes referred to as HTTP verbs

68. Annotations
an annotation is a form of syntactic metadata that can
be added to Java source code.
Or
Java Annotation is a tag that represents the metadata i.e. attached with class, interface,
methods or fields to indicate some additional information which can be used by java
compiler and JVM.

Annotations in Java are used to provide additional information, so it is an alternative


option for XML and Java marker interfaces.

First, we will learn some built-in annotations then we will move on creating and using
custom annotations.

Or

Annotations are used to provide supplement information about a program.


• Annotations start with '@'.
• Annotations do not change action of a compiled program.
• Annotations help to associate metadata (information) to the program elements
i.e. instance variables, constructors, methods, classes, etc.

69. What is a class?


Class is a blueprint. Using the class, JVM creates an object. A class does not exist
in reality. (Contractor example:
Building plan – class
JVM – Contractor
Actual Building - object)

70. What is an object?


Object is a real world entity which has a physical existence. An object is created
by the JVM by referring to the class.

71. What is Java Servlets?


Servlet is basically a java file which can take the request from the client and process the
request and provide response in the form of html page. Deployment descriptor mentions
which servlet should be called for which request and mapping can be done using xml files or
annotations
72. Inversion of control

73. Types of Inversion of control

74. Create Application Context in project


75.Dependency Injection

76. Difference between setter and constructor injection


77. Bean wiring and @Auto wired annotation

78.InternalResourceViewResolver in spring mvc?


79.Difference between @Component @Controller @Repository

80. @ComponentScan annotation


.

81. spring vs spring boot diff


82. Features of spring boot

83.spring boot works

84. configure spring boot externally


85.Spring boot starters

86. autoconfiguration in spring boot

87.change the port


88.spring boot actuator

89.spring boot devtools


DevTools stands for Developer Tool. The aim of the module is to try and improve the
development time while working with the Spring Boot application. Spring Boot DevTools
pick up the changes and restart the application.

90.spring boot external database


91. rest and restful

92.life cycle of servlet

93.servlet config

94.servlet context
95.better way of maintaining session

96.http session object

97.diff post and get

98.
99.implicit objects of jsp

100.JDBC
101.Types of JDBC

102. statement,prepared statement


1. Statement :
It is used for accessing your database. Statement interface cannot accept
parameters and useful when you are using static SQL statements at runtime.
If you want to run SQL query only once then this interface is preferred over
PreparedStatement.
2. PreparedStatement :
It is used when you want to use SQL statements many times. The
PreparedStatement interface accepts input parameters at runtime.
Difference between CallableStatement and PreparedStatement :

Statement PreparedStatement
It is used when SQL query is to be It is used when SQL query is to be executed
executed only once. multiple times.
You can not pass parameters at runtime. You can pass parameters at runtime.
Used for CREATE, ALTER, DROP Used for the queries which are to be executed
statements. multiple times.
Performance is very low. Performance is better than Statement.
It is base interface. It extends statement interface.
Used to execute normal SQL queries. Used to execute dynamic SQL queries.
We can not used statement for reading We can used Preparedstatement for reading
binary data. binary data.
It is used for DDL statements. It is used for any SQL Query.
We can not used statement for writing We can used Preparedstatement for writing
binary data. binary data.
No binary protocol is used for
communication. Binary protocol is used for communication.
103. java 8 feature
Feature Name Description
Lambda expression A function that can be shared or referred to as an object.
Functional Interfaces
Single abstract method interface.
Method References Uses function as a parameter to invoke a method.
It provides an implementation of methods within interfaces
Default method enabling 'Interface evolution' facilities.
Stream API Abstract layer that provides pipeline processing of the data.
New improved joda-time inspired APIs to overcome the
Date Time API drawbacks in previous versions
Wrapper class to check the null values and helps in further
Optional processing based on the value.
Nashorn, JavaScript An improvised version of JavaScript Engine that enables
Engine JavaScript executions in Java, to replace Rhino.

104. What do you mean by abstract class?


An abstract class is a template definition of methods and variables of a class
(category of objects) that contains one or more abstracted methods. ... Declaring a
class as abstract means that it cannot be directly instantiated, which means that
an object cannot be created from it.

105. functional interface


A functional interface is an interface that contains only one abstract method.
They can have only one functionality to exhibit. From Java 8
onwards, lambda expressions can be used to represent the instance of a
functional interface. A functional interface can have any number of default
methods. Runnable, ActionListener, Comparable are some of the
examples of functional interfaces.
Before Java 8, we had to create anonymous inner class objects or implement
these interfaces.

106. Map , set


Set:
A Set is a Collection that cannot contain duplicate elements. It models the mathematical
set abstraction. The Set interface contains only methods inherited from Collection and adds
the restriction that duplicate elements are prohibited.
Map:
A Map is an object that maps keys to values. A map cannot contain duplicate keys: Each
key can map to at most one value. It models the mathematical function abstraction. ... The
Java platform contains three general-purpose Map implementations: HashMap , TreeMap ,
and LinkedHashMap .
What is the difference between a Map and a set?

Both Set and Map interfaces are used to store a collection of objects as a single unit. The
main difference between Set and Map is that Set is unordered and contains different
elements, whereas Map contains the data in the key-value pair.

107.Unit Testing
Unit testing involves the testing of each unit or an individual component of the software
application. It is the first level of functional testing. The aim behind unit testing is to validate
unit components with its performance.

A unit is a single testable part of a software system and tested during the development phase
of the application software.

The purpose of unit testing is to test the correctness of isolated code. A unit component is an
individual function or code of the application. White box testing approach used for unit
testing and usually done by the developers.

Whenever the application is ready and given to the Test engineer, he/she will start checking
every component of the module or module of the application independently or one by one,
and this process is known as Unit testing or components testing.

108. Integration testing


Integration testing is the second level of the software testing process comes after unit
testing. In this testing, units or individual components of the software are tested in a
group. The focus of the integration testing level is to expose defects at the time of
interaction between integrated components or units.
[8:55 am, 02/09/2021] Sravani: ContextConfig: used to locate spring configurations(xml files). We
provide full path inside param value tag

[8:55 am, 02/09/2021] Sravani: Context hierarchy : defines 2 types of web application contexts- root
and servlet / child web application context

[8:55 am, 02/09/2021] Sravani: VIVA

[8:55 am, 02/09/2021] Sravani: Context configuration helps in loading the spring configurations from
xml files.

109.What is @inject annotation in spring?


@Inject annotation is a standard annotation, which is defined in the standard
"Dependency Injection for Java" (JSR-330). Spring (since the version 3.0) supports
the generalized model of dependency injection which is defined in the standard JSR-
330.

120.valid :
The @Valid annotation is used to mark nested attributes in particular. This triggers the
validation of the nested object. For instance, in our current scenario, let's create a
UserAddress object: public class UserAddress { @NotBlank private String countryCode; //
standard constructors / setters / getters / toString

--------------------------------------------------------------------------------------------------

121)@ModelAttribute:
For parameter annotations, think of @ModelAttribute as the equivalent of @Autowired +
@Qualifier i.e. it tries to retrieve a bean with the given name

from the Spring managed model. If the named bean is not found, instead of throwing an error or
returning null, it implicitly takes on the role of @Bean i.e.

Create a new instance using the default constructor and add the bean to the model.

The @ModelAttribute is an annotation that binds a method parameter or method return value to a
named model attribute and then exposes it to a web view.

122)@Autowired:
To autowire a relationship between the collaborating beans without using constructor arguments
and property tags that reudces rhe amount of XML configaration.It

automatically injects the dependent beans into the associated references of a POJO class.

Or
The @Autowired annotation can be used to autowire bean on the
setter method just like @Required annotation, constructor, a
property or methods with arbitrary names and/or multiple
arguments.

123)@RequestMapping :
Most imp annotation.This maps http request to handler methods of MVC and REST controllers.Can
be applied to class level/method level in a controller.

Maps web requests onto specific handleer classes/handler methods.

124)Bean :
In Spring, the objects that form the backbone of your application and that are managed by the
Spring IoC container are called beans.

A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC
container.

125)what's difference between entity and bean class:

126)ORM.XML :
The standard JPA orm. xml file applies metadata to the persistence unit. It provides support for all of
the JPA 2.0 mappings.

You can use this file instead of annotations or to override JPA annotations in the source code.

127)How many ways we can write query in jpa :


Query, written in Java Persistence Query Language (JPQL) syntax. NativeQuery, written in plain SQL
syntax.

128)Explain invalid date exception part :

129)Difference between CRUD repository and JPA repository :


130)@PersistenceContext :
widely used by JPA/Hibernate developers to inject an Entity Manager into their DAO classes.

131)Annotations :
@Entity and @Id . The @Entity annotation specifies that the class is an entity and is mapped to a
database table.

@Table annotation specifies the name of the database table to be used for mapping.

132)Uses of bean Classes :


In computing based on the Java Platform, JavaBeans are classes that encapsulate many objects into
a single object (the bean).

They are serializable, have a zero-argument constructor, and allow access to properties using getter
and setter methods. The name "Bean"

was given to encompass this standard, which aims to create reusable software components for Java.

133)Check for validations and exceptions in code :


Exceptions : are the unusual behaviour of the code and it should be managed so that it does not
affect the flow of the rest of the code.

Validations : The possible errors that we can suggest to the user.

134)Explain Spring MVC :


A Spring MVC is a Java framework which is used to build web applications. It follows the Model-
View-Controller design pattern.
MVC Model-represents the POJO'S,bussiness logic,database logic.

View-responsible to generate/select the User interface and present the data to the end user

Controller-Intercepts all the requests/commands sent to the application and updates the view.

It implements all the basic features of a core spring framework like Inversion of Control, Dependency
Injection.

A Spring MVC provides an elegant solution to use MVC in spring framework by the help of
DispatcherServlet.

Here, DispatcherServlet is a class that receives the incoming request and maps it to the right
resource such as controllers, models, and views.

135)@Service -specialization of @Component at the service layer


@Component-indicates that an annotated class is a spring component

136)Application context :
The ApplicationContext is the central interface within a Spring application that is used for providing
configuration information to the application.

It represents the Spring IoC container and is responsible for instantiating, configuring, and
assembling the beans.

The container gets its instructions on what objects to instantiate, configure,

and assemble by reading configuration metadata.

137)Binding result :
BindingResult holds the result of a validation and binding and contains errors that may have
occurred.

The BindingResult must come right after the model object that is validated or else Spring fails to
validate the object and throws an exception

138)Can we write the code without Internal View resolver ?? No

139)Whether the <servlet-name> can be different :


<servlet-name>we can give servlet name here </servlet-name> and that should not be compulsion
to match with the .XML name
For example <servlet-name>abc</servlet-name>

And the file name can be anything like this def.xml

140)View resolver :
Spring MVC Framework provides the ViewResolver interface, that maps view names to actual views.

It also provides the View interface, which addresses the request of a view to the view technology.

(or)

In Spring MVC based application, the last step of request processing is to return the logical view
name.

Here DispatcherServlet has to delegate control to a view template so the information is rendered.

This view template decides that which view should be rendered based on returned logical view
name.

These view templates are one or more view resolver beans declared in the web application context.
These beans have to implement the ViewResolver interface for DispatcherServlet to auto-detect
them. Spring MVC comes with several ViewResolver implementations.

141)InternalResourceViewResolver :(URL based):


In most of Spring MVC applications, views are mapped to a template’s name and location directly.
InternalResourceViewResolver helps in mapping

the logical view names to directly view files under a certain pre-configured directory.

Uses prefix and suffix to map the view.

142)@Valid :
value="txmanager" : To avoid transcational begin and commit after persisting every data,,we use
this.

@Transactional : there are two types if transaction management Global(managed byy spring
containers) and local(database)

Definition : used to give metadata to transactional proxy to perform transaction management.

Transaction management ensures data integruty and consistency at any environment.


143)Dispatcher Servlet :
It is a front cotroller,where a single servlet receives all requests and transfers them to all the other
components of the application.

It's task is to send the request to the specific MVC controller.

144)Inversion of control :
Run time will be able to create objects and give it back to the code.

145)Getters and setters :


For each instance variable, a getter method returns its value while a setter method sets or updates
its value.Used for data encapsulation.

146)@RepositoryDefnition :
customization to expose selected methods in the interface can be achieved.

extending CRUD will provde the complete set of methods avalable for entity manipulation.

@Repository: annotation is used to indicate that the class provides the mechanism for storage,
retrieval, search, update and delete operation on objects.

Questions and Answers:-

148.What tags will be present in web.xml?


• context-param.
• description.
• display-name.
• distributable.
• ejb-ref.
• ejb-local-ref.
• env-entry.
• error-page.

149.Where will the exceptions be placed in ( which layer)


Ans: The Controller layer is where the Domain Exceptions will be treated.
150.How to deal with exception in spring
Ans: You can add extra ( @ExceptionHandler ) methods to any controller to
specifically handle exceptions thrown by request handling ( @RequestMapping )
methods in the same controller. Such methods can: Handle exceptions without the
@ResponseStatus annotation.

151.How to manage session in spring framework


Ans:

1. Spring Session Core: Provides API and core support for session
management.
2. Spring Session JDBC: provides session management using relational
database.
3. Spring Session Data Redis: provides session management implementation
for Redis database.
4. Spring Session Hazelcast: provides session management support using
Hazelcast.

152.Diif array and array list:


Basis Array ArrayList

Definition An array is a dynamically-created object. It The ArrayList is a class of


serves as a container that holds the constant Java Collections framework. It
number of values of the same type. It has a contains popular classes like Vector,
contiguous memory location. HashTable, and HashMap.

Static/ Array is static in size. ArrayList is dynamic in size.


Dynamic

Resizable An array is a fixed-length data structure. ArrayList is a variable-length data


structure. It can be resized itself
when needed.

Initialization It is mandatory to provide the size of an array We can create an instance of


while initializing it directly or indirectly. ArrayList without specifying its size.
Java creates ArrayList of default size.

Performance It performs fast in comparison to ArrayList ArrayList is internally backed by the


because of fixed size. array in Java. The resize operation in
ArrayList slows down the
performance.

Primitive/ An array can store We cannot store primitive type in


Generic type both objects and primitives type. ArrayList. It automatically converts
primitive type to object.

Iterating We use for loop or for each loop to iterate We use an iterator to iterate over
Values over an array. ArrayList.

Type-Safety We cannot use generics along with array ArrayList allows us to store
because it is not a convertible type of array. only generic/ type, that's why it is
type-safe.

Length Array provides a length variable which ArrayList provides the size() method
denotes the length of an array. to determine the size of ArrayList.
Adding We can add elements in an array by using Java provides the add() method to
Elements the assignment operator. add elements in the ArrayList.

Single/ Multi- Array can be multi-dimensional. ArrayList is always single-


Dimensional dimensional.

153.What is lambda?
Ans: A lambda expression is a short block of code which takes in parameters and
returns a value.

154.What is functional interface


Ans: A functional interface in Java is an interface that contains only a single
abstract (unimplemented) method. A functional interface can contain default and
static methods which do have an implementation, in addition to the single
unimplemented method.

155.Diff between jpa and dpa data

JPA Hibernate

Java Persistence API (JPA) defines the management Hibernate is an Object-Relational Mapping
of relational data in the Java applications. (ORM) tool which is used to save the state of
Java object into the database.

It is just a specification. Various ORM tools It is one of the most frequently used JPA
implement it for data persistence. implementation.

It is defined in javax.persistence package. It is defined in org.hibernate package.

The EntityManagerFactory interface is used to It uses SessionFactory interface to create


interact with the entity manager factory for the Session instances.
persistence unit. Thus, it provides an entity manager.

It uses EntityManager interface to create, read, and It uses Session interface to create, read, and
delete operations for instances of mapped entity delete operations for instances of mapped
classes. This interface interacts with the persistence entity classes. It behaves as a runtime interface
context. between a Java application and Hibernate.

It uses Java Persistence Query Language (JPQL) as It uses Hibernate Query Language (HQL) as an
an object-oriented query language to perform object-oriented query language to perform
database operations. database operations.

156.Duration of sprint.
Ans: That is, the Team needs to be able to get Stories Done. It's a rule of Scrum
that a Sprint should never be longer than one month. Generally speaking, the Sprint
length should be approximately three times as long as it takes to Swarm on an
average medium-size Story and get it Done.

157.Life cycle of servlet.


Ans:

1. Servlet class is loaded.


2. Servlet instance is created.
3. init method is invoked.
4. service method is invoked.
5. destroy method is invoked.

158.Spring mvc life cycle.


Ans: The entire process is request-driven. There is a Front Controller pattern and the
Front Controller in Spring MVC is DispatcherServlet. Upon every incoming request
from the user, Spring manages the entire life cycle

159.Which annotation is used to call handler method.


Ans: @ResponseBody. This annotation is used to annotate request handler
methods
160.controller vs rest controller
The @controller is a common annotation that is used to mark a
class as spring MVC controller

while @rest controller is a special controller used in RESTful


web services and the equivalent of @controller + @response body

161.What is Agile?

Agile is a methodology that focuses on continuously delivering small


manageable increments of a project through iterative development and
testing. It was introduced as an alternative to the traditional waterfall
methodology, known for its structured, linear, sequential life-cycle.

162.What is Devops?

DevOps is the combination of cultural philosophies, practices, and tools


that increases an organization’s ability to deliver applications

163.What is the JPQL?


JPQL is the Java Persistence query language defined in JPA specification. It is used to
construct the queries

164. What is the difference between an abstract class and an interface


in Java?

The key technical differences between an abstract class and an interface are: Abstract
classes can have constants, members, method stubs (methods without a body) and
defined methods, whereas interfaces can only have constants and methods stubs
166.What is entity life cycle?

The life cycle of entity objects consists of four states: New, Managed, Removed and
Detached. When an entity object is initially created its state is New. In this state the object is
not yet associated with an EntityManager. persistence.

165.Life Cycle of a Servlet (Servlet Life


Cycle)

A servlet life cycle can be defined as the entire process from its creation till the
destruction. ... The servlet is initialized by calling the init() method. The servlet calls
service() method to process a client's request. The servlet is terminated by calling the
destroy() method.
….>

1. Life Cycle of a Servlet


1. Servlet class is loaded
2. Servlet instance is created
3. init method is invoked
4. service method is invoked
5. destroy method is invoked

The web container maintains the life cycle of a servlet instance. Let's see the life cycle
of the servlet:

1. Servlet class is loaded.


2. Servlet instance is created.
3. init method is invoked.
4. service method is invoked.
5. destroy method is invoked.

there are three states of a servlet: new, ready and end. The servlet is in new state if
servlet instance is created. After invoking the init() method, Servlet comes in the ready
state. In the ready state, servlet performs all the tasks. When the web container invokes
the destroy() method, it shifts to the end state.
1) Servlet class is loaded
The classloader is responsible to load the servlet class. The servlet class is loaded when
the first request for the servlet is received by the web container.

2) Servlet instance is created


The web container creates the instance of a servlet after loading the servlet class. The
servlet instance is created only once in the servlet life cycle.

3) init method is invoked

The web container calls the init method only once after creating the servlet instance. The init metho
the servlet. It is the life cycle method of the javax.servlet.Servlet interface. Syntax of the init method
1. public void init(ServletConfig config) throws ServletException

4) service method is invoked


The web container calls the service method each time when request for the servlet is
received. If servlet is not initialized, it follows the first three steps as described above
then calls the service method. If servlet is initialized, it calls the service method. Notice
that servlet is initialized only once. The syntax of the service method of the Servlet
interface is given below:

1. public void service(ServletRequest request, ServletResponse response)


2. throws ServletException, IOException

5) destroy method is invoked


The web container calls the destroy method before removing the servlet instance from
the service. It gives the servlet an opportunity to clean up any resource for example
memory, thread etc. The syntax of the destroy method of the Servlet interface is given
below:

public void destroy()


167. steps in implementing spring mvc with jpa
Steps
1.
1. Create database tables and insert data
2. Create a maven web project
3. Add Spring MVC, Hibernate and MySQL depedencies
1. Update pom.xml
2. Add hibernate and database(mysql) resource file
1. create a applications.properties file under /src/main/resources
3. Add Configuration files -> Screen shot here
1. WebMvcConfig – This configuration class can be treated as a
replacement of spring-servlet.xml as it contains all the information
required for component-scanning and view resolver
2. HibernateConfig.java -This file contains information about the
database and hibernate properties
3. ServletInitializer – which acts as replacement of any spring
configuration defined in web.xml
4. Add/Update User Entity class -> Screen shot here
1. User.java
5. Create Repository Interface -> Screen shot here
1. UserRepository.java
6. Create Service Interface -> Screen shot here
1. UserService.java
2. UserServiceImpl.java
7. Update a Controller -> Screen shot here
1. UserController.java
8. Add/Update pages/views to display user details -> Screen shot here
1. home.jsp
2. addUser.jsp
3. editUser.jsp
4. allUsers.jsp
5. error.jsp
9. Delete web.xml as we will be using only java configurations
10. Run the application

168.difference between post and put


The difference between POST and PUT is that PUT requests are idempotent. That is,
calling the same PUT request multiple times will always produce the same result. In contrast,
calling a POST request repeatedly have side effects of creating the same resource multiple
times.

PUT HTTP Request


PUT is a request method supported by HTTP used by the World Wide Web.
The PUT method requests that the enclosed entity be stored under the
supplied URI. If the URI refers to an already existing resource, it is modified
and if the URI does not point to an existing resource, then the server can
create the resource with that URI.
POST HTTP Request
POST is a request method supported by HTTP used by the World Wide
Web. By design, the POST request method requests that a web server
accepts the data enclosed in the body of the request message, most likely
for storing it. It is often used when uploading a file or when submitting a
completed web form.

Difference between PUT and POST methods

PUT POST

POST method is used to


request that the origin
server accept the entity
PUT request is made to a particular resource.
enclosed in the
If the Request-URI refers to an already
request as a new
existing resource, an update operation will
subordinate of the resource
happen, otherwise create operation should
identified by the Request-
happen if Request-URI is a valid resource URI
URI in the Request-Line. It
(assuming client is allowed to determine
essentially means that
resource identifier).
POST request-URI should
Example –
be of a collection URI.
Example –
PUT /article/{article-id}
POST /articles

POST is NOT idempotent.


So if you retry the request
N times, you will end up
PUT method is idempotent. So if you send having N resources with N
retry a request multiple times, that should be different URIs created on
equivalent to single request modification. server.

Use PUT when you want to modify a single


resource which is already a part of resources
collection. PUT overwrites the resource in its
entirety. Use PATCH if request updates part of Use POST when you want
the resource. to add a child resource
under resources collection.
PUT POST

Generally, in practice, always use PUT for Always use POST for
UPDATE operations. CREATE operations.

170.methods of http

The primary or most commonly-used HTTP methods are POST, GET, PUT, PATCH,
and DELETE. These methods correspond to create, read, update, and delete (or
CRUD) operations, respectively.

171. diff sql vs jpql


The main diff b/w sql and jpql is that sql works with relational database
tables,records and fields,where as jpql works with java classes and objects.

172. spring security


Is a powerful and highly customizable authentication and access-control
framework
Auth: permission or userid already registered or not?
Autheri : limiting access to particular user
Access is given using roles mapping

173.Ioc (inversion of control ):


It is the process of creating object by giving control to spring
or
Run time is capable of creating obj and sending it to the program when needed
Depency injection is achieved through ioc

174.@autowiring
Automatic injection of beans
175.Diff b/w crud and jpa repositories:
Difference between JPA and CRUD Repositories:

• CrudRepository mainly provides CRUD functions.


• PagingAndSortingRepository provides methods to do pagination and sorting
records.
• JPA repository : - it provides functions of both CrudRepository and
PagingAndSortingRepository and it is technology specific(add some more
functionality that is specific to JPA)

176.jpa vendors
Hibernate
Eclipselinks
ibatis

177. @configuration
Used by spring containers as a source of bean definition and it
is a class level annotation

178. Rest
Representational state transfer it is an architectural pattern used
to web services which interact with each other through HTTP
protocol.

179. Lambda
(parameter)->(expressions)

180. What is Jenkins why it is used?


Jenkins is used to build and test your product continuously, so developers can
continuously integrate changes into the build. Jenkins is the most popular open
source CI/CD tool on the market today and is used in support of DevOps, alongside
other cloud native tools
continuous integration
Continuous delivery
CI stands for continuous integration, a fundamental DevOps best practice where developers
frequently merge code changes into a central repository where automated builds and tests
run. But CD can either mean continuous delivery or continuous deployment.

181. Is Jenkins a DevOps tool?


Jenkins is an open source continuous integration/continuous delivery and
deployment (CI/CD) automation software DevOps tool written in the Java
programming language. It is used to implement CI/CD workflows, called pipelines.

182. What is SonarQube used for?


SonarQube is a Code Quality Assurance tool that collects and analyzes source
code, and provides reports for the code quality of your project. It combines static and
dynamic analysis tools and enables quality to be measured continually over time.

183. What is JSP life cycle?


A JSP life cycle is defined as the process from its creation till the destruction. This is
similar to a servlet life cycle with an additional step which is required to compile a JSP into
servlet.

184.Spring test annotations:


?

185.NotNull and Notempty difference:


@NotNull: a constrained CharSequence, Collection, Map, or Array is valid as long as it's
not null, but it can be empty. @NotEmpty: a constrained CharSequence, Collection, Map,
or Array is valid as long as it's not null, and its size/length is greater than zero.

186. All classes in java inherited from which call:


All classes in java are inherited from Object class. Interfaces are
not inherited from Object Class.
A subclass inherits all the members (fields, methods, and nested classes) from
its superclass. Constructors are not members, so they are not inherited by subclasses,
but the constructor of the superclass can be invoked from the subclass.

187.Why we can't use equals method for employee object:


Now if you compare them with == it will return false despite the fact that the objects
are exactly the same. Same goes for Strings. "==" compares Object references with
each other and not their literal values. If both the variables point to same object, it
will return true.

188.What are the java 7 features:

189."Try-with- resource " method we used instead of which method:


?

190. Finally block in exceptions:


A finally block contains all the crucial statements that must be executed whether
exception occurs or not. The statements present in this block will always execute
regardless of whether exception occurs in try block or not such as closing a connection,
stream etc.

300. @contextConfiguration
@ContextConfiguration defines class-level metadata that is used to determine how to
load and configure an ApplicationContext for integration tests.

301.@Service if belongs to bean creation annotations?


This means that the bean will be created and initialized only when it is first requested for
... @Service. This annotation is used on a class. The. @Service.

This annotation is used on a class. The


@Service
marks a Java class that performs some service, such as execute
business logic, perform calculations and call external APIs. This
annotation is a specialized form of the
@Component
annotation intended to be used in the service layer.
302.Which are the annotations you used to create an beans:
While the @Component annotation is used to decorate classes that are auto-detected
by Spring scanning, the @Bean annotation is used to explicitly declare a bean creation.

303.Which are the method present in list but not in set:


The List interface provides two methods to efficiently insert and remove multiple
elements at an arbitrary point in the list

If the list's list-iterator does not support the set operation then
an UnsupportedOperationException will be thrown when replacing the first element.

304.Can we retiview the data using index in set:

The boolean value denotes if index is found the set or not. The integer value contains
the integer stored at index in the set. If the boolean value is set true, which indicates
index to be a vakid index, print the integer value stored in the pair. Otherwise print
“Invalid index”.

……///////////

401) what is Class ?


class--the basic building block of an object-oriented language
such as Java--is a template that describes the data and
behavior associated with instances of that class. When you
instantiate a class you create an object that looks and feels like
other instances of the same class.

402) What is interface ?


An interface is declared by using the interface keyword. It
provides total abstraction; means all the methods in an interface
are declared with the empty body, and all the fields are public,
static and final by default. A class that implements an interface
must implement all the methods declared in the interface.
403) What is abstract class ?

An abstract class is a template definition of methods and


variables of a class (category of objects) that contains one or
more abstracted methods. ... Declaring a class as abstract
means that it cannot be directly instantiated, which means that
an object cannot be created from it.

404) What is polymorphism ?

Polymorphisms is the ability of different objects to respond in a


unique way to the same message.

405) What is JDBC

Java Database Connectivity is an application programming


interface for the programming language Java, which defines how
a client may access a database.

JDBC makes it possible to do establish a connection with a data


source, send queries and update statements, and process the
results.

406) try-with-resources
In Java, the try-with-resources statement is a try statement
that declares one or more resources. The resource is as an
object that must be closed after finishing the program. The
try-with-resources statement ensures that each resource is
closed at the end of the statement execution.
408) what is Inheritance
Inheritance in Java is a mechanism in which one object acquires
all the properties and behaviors of a parent object. ... The idea
behind inheritance in Java is that you can create new classes
that are built upon existing classes. When you inherit from an
existing class, you can reuse methods and fields of the parent
class.

) rest API
REST or RESTful API design (Representational State Transfer)
is designed to take advantage of existing protocols. ... This
means that developers do not need to install libraries or
additional software in order to take advantage of a REST API
design.

RESTful Web services - Interview Questions

GET - Provides a read only access to a resource.

PUT - Used to create a new resource.

DELETE - Ued to remove a resource.

POST - Used to update a existing resource or create a new


resource.

OPTIONS - Used to get the supported operations on a resource.

500) spring MVC


Spring MVC is a java framework which is used to build web
applications. It follows the model-view-controller design pattern
it implements all the basic features of a cold Spring framework
like inversion of control dependency injection.

It has 4 components

Front controller, controller , view , web browser.

505) context component scan


<context:component-scan> detects the annotations by package
scanning. To put it differently, it tells Spring which packages
need to be scanned to look for the annotated beans or
components.

506) context annotation config


The <context:annotation-config> annotation is mainly used to
activate the dependency injection annotations. ... That is
because <context:annotation-config> activates the annotations
only for the beans already registered in the application context.
As can be seen here, we annotated the accountService field
using @Autowired.

507) concept of oops


Object oriented programming system (oops) is a programming
concept that works on the principles of abstraction,
encapsulation, inheritance and polymorphism. The basic concepts
of oops is to create objects reuse them through the program and
manipulate these objects to get results.
508) inheritance
Inheritance is a mechanism wherein a new class is derived from
an existing class. In Java, classes may inherit or acquire the
properties and methods of other classes.

600) annotation driven


<mvc:annotation-driven /> means that you can define spring
beans dependencies without actually having to specify a bunch of
elements in XML or implement an interface or extend a base
class.

602) @autowired
@Autowired annotation – We can use Spring @Autowired
annotation for spring bean autowiring. @Autowired annotation can
be applied on variables and methods for autowiring byType. We
can also use @Autowired annotation on constructor for
constructor based spring autowiring.

603) oops concept


Object oriented programming system is a programming concept
that works on the principles of abstraction, encapsulation,
inheritance and polymorphism. The basic concepts of oops is to
create objects reuse them without the program and manipulate
these objects to get results.

605) @rest controller vs @controller


The @Controller is a common annotation that is used to mark a
class as Spring MVC Controller
while @RestController is a special controller used in RESTFul
web services and the equivalent of @Controller +
@ResponseBody.

606) entity manager


In JPA, the EntityManager interface is used to allow applications
to manage and search for entities in the relational database. ...
The EntityManager is an API that manages the lifecycle of
entity instances. An EntityManager object manages a set of
entities that are defined by a persistence unit.

701) dispatcher servelet


The DispatcherServlet is a front controller like it provides a
single entry point for a client request to Spring MVC web
application and forwards request to Spring MVC controllers for
processing.

704) context : component scan


Basically, <context:component-scan> detects the annotations by
package scanning. To put it differently, it tells Spring which
packages need to be scanned to look for the annotated beans or
components.
705) concepts of oops
Object-Oriented Programming System (OOPs) is a programming
concept that works on the principles of abstraction,
encapsulation, inheritance, and polymorphism. ... The basic
concept of OOPs is to create objects, re-use them throughout
the program, and manipulate these objects to get results.

706) inheritance supported by java


On the basis of class, there can be three types of inheritance in
java: single, multilevel and hierarchical. In java programming,
multiple and hybrid inheritance is supported through interface
only.

702) rest API


A REST API (also known as RESTful API) is an application
programming interface (API or web API) that conforms to the
constraints of REST architectural style and allows for
interaction with RESTful web services. REST stands for
representational state transfer

803) exception handler


The Exception Handling in Java is one of the powerful mechanism
to handle the runtime errors so that normal flow of the
application can be maintained.

805) oops concepts


Object oriented programming system is a programming concept
works on the principles of abstraction encapsulation, inheritance
and polymorphism. The basic concept of oops is to create objects
reuse them lo throughout the program and manipulate these
objects to get results.

906) what is MVC driven and why we use it


Stands for "Model-View-Controller." MVC is an application design
model comprised of three interconnected parts. ... The MVC
model or "pattern" is commonly used for developing modern user
interfaces. It is provides the fundamental pieces for designinguu
a programs for desktop or mobile, as well as web applications.

806) what is autowired why and where we require it

The @Autowired annotation can be used to autowire bean on the


setter method just like @Required annotation, constructor, a
property or methods with arbitrary names and/or multiple
arguments.

You might also like