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

vivanotes

Uploaded by

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

vivanotes

Uploaded by

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

Scenario--explain

What was the requirement in scenario


Explain the scenario Annotations for validation on no. Of tickets
Case Study - your experience

Interface
Front controller--A front controller is defined as a controller that handles all requests for a Web Application.
DispatcherServlet servlet is the front controller in Spring MVC that intercepts every request and then
dispatches requests to an appropriate controller.

Configuration--@Configuration annotation indicates that a class declares one or more @Bean methods and
may be processed by the Spring container to generate bean definitions and service requests for those
beans at runtime

******Mvc flow--prefer video**********

******What are the steps in implementing spring mvc with jpa--Video(Naveen reddy)******

Difference between post and put--PUT is meant as a a method for "uploading" stuff to a particular URI, or
overwriting what is already in that URI. POST, on the other hand, is a way of submitting data RELATED to a
given URI.

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. There are a number of other methods, too, but they are utilized less frequently

Advantages of JPA--that in JPA data is represented by classes and objects rather than by tables and
records as in JDBC

Spring JPA data--


Java Persistence API (JPA) is a specification provided by Java for APIs accessing various SQL databases.
... Spring Data JPA is a sub-project of Spring Data and provides abstraction over the Data Access Layer
using Java Persistence API and ORM implementations like Hibernate.

JSP in detail.---prefer video

Life cycle of entity and servlet--


Servlet class is loaded.
Servlet instance is created.
init method is invoked.
service method is invoked.
destroy method is invoked.

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 and has no representation in the database.
An entity object becomes Managed when it is persisted to the database via an EntityManager’s persist
method
A managed entity object can also be retrieved from the database and marked for deletion, using the
EntityManager’s remove method within an active transaction.
The last state, Detached, represents entity objects that have been disconnected from the EntityManager.
For instance, all the managed objects of an EntityManager become detached when the EntityManager is
closed.

Diff btw interface and abstract class---Abstract class


Interface
1) Abstract class can have abstract and non-abstract methods. Interface can have only abstract
methods. Since Java 8, it can
have
default and static methods also.
2) Abstract class doesn't support multiple inheritance. Interface supports multiple
inheritance.
3) Abstract class can have final, non-final, static and non-static variables. Interface has only static and
final variables.
4) Abstract class can provide the implementation of interface. Interface can't provide the
implementation of abstract class.
5) The abstract keyword is used to declare abstract class. The interface keyword is used
to declare interface.

Spring data jpa annotations----@Transactional,@NoRepositoryBean,@Param,@Id,@Transient,@Query,@


Procedure,@EnableJpaRepositories,@Modifying,@Lock
jdbc and orm ---->>>>>
ORM responsible for establishing connections with the database, unlike JDBC. It uses Query Language to
communicate with the database and execute the queries.
After, ORM maps itself the results to corresponding Java objects.

maven ---->>>>>
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.

Jpql vs SQL--->>>
The main difference between SQL and JPQL is that SQL works with relational database tables, records and
fields, whereas JPQL works with Java classes and objects.
For example, a JPQL query can retrieve and return entity objects rather than just field values from database
tables, as with SQL.

Spring security--->>>>
Spring Security is the primary choice for implementing application-level security in Spring applications.
Generally, its purpose is to offer you a highly customizable way of implementing authentication,
authorization, and protection against common attacks.

Autowired, dependency injection, how to achieve dependency injection


Dependency Injection is a design pattern, and @autowired is a mechanism for implementing it.
The Spring-Core module is responsible for injecting dependencies through either Constructor or Setter
methods.
The design principle of Inversion of Control emphasizes keeping the Java classes independent of each
other and the container frees them from object creation and maintenance.

Ioc---->>>>
Spring IoC Container is the core of Spring Framework. It creates the objects, configures and assembles
their dependencies, manages their entire life cycle.
The Container uses Dependency Injection(DI) to manage the components that make up the application. ...
These objects are called Beans.

Crud repositories vs jpa repository--->>>>


Their main functions are: CrudRepository mainly provides CRUD functions. PagingAndSortingRepository
provides methods to do pagination and sorting records.
JpaRepository provides some JPA-related methods such as flushing the persistence context and deleting
records in a batch.

What is dispatchservelet?--->>>
The job of the DispatcherServlet is to take an incoming URI and find the right combination of handlers
(generally methods on Controller classes) and
views (generally JSPs) that combine to form the page or resource that's supposed to be found at that
location.
What is Junit?----->>>>
JUnit is an open source framework designed for the purpose of writing and running tests in the Java
programming language. ...
JUnit allows the developer to incrementally build test suites to measure progress and detect unintended
side effects. Tests can be run continuously.
Results are provided immediately.

What are the configuration is java?--->>>>


Spring JavaConfig is a product of the Spring community that provides a pure-Java approach to configuring
the Spring IoC Container.
While JavaConfig aims to be a feature-complete option for configuration, it can be (and often is) used in
conjunction with the more well-known
XML-based configuration approach.

What is final keyword?----The final keyword in java is used to restrict the user.If you make any variable as
final, you cannot change the value of final variable,If you make any method as final, you cannot override it,If
you make any class as final, you cannot extend it,
Is final method inherited?
Ans) Yes, final method is inherited but you cannot override it.

Which annotation is used for autopopulating?


you want your beans auto-detected and then to collect them automatically.
So annotate your B, C, D classes with @Component -like annotations (e.g. @Component, @Service,
@Repository, @Controller etc.), and then use @ComponentScan to detect them. (@Bean is used for other
purposes, you didn't use it properly in your example).
Then you collect all beans of type A with @Autowired annotation:

Collection---The Collection in Java is a framework that provides an architecture to store and manipulate the
group of objects.

Differences between arraylist and vector.---ArrayList


Vector
1) ArrayList is not synchronized.
Vector is synchronized.
2) ArrayList increments 50% of current array size if the number of elements exceeds from its capacity.
Vector increments 100% means
doubles the array size if the total number of
elements exceeds than
its capacity.
3) ArrayList is not a legacy class. It is introduced in JDK 1.2.
Vector is a legacy class.
4) ArrayList is fast because it is non-synchronized. Vector is
slow because it is synchronized, i.e.,
in a multithreading environment, it holds
the
other threads in runnable or non-runnable state until
current thread releases the lock of the object.
5) ArrayList uses the Iterator interface to traverse the elements. A
Vector can use the Iterator interface or
Enumeration
entitymanager---- The EntityManager API is used to create and remove persistent entity instances, to find
entities by their primary key, and to query over entities.

pathvariable.....---the @PathVariable annotation can be used to handle template variables in the request
URI mapping

jpa directives...----JSP directives are the elements of a JSP source code that guide the web container on
how to translate the JSP page into it’s respective servlet.
Page directive
Include directive
Taglib directive

implicit objects-----These Objects are the Java objects that the JSP Container makes available to the
developers in each page and the developer can call them directly without being explicitly declared. ... JSP
Implicit Objects are also called pre-defined variables

Autowired--Autowiring feature of spring framework enables you to inject the object dependency implicitly. It
internally uses setter or constructor injection.
Autowiring can't be used to inject primitive and string values. It works with reference only

Controller and autocontroller---Controllers interpret user input and transform it into a model that is
represented to the user by the view. Spring implements a controller in a very abstract way, which enables
you to create a wide variety of controllers.

View resolver----Spring provides view resolvers, which enable you to render models in a browser without
tying you to a specific view technology

Functional interface---A functional interface is an interface that contains only one abstract method. They
can have only one functionality to exhibit. A functional interface can have any number of default methods.
Runnable, ActionListener, Comparable are some of the examples of functional interfaces.

Inheritence---Inheritance is a mechanism of deriving new class from already existing class.(Reusability)

Bean scope---In Spring, bean scope is used to decide which type of bean instance should be returned from
Spring container back to the caller.

5 types of bean scopes are supported


1:- Singleton
2:-Prototype
3:-Request
4:-Session
5:-GlobalSession

Difference between comparable and comparator----


1) Comparable provides a single sorting sequence. In other words, we can sort the collection on the basis
of a single element such as id, name, and price.
The Comparator provides multiple sorting sequences. In other words, we can sort the collection on the
basis of multiple elements such as id, name, and price etc.

2) Comparable affects the original class, i.e., the actual class is modified.
Comparator doesn't affect the original class, i.e., the actual class is not modified.

3) Comparable provides compareTo() method to sort elements.


Comparator provides compare() method to sort elements.

4) Comparable is present in java.lang package.


A Comparator is present in the java.util package.

5) We can sort the list elements of Comparable type by Collections.sort(List) method.


We can sort the list elements of Comparator type by Collections.sort(List, Comparator) method.

Internal view resolver---The InternalResourceViewResolver is an implementation of ViewResolver in Spring


MVC framework which resolves logical view name

JSP directives ---The jsp directives are messages that tells the web container how to translate a JSP page
into the corresponding servlet.
There are three types of directives:
page directive
include directive
taglib directive

Implicit objects---These Objects are the Java objects that the JSP Container makes available to the
developers in each page and the developer can call them directly without being explicitly declared. ... JSP
Implicit Objects are also called pre-defined variables.

Serializable--Serializable is a marker interface your classes must implement if they are to be serialized and
deserialized. Java object serialization (writing) is done with the ObjectOutputStream and deserialization
(reading) is done with the ObjectInputStream.

Question: what is serialisation and how to implement?


Ans: Just by writing implements serializable
Annotations used in entity and bean-->>>>>--annotate the component property as @Id and make the
component class @Embeddable.
annotate the component property as @EmbeddedId.
annotate the class as @IdClass and annotate each property of the entity involved in the primary key with
@Id.

how to validate the min. And max. Tickets in the scenario.. (this was the question in MCQs)

Session tracking and the ways which we can do session tracking.. how to do it in spring MVC..->>>>---
1-Session Tracking is a way to maintain state (data) of an user.
It is also known as session management in servlet. Http protocol is a stateless so we need to maintain state
using session tracking techniques.
Each time user requests to the server, server treats the request as the new request.
2-User Authentication.
HTML Hidden Field.
Cookies.
URL Rewriting.
Session Management API.
3-Using spring security you can implement session tracking and apply filters to validate requests. Spring
security is very easy to implement.

Question: what is serialisation and how to implement? >-----


In Java, we create objects. These objects live in memory and are removed by the garbage collector once
they are not used anymore.
If we want to transfer an object, for instance, store it on a disk or send it over a network, we need to
transform it into a byte stream.
To do this, the class of that object needs to implement the interface Serializable. Serialization is converting
the state of an object into a byte stream.
This byte stream does not contain the actual code.
Ans: Just by writing implements serializable

Which JPA vendor did we use?-----Hibernate

Uses of annotations--->>
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.

Custom exception--->>>>
Custom exceptions provide you the flexibility to add attributes and methods that are not part of a standard
Java exception. These can store additional information,
like an application-specific error code, or provide utility methods that can be used to handle or present the
exception to a user.

Spring boot and everything else that is spring --->>>


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.
What is spring boot is used for?
Spring Boot helps developers create applications that just run. Specifically, it lets you create standalone
applications that run on their own,
without relying on an external web server, by embedding a web server such as Tomcat or Netty into your
app during the initialization process.

Dispatcher and why---->


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.
====DispatcherServlet acts as front controller for Spring based web applications. It provides a mechanism
for request processing where actual work is performed
by configurable, delegate components.

Question regarding component scan ----->>>


Using component scan is one method of asking Spring to detect Spring-managed components. Spring
needs the information to locate and register all the
Spring components with the application context when the application starts. Spring can auto scan, detect,
and instantiate components from pre-defined project packages

Difference between spring jpa and jpa data

Crud repository methods.----->>>>


CrudRepository is a Spring Data interface for generic CRUD operations on a repository of a specific type.
It provides several methods out of the box for interacting with a database.
METHODS--
Wrapper class---->>>>
A Wrapper class is a class whose object wraps or contains primitive data types. When we create an object
to a wrapper class,
it contains a field and in this field, we can store primitive data types. In other words, we can wrap a primitive
value into a wrapper class object.

Multi threading---->>>>Multithreading is a model of program execution that allows for multiple threads to be
created within a process,
executing independently but concurrently sharing process resources. Depending on the hardware,
threads can run fully parallel if they are distributed to their own CPU core

@modelattribute anotation
@SessionaAttribute
@configuration
@componentscan
@controller and @restcontroller
@Atcontroller and @Requestmapping
Spring Rest
Spring security
View resolver
How do u handle Exceptions in spring

You might also like