J2EE Key Notes
J2EE stands for Java 2 Platform Enterprise Edition. It is an open and standards-based platform for development, deployment, and management of multi-tier, web-enabled, component-based and server-centric enterprise applications.
Components of J2EE applications
- Client-tier: Run-on the client machine.
- Web tier components: Run-on the J2EE server.
- Business tier: Run-on the J2EE server.
- Enterprise Information System software (EIS software): Runs on the EIS server.
Java Servlets and Java server pages technology components identified as web components. Servlets dynamically receive requests and make responses. JSP server pages also behave as Java Servlets but facilitate to create more static content.
J2EE client types
- Applets
- Application clients
- Java Web Start enabled clients, by Java Web Start technology.
- Wireless clients, based on the Mobile Information Device Profile (MIDP) technology.
J2EE container
The interface between a component and the low-level platform with specific functionality that supports the component is called a container. The application server maintains control and provides relevant services through an interface or framework calls as a container.
Object-Relational mapping (ORM)
The mapped objects in a Java class to the tables of the relational database using metadata describes the database and object mapping. The working method is to transform data from one representation to another.
Advantages of ORM
- Productivity: Reduced time for data access coding with the help of automatic code creation base on the defined data model.
- Maintainability: All code generated from ORM are well tested. Only the developer is required to create the correct functionality
- Performance: The code generated from ORM completely manages the data access needs of the application. No need to create any data access code. Also, the code is optimized to speed up the data access process.
- Vendor independence: The code generated from ORM does not depend on the vendor. This is to increase the portability of the application.
Hibernate
Hibernate is an open-source object-relational mapping and query service which facilitates writing Hibernate Query Language (HQL) scripts instead of Structured Query Language (SQL) scripts. It is a fast and easy process than writing native SQL. Hibernate has more powerful object-oriented contents like associations, inheritance, and polymorphism. Also, it has powerful compositions and collections.
limitation of hibernate
- Slow: execution of HQL queries is slower.
- Only composite key support is available and it prevents advanced query options.
- No shared value type references are available.
advantages of hibernate
- Database and vendor independence application.
- Standard Object-relational mapping support.
- Domain object mapping for a relational database.
- Better performance than Java Database Connectivity.
- Java Persistence API based applications.
Hibernate Methods
- save() stores an object into the database. There is a check for duplicate records
- saveorupdate() used to update an object using the identifier. if the identifier is NULL a new record will be created.
- load() vs get(): When the object is not available in either cache or database, the load() method throws an exception but get() returns null.
Collection types in Hibernate
One-to-many reference is defined as a collection. There are five main collection types associated with J2EE. They are: Set type, List type, Array type, Map type, Bag type
Spring
Spring is an open-source application that reduces the complexity of enterprise application development. Spring is based on an inversion of control or dependency injection design patterns.
advantages:
- Plain Old Java Object (POJO) based development facilitates to re-use existing components.
- reduce development cost
- Improve the testability with dependency injection.
- Improve maintainability with reduced code coupling.
- No need to have an application server and works on enterprise service.
- Easy initialization for properties.
- Easily testable components.
- Lightweight container.
- Possibilities to use configuration management service of spring in any runtime environment with whatever architectural layer.
- Possibility to organize middle-tier objects in an efficient way
Servlets
servlets are Server-side component that provides a powerful mechanism to create platform-independent programs support various protocols like HTTP.
lifecycle:
- Classloading: Web container loads the servlet class file (*.class).
- Instantiation: Instantiate By calling default no-arg constructor,
- Initialize: Init () called and configuration is assigned to the servlet.
- Request Handling: Servlet provides the services by calling Service ().
- Removal phase: The destroy () function is called before servlet destruction. Garbage collection occurs later.
Enterprise Java Beans (EJB)
is the server-side component that executes in EJB container and encapsulates the business logic for the enterprise application.
EJB Container provides
- Persistence
- Security
- Transaction
- Connection pooling
- Component lifecycle management
- Threading
EJB Design principle
- The behavior is specified by interfaces.
- loosely coupled and tired.
- Implementation is hidden from the client-side.
- The EJB container supports the application developer.
- The API to the application is in session tier.
- The API to the data sources is in the entity tier.
Advantages:
- Support for the integration of components from different vendors.
- Possibility to authorize the EJB component’s detailed knowledge of the environment.
- Possibility to assemble applications from separate component sources.
- Interaction with its clients is entirely specified in terms of Java interfaces.
- Portability support.
- It does not maintain resources.
EJB types:
- Session Beans: Stateful session beans, Stateless session beans
- Entity Beans: Bean Managed Persistence (BMP), Container-Managed Persistence (CMP),Message Driven Beans
JSP
Types of tags associated with JSP
- Directives
- Declarations
- Scriptlets
- Expressions
expression elements are expressions used for writing dynamic content back to the client browser.
JSP directive is the mechanism to provide metadata information to web containers about the JSP file. In the translation and compilation phases of the JSP life cycle, this Metadata is used by the web container.
types of JSP directive are Page, Include and Taglib
MVC
MVC stands for Model View Controller.
- Model: represents the internal state of the system as a set of Java Beans.
- View: Most often the view is constructed using Java Server Pages (JSP) technology.
- Controller: The controller is the process that focuses on receiving client requests and produce the next level of a user interface according to the request.
JSF
JSF stands for Java Server Faces. It is the user interface (UI) designing framework for Java Web application developments based on MVC. There is a set of reusable UI components associated with JSF. The automated data saving process from form to server and display at the client side is also handled by JSF.
Connection Pooling
Is a mechanism to re-use the existing connections. It maintains a number of already created object connections and when there is a demand, existing connection are used.
Thin client
A program interface that does not have any operations like database queries, complex business rules or any connection to the third-party application is called a thin client.
file types ear, jar war?
- *.jar files — containing libraries, resources, and accessories
- *.war files — The files that are required for the development of web application (HTML, java scripts, JSP)
- *.ear files — The files for Enterprise Java Beans modules for the application
Secure Socket Layer (SSL)
establishes an encrypted link between web server and the web browser to allow secure transmission of sensitive information such as login credentials, credit/debit card information and social security numbers.
Java beans
Action form: A Java bean that is associated with single or multiple action mapping is called an action form. Action form objects are automatically populated at the server end when data has been entered from the client side through a user interface (UI).Session states of a web application are maintained by action forms.
https://www.softwaretestinghelp.com/j2ee-interview-questions-answers/