Friday, March 16, 2007

What is bean ?

A reusable software component that conforms to certain design and naming conventions. The conventions enable beans to be easily combined to create an application using tools that understand the conventions.


SOURCE : www.referjava.com

What is ArrayList?

A growable array. It gives you fast iteration and fast random access. It is an ordered collection but not sorted.


SOURCE : www.referjava.com

What is Assertion ?

Assertions give you a way to test your assumptions during development and debugging. They are enabled during testing but disabled during deployment. The keywords assert is used as of version1.4


SOURCE : www.referjava.com

What is array?

Arrays are objects in Java that store multiple variables of the same type. They can hold primitive types or object references. Arrays are objects on the heap.
or
A collection of data items, all of the same type, in which each item's position is uniquely designated by an integer.


SOURCE : www.referjava.com

What is argument?

A data item specified in a method call. An argument can be a literal value, a variable, or an expression.


SOURCE : www.referjava.com

What is Applet?

A component that typically executes in a Web browser, but can execute in a variety of other applications or devices that support the applet programming model.


SOURCE : www.referjava.com

What is Application Programming Interface (API)

Application Programming Interface. The specification of how a programmer writing an application accesses the behavior and state of classes and objects.


SOURCE : www.referjava.com

Saturday, March 10, 2007

What are the services provided by the container?

i. Manages execution and life cycle of EJBs.
ii. May provide transaction services.
iii.Shields clients from lower level network management.
iv. May provide persistent storage.


SOURCE : www.referjava.com

What is scalable, portability in J2EE?

i. Scalable in the sense could handle number of clients at the same time.



ii. Portable - platform independent, app server independent, data store independent.


SOURCE : www.referjava.com

When to use container managed and bean managed persistence?

Container managed persistance is used when the persistant datastore is a

relational database and there is one to one mapping between a data represented in a table in the relational database and the ejb object. Bean managed persistance in used when there is no one to one mapping of the table and a complex query reteriving data from several tables needs to be performed to construct an ejb object. Bean managed is also used when the

persistence datastorage is not a relational database.



SOURCE : www.referjava.com

How is entity bean created using Container managed entity bean ?

In both container managed and bean managed when the client calls create the call is passed on to ejbCreate.



In a container managed bean ejbCreate method will initialize all instance variables based ont he input arguments passed in. Once ejbCreate method completesthe container will automatically persist the bean. ejbCreate would return null.This is because: it is not practially possible to generate a primary key in ejbCreate and it would be impossible to get hold of the primary key for a row in a table even before the row exists as storage happens only after

ejbCreatecall completes.



In a bean managed persistance the ejbCreate will perform the fallowing:

i. Create an entry in the database

ii. Initialize the instance variables

iii. Return the primary key.



SOURCE : www.referjava.com

What are the methods of Entity Bean?

setEntityState

create

ejbCreate

ejbPostCreate

ejbActivate

ejbPassivate

remove

ejbRemove

unsetEntityState


SOURCE : www.referjava.com

Why does EJB needs two interface (Home and Remote Interface) ?

To handle the network tranport layer. TODO I do not have much knowledge to explain further.


SOURCE : www.referjava.com

When to use session, entity and message driven beans?

Session beans are used to represent a business procedure and no persistance

Is required. Session bean represents a client in the server. Entity beans represent a business logic compared procedure. Entity beans are typically shared between several session beans and persist beyond the scope of the application.



Message driven beans are new in j2ee 2.0 and are asynchronous beans typically

used to inteact with legacy batch processing systems.


SOURCE : www.referjava.com

Monday, March 5, 2007

What is component mapping in hibernate?

Lazy setting decides whether to load child objects while loading the Parent Object.You need to do this setting respective hibernate mapping file of the parent class.Lazy = true (means not to load child)By default the lazy loading of the child objects is true. This make sure that the child objects are not loaded unless they are explicitly invoked in the application by calling getChild() method on parent.In this case hibernate issues a fresh database call to load the child when getChild() is actully called on the Parent object.But in some cases you do need to load the child objects when parent is loaded. Just make the lazy=false and hibernate will load the child when parent is loaded from the database.Exampleslazy=true (default)Address child of User class can be made lazy if it is not required frequently.lazy=falseBut you may need to load the Author object for Book parent whenever you deal with the book for online bookshop.

SOURCE : www.referjava.com

Why do you need ORM tools like hibernate?

To overcome the "paradigm mismatch" between object oriented data and table oriented relational databases.

SOURCE : www.referjava.com

What is the difference between sorted and orderd collection in hibernate?

A sorted collection is sorted in-memory using java comparator, while order collection is ordered at the database level using order by clause.

SOURCE : www.referjava.com

What is the main advantage of using the hibernate than using the sql?

Main advantage is that it avoids writing queries. Ofcourse, u have to write to some extent but a lot is relaxed.Most of the work is taken care by mapping.Also criteria class is very useful for complex joins.

Using ORM we can avoid the jdbc API completely and also provides ease to the developer in developing the classes.


SOURCE : www.referjava.com

How to create primary key using hibernate?

id field in hbm.xml file is used to specify the primary key in database. We also use generator to specify the way primary key is generated to the database. For example

< id name="testId" type="string" >
< column name="testColumn" length="40" / >
< generator class="increment" / >
< /id >

here the primary key field name in database is testColumn and it will autonmatically incremented by one as the generator is specified as increment.


SOURCE : www.referjava.com

What is the advantage of Hibernate over jdbc?

Hibernate is used to persist the objects in the database, but we have to use the jdbc to connect to database. JDBC is used to store the primitivies in the database.
Hibernate is basically a ORM tool which allows you to perform database activies without bothering about the Database change.

You dont need to change the SQL scripts if you change database.

Apart from that you dont need to write most of the SQL scripts for persisting ,deleting object and parsing the resultsets.With respect to perfomance, hibernate provide the capability to reduce the number of database trips by creating the betch processing and session cache and second level cache.

It also supports the transactions.
More then this all, it is very easy to make a cleaner seperation of Data Access Layer from usiness logic layer.
With all the capabilities mention above it is fast and easy to learn hibernate, develop application and maintain easily.


SOURCE : www.referjava.com

What is the difference between Hibernate and EJB 2.1?

Hibernate is a ORM(object relation mapping ) tool which can be used for creating a mapping between plain java bean objects (POJO) and a persitent storage (rdbms).The EJB 3.0 specification is divided into two parts The first which deals with session and MDBs and the second which deals with persistence and entity beans. The latter part is called JPA(java persistance API ). Hibernate 3.0 implements the JPA specification.EJB 2.1 is a specification for defining loosely coupled reusable business componenets.

EJB 2.1 and hibernate serve two different purposes. Hibernate can be co related with the entity beans in EJB 2.1.HIbernate offers far more extensive features then plain entity beans.still there are no containers (applicaiton servers) available which fully implement the EJB 3.0 specification. depending upon the buisness needs hibernate framework can be used in conjuction with EJB2.1 to achieve the JPA abstraction.

SOURCE : www.referjava.com

What is the difference between beans and hibernate?

Beans are at form level and hibernate at data base level.

Hibernate adapts beans.Its plain old Java objects. POJO. Hibernate always has a bean orientation.But the Bean is just not persistent, using hibernate you can make a bean persistent.A bean when used in Hibernate It can create a table ,Add a row,Delete a rowUpdate row.THis is all done with Hib Configuration stuff.Hibernate is ORM as it can relate a bean to a row in a table


SOURCE : www.referjava.com

Thursday, March 1, 2007

Why can't I say just abs() or sin() instead of Math.abs() and Math.sin()?

The import statement does not bring methods into your local name space. It lets you abbreviate class names, but not get rid of them altogether. That's just the way it works, you'll get used to it. It's really a lot safer this way.
However, there is actually a little trick you can use in some cases that gets you what you want. If your top-level class doesn't need to inherit from anything else, make it inherit from java.lang.Math. That *does* bring all the methods into your local name space. But you can't use this trick in an applet, because you have to inherit from java.awt.Applet. And actually, you can't use it on java.lang.Math at all, because Math is a "final" class which means it can't be extended.


SOURCE : www.referjava.com

What is the difference between instanceof and isInstance?

instanceof is used to check to see if an object can be cast into a specified type without throwing a cast class exception.

isInstance()

Determines if the specified Object is assignment-compatible with the object represented by this Class. This method is the dynamic equivalent of the Java language instanceof operator. The method returns true if the specified Object argument is non-null and can be cast to the reference type represented by this Class object without raising a ClassCastException. It returns false otherwise.


SOURCE : www.referjava.com

Describe what happens when an object is created in Java?

Several things happen in a particular order to ensure the object is constructed properly:

1. Memory is allocated from heap to hold all instance variables and implementation-specific data of the object and its superclasses. Implemenation-specific data includes pointers to class and method data.

2. The instance variables of the objects are initialized to their default values.

3. The constructor for the most derived class is invoked. The first thing a constructor does is call the consctructor for its superclasses. This process continues until the constrcutor for java.lang.Object is called, as java.lang.Object is the base class for all objects in java.

4. Before the body of the constructor is executed, all instance variable initializers and initialization blocks are executed. Then the body of the constructor is executed. Thus, the constructor for the base class completes first and constructor for the most derived class completes last.


SOURCE : www.referjava.com

How many static init can you have ?

As many as you want, but the static initializers and class variable initializers are executed in textual order and may not refer to class variables declared in the class whose declarations appear textually after the use, even though these class variables are in scope.


SOURCE : www.referjava.com

How to Retrieve Warnings?

SQLWarning objects are a subclass of SQLException that deal with database access warnings. Warnings do not stop the execution of an application, as exceptions do; they simply alert the user that something did not happen as planned. A warning can be reported on a Connection object, a Statement object (including PreparedStatement and CallableStatement objects), or a ResultSet object. Each of these classes has a getWarnings method, which you must invoke in order to see the first warning reported on the calling object

E.g.

SQLWarning warning = stmt.getWarnings();

if (warning != null) {

while (warning != null) {

System.out.println("Message: " + warning.getMessage());

System.out.println("SQLState: " + warning.getSQLState());

System.out.print("Vendor error code: ");

System.out.println(warning.getErrorCode());

warning = warning.getNextWarning();

}

}



SOURCE : www.referjava.com

What Class.forName will do while loading drivers?

It is used to create an instance of a driver and register it with the DriverManager. When you have loaded a driver, it is available for making a connection with a DBMS.


SOURCE : www.referjava.com

What information is needed to create a TCP Socket?

The Local System's IP Address and Port Number. And the Remote System's IPAddress and Port Number.


SOURCE : www.referjava.com

What is a task's priority and how is it used in scheduling?

A task's priority is an integer value that identifies the relative order in which it should be executed with respect to other tasks. The scheduler attempts to schedule higher priority tasks before lower priority tasks.


SOURCE : www.referjava.com