Você está na página 1de 6

J2EE Interview Questions and Answers

TOP 20
by Yasser R Shaikh | Jan 6, 2014 | Interview Questions & Answers | 0 comments

You are here:


Interview Q & A >> J2EE >> J2EE Interview Questions and
Answers TOP 20
1. What is J2EE ?

J2EE means Java 2 Enterprise Edition. The functionality of J2EE is


developing multitier web-based applications .The J2EE platform is
consists of a set of services, application programming interfaces
(APIs), and protocols.
2. What are the four components of J2EE application ?

Application clients components.

Servlet and JSP technology are web components.

Business components (JavaBeans).

Resource adapter components


3. What are types of J2EE clients ?

Applets

Application clients

Java Web Start-enabled clients, by Java Web Start technology.

Wireless clients, based on MIDP technology.


4. What are considered as a web component ?

Java Servlet and Java Server Pages technology components are


web components. Servlets are Java programming language that
dynamically receive requests and make responses. JSP pages
execute as servlets but allow a more natural approach to creating
static content.
5. What is JSF ?

JavaServer Faces (JSF) is a user interface (UI) designing


framework for Java web applications. JSF provide a set of reusable
UI components, standard for web applications.JSF is based on MVC
design pattern. It automatically saves the form data to server and
populates the form date when display at client side.
6. Defi ne Hash table ?

HashTable is just like Hash Map or Collection having unique key


value pairs. Hashtable is a collection of Synchronized object. It does
not allow duplicate values but it allows null values.
7. What is Hibernate ?

Hibernate is a open source object-relational mapping and query


service. In hibernate we can write HQL instead of SQL which save
developers to spend more time on writing the native SQL. Hibernate
has more powerful association, inheritance, polymorphism,
composition, and collections. It is a beautiful approach for persisting
into database using the java objects. Hibernate also allows you to
express queries using java-based criteria.
8. What is the limitation of Hibernate ?

Slower in executing the queries than queries are used directly.

Only query language support for composite keys.

No shared references to value types.


9. What are the advantage of Hibernate ?

Hibernate is portable (database and vendor independent).

Standard ORM also supports JPA

Mapping of Domain object to relational database.

Hibernate is better then plain JDBC.

JPA provider in JPA based applications.


10. What is ORM?

ORM stands for Object-Relational mapping. The objects in a Java


class which is mapped in to the tables of a relational database using

the metadata that describes the mapping between the objects and
the database. It works by transforming the data from one
representation to another.
11. What is the diff erence between save() and saveorupdate() in
Hibernate ?

save() : Persists an entity. Will assign an identifier if one


doesnt exist. If one does, its essentially doing an update. Returns
the generated ID of the entity

saveOrUpdate() : Calls either save or update depending on


some checks. E.g. if no identifier exists, save is called. Otherwise
update is called.

update : Attempts to persist the entity using an existing


identifier. If no identifier exists, I believe an exception is thrown.

saveOrUpdateCopy : This is deprecated and should no longer


be used. Instead there is merge which can be used.

merge : Now this is where my knowledge starts to falter. The


important thing here is the difference between transient, detached
and persistant entities. For more info on the object states, [take a
look here][2]. With save & update, you are dealing with persistant
objects. They are linked to a Session so Hibernate knows what has
changed. But when you have a transient object, there is no session
involved. In these cases you need to use merge for updates and
persist for saviing.

persist As mentioned above, this is used on transient objects.


It does not return the generated ID.
12. Diff erence between get and load in Hibernate

The get() methods always hit the database. Meaning, as soon as


the call to get() occurs, Hibernate issues an SQL statement to the
database in an attempt to fetch the associated data (usually a row in
the database) to rebuild the requested persistent object.

A call to load(), on the other hand, does not immediately incur a


call to the database. The load()method causes a proxy object to
be constructed as a stand-in for the persistent object. It is only after
some state is requested from the proxy that Hibernate issues the
appropriate SQL to the database and builds the real persistent
object.
When using get(), the method will return null if no data exists for
the requested identifier. Since theload() method does not
immediately retrieve the object, if no data exists for the identifier
used to retrieve the object, an ObjectNotFoundException is
thrown once data is requested of the proxy.
13. How to call stored procedure in Hibernate ?

Supposing you have the following Oracle Stored procedure:


CREATE FUNCTION agenda RETURN SYS_REFCURSOR
AS
my_cursor SYS_REFCURSOR;
BEGIN
OPEN my_cursor FOR
SELECT
id,person_name,person_surname,person_address
FROM Person;
RETURN

my_cursor;

END;
Invoking it from Hibernate requires mapping the Stored Procedure in
the Person class.
<sql-query name="SP_agenda" callable="true">
<return alias="ev" class="Person">
<return-property name="id" column="id"/>

<return-property name="name"
column="person_name"/>
<return-property name="surname"
column="person_surname"/>
<return-property name="address"
column="person_address"/>
</return>
{ ? = call agenda() }
</sql-query>
Then, you can execute the procedure just like a normal Query:
Query query = session.getNamedQuery("SP_agenda");
List results = query.list();
14. What are the benefi ts of using a ORM?

More Productive

Easily Maintenance

Better Performance

Vendor Independent
15. What are the Core Interfaces of Hibernate Framework ?

Session Interface

SessionFactory Interface

Configuration Interface

Transaction Interface

Query and Criteria Interface


16. What is the fi le extension for a Hibernate Mapping fi le ?

<classname>.hbm.xml
17. What is the fi le name of Hibernate Confi guration fi le?

hibernate.cfg.xml
18. Hibernate is Database Independent. Explain how ?

By only changing the below 2 property full database can be


replaced.
<property
name="hibernate.dialect">org.hibernate.dialect.Ora
cle9Dialect</property>
<property
name="hibernate.connection.driver_class">oracle.jd
bc.driver.OracleDriver</property>
19. How can you add Hibernate Mapping fi le in Hibernate
Confi guration fi le?

By using adding this <mapping


resource="filename.hbm.xml"/>
20. Defi ne Connection Pooling ?

Opening database connection is a time consuming operation.


Connection pooling increases the performance of the applications
by reusing the active database connections instead of create new
connection for every request. Connection pooling Behavior is
controlled by the connection string parameters. Following the the 4
parameters that control most of the connection pooling behavior.

Connect Timeout

Max Pool Size

Min Pool Size

Pooling

Você também pode gostar