0% found this document useful (0 votes)
8 views3 pages

Java Frameworks and ORM Overview

The document provides an overview of various Java technologies including Hibernate, Java, JPA, JSP, EJB, Apache Struts, and SQL, along with common interview questions and answers for each. Key features and differences between these technologies are highlighted, such as Hibernate being an ORM framework, JPA as a specification, and JSP for dynamic web pages. It also covers SQL as a language for database management and includes types of JOIN operations.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Java Frameworks and ORM Overview

The document provides an overview of various Java technologies including Hibernate, Java, JPA, JSP, EJB, Apache Struts, and SQL, along with common interview questions and answers for each. Key features and differences between these technologies are highlighted, such as Hibernate being an ORM framework, JPA as a specification, and JSP for dynamic web pages. It also covers SQL as a language for database management and includes types of JOIN operations.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Hibernate

Hibernate is an ORM (Object-Relational Mapping) framework for Java that maps Java objects to
database tables. It reduces boilerplate JDBC code and handles transactions, caching, and query
generation. Key Features: HQL, Criteria API, Caching, Lazy Loading, Annotations for mapping.

Common Interview Q&A;


Q: What is Hibernate?
A: An ORM framework for mapping Java objects to relational database tables.
Q: Difference between Hibernate and JDBC?
A: Hibernate automates mapping and query generation; JDBC requires manual SQL.
Q: What is HQL?
A: Hibernate Query Language, object-oriented query language similar to SQL.
Q: Explain caching in Hibernate.
A: First-level cache (Session), Second-level cache (SessionFactory).

Java
Java is a high-level, object-oriented, platform-independent programming language. Core Concepts:
OOP principles, JVM architecture, collections, exceptions, multithreading.

Common Interview Q&A;


Q: What is JVM?
A: Java Virtual Machine executes Java bytecode.
Q: Difference between JDK, JRE, JVM?
A: JDK includes JRE + development tools, JRE runs Java programs, JVM executes bytecode.
Q: Explain OOP concepts.
A: Encapsulation, Inheritance, Polymorphism, Abstraction.

JPA (Java Persistence API)


JPA is a specification for accessing, persisting, and managing data in Java objects to relational
databases. Hibernate is one implementation of JPA.

Common Interview Q&A;


Q: What is JPA?
A: A Java specification for object-relational mapping.
Q: Difference between JPA and Hibernate?
A: JPA is the specification; Hibernate is an implementation.
Q: What are JPA annotations?
A: @Entity, @Id, @GeneratedValue, @OneToMany, @ManyToOne.

JSP (JavaServer Pages)


JSP is a technology to create dynamic web pages using Java in HTML. It allows embedding Java
code into HTML pages and runs on the server.
Common Interview Q&A;
Q: What is JSP?
A: A server-side technology to create dynamic content.
Q: Difference between JSP and Servlet?
A: Servlets are Java classes; JSPs are HTML with embedded Java code.
Q: What are JSP directives?
A: page, include, taglib.

EJB (Enterprise JavaBeans)


EJB is a server-side software component that encapsulates business logic in enterprise
applications. Types: Session Beans, Message-Driven Beans, Entity Beans (deprecated).

Common Interview Q&A;


Q: What is EJB?
A: A component-based architecture for modular enterprise applications.
Q: Types of Session Beans?
A: Stateless, Stateful, Singleton.
Q: Difference between EJB and Spring?
A: EJB is Java EE spec; Spring is a lightweight framework.

Apache Struts
Apache Struts is an MVC framework for creating Java web applications. It uses Action classes,
XML configuration, and JSP for the view layer.

Common Interview Q&A;


Q: What is Struts?
A: An open-source MVC framework for Java web apps.
Q: Difference between Struts 1 and Struts 2?
A: Struts 2 has improved architecture, uses interceptors, and POJO-based actions.
Q: How does Struts implement MVC?
A: Model: business logic, View: JSP, Controller: ActionServlet.

SQL (Structured Query Language)


SQL is a standard language for managing and manipulating relational databases. Includes DDL,
DML, DCL, and TCL commands.

Common Interview Q&A;


Q: What is SQL?
A: A language to store, retrieve, and manipulate data in databases.
Q: Difference between SQL and MySQL?
A: SQL is a language; MySQL is a database system implementing SQL.
Q: What is a JOIN?
A: A way to combine rows from two or more tables.
Q: Types of JOIN?
A: INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN.

Common questions

Powered by AI

Annotations in JPA play a crucial role in defining the metadata for ORM operations, making the mapping between Java data model entities and relational database tables more declarative. Key annotations include @Entity, which specifies a class as a JPA entity; @Id, marking the primary key; @GeneratedValue, indicating how the key should be generated; and @OneToMany, @ManyToOne, which define entity relationships. These annotations reduce the need for XML configuration files, making the ORM setup in frameworks like Hibernate more intuitive and aligned with modern Java programming practices .

JSP (JavaServer Pages) complements Servlets in Java web applications by allowing developers to write HTML code combined with Java logic directly into web pages, making the development of dynamic content seamless. JSP addresses some of the limitations of Servlets by separating Java code from HTML, promoting a more MVC architecture-friendly design. It offers built-in tags for easier management of Java components and supports custom tags and expression language, which simplifies complex expressions and scripts, making it a preferable choice for rapid web development compared to the rigid coding structure of traditional servlets .

Using JPA as a persistence framework offers several advantages over direct database access techniques. JPA abstracts the database layer, allowing developers to use Java objects through a standardized API, simplifying code maintenance and portability. It supports complex queries, transactions management, and entity relationships with a reduced level of SQL knowledge. However, JPA can introduce additional overhead due to its abstraction layer, and performance might not match hand-tuned SQL queries. Furthermore, JPA requires configuration and a learning curve, which might be unnecessary for projects with simple database interaction needs, where direct database access methods may suffice for efficiency and simplicity .

The core concepts of Java, particularly its OOP principles and JVM architecture, facilitate its use in enterprise applications by promoting code reusability, scalability, and robustness. OOP principles such as Encapsulation protect data integrity by hiding implementation details; Inheritance allows the creation of new classes based on existing ones, promoting reusability; Polymorphism enables flexibility by allowing objects to be processed differently based on their data type or class; and Abstraction simplifies complex systems by modeling them with simple interfaces. Furthermore, the JVM architecture ensures platform independence, allowing Java applications to run consistently across different environments, which is crucial for large-scale enterprise systems requiring reliability and scalability .

Enterprise JavaBeans (EJB) contribute to scalable enterprise application development by providing robust support for distributed, transactional, and portable business logic components within Java EE applications. EJB facilitates automatic support for transactions, security, and remote procedure calls. Comparatively, the Spring framework, being more lightweight and flexible, allows for easier configuration and integration of various technologies and is often preferred for building non-distributed applications needing rapid development and simpler solutions. EJB requires a Java EE compliant server, whereas Spring can use any servlet container, making it more versatile for different scopes of applications .

SQL's JOIN operations are pivotal for combining data across multiple tables, which can greatly enhance the richness and relevance of data retrieved in queries. Joins like INNER, LEFT, RIGHT, and FULL JOIN allow developers to specify how data from different tables should be combined based on a related column. The use of JOIN operations can complicate query formulation, increase processing costs, and require careful indexing to avoid performance degradation. Improper indexing or use of complex joins on large datasets can increase query execution time and resource utilization, necessitating optimization strategies and careful schema design for efficient query handling .

The key differences between Hibernate and JDBC lie in their approach to database interaction and query handling. Hibernate automates the mapping between Java objects and database tables, handling the SQL query generation internally through methods such as HQL (Hibernate Query Language), thus reducing boilerplate code. In contrast, JDBC requires explicit manual handling of SQL queries and result sets, demanding more code for operations such as mapping results to objects and transaction handling. Hibernate also provides features like caching and lazy loading, which are not inherent in JDBC, to improve performance and scalability .

Struts 2 introduced significant improvements over Struts 1, primarily in its architecture and feature set. Struts 2 was rebuilt from the ground up, embracing the principles of CoC (Convention over Configuration) and using POJO-based actions, making it more flexible and less cumbersome. It incorporates interceptors, which allow for easier request handling and pre- and post-processing logic, unlike Struts 1, which relies heavily on the ActionServlet. Struts 2 also provides improved integration with modern technologies and better error control through its tag-based templates, unlike the more rigid and verbose configuration required in Struts 1 .

Lazy Loading in Hibernate is beneficial in scenarios where large data sets are retrieved but only a subset of the data is needed immediately, reducing the initial load time and memory consumption. It helps improve performance by fetching associated data only when it's required in the application, rather than at the initial query time. However, misuse or misunderstanding of Lazy Loading can lead to LazyInitializationException if an entity's lazy-loaded attribute is accessed outside the scope of a session. It can also result in N+1 select problems, where accessing a collection of entities triggers additional individual queries, degrading performance if not handled correctly with proper fetching strategies .

Hibernate's caching mechanism improves application performance by reducing the number of database hits, thus decreasing latency and increasing throughput. It achieves this through two levels of caching: the first-level cache associated with the Session object, and the second-level cache associated with the SessionFactory. The first-level cache is mandatory and is available as long as the session is open, storing objects within the same transaction context. The second-level cache, which is optional and configurable using third-party providers like Ehcache, Hazelcast, and Infinispan, stores objects across sessions, allowing them to be shared and reused, which further reduces redundant database access .

You might also like