HashMap: It is unordered, unsorted map. HashMap allows one 'null' values in a collection.
Hashtable: It is same as HashMap but it does not allow null either in keys and values.
LinkedHashMap: It takes insertion order. It is slower than HashMap for adding,deleting but faster iteration
TreeMap: It is a SortedMap. Like TreeSet, TreeMap can define a custom Sort using Comparator or Comparator
Here we are providing interview questions which are related to java / j2ee. Give your comments and make it helpful to all.For JAVA videos visit http://www.sharmanj.com/allvideos.html
Wednesday, June 30, 2010
Tuesday, June 29, 2010
Describe HashSet, LinkedHashSet, TreeSet ?
HashSet: This is unordered, unsorted set. When we dont want to care about the order and no duplicate it is better to use.
LinkedHashSet: It is unorder version of HashSet. It maintains doubly linkedlist across all elements. It is better to use than HashSet, because HashSet order is unpredictable.
-> This elements is stored in which they are inserted.
->When using HashSet and LinkedHashSet the objects you add to them must override hascode() method, if they dont override it allows duplicates.
TreeSet:
->it uses Red-Black tree structure.
->the elements will be in the ascending order according natural order.
-> we can construct a constructor your own rules for what the order should be using a comparable or comparator.
LinkedHashSet: It is unorder version of HashSet. It maintains doubly linkedlist across all elements. It is better to use than HashSet, because HashSet order is unpredictable.
-> This elements is stored in which they are inserted.
->When using HashSet and LinkedHashSet the objects you add to them must override hascode() method, if they dont override it allows duplicates.
TreeSet:
->it uses Red-Black tree structure.
->the elements will be in the ascending order according natural order.
-> we can construct a constructor your own rules for what the order should be using a comparable or comparator.
Describe ArrayList, Vector, LinkedList?
ArrayList:it is ordered but not sorted.it gives fast iteration and fast RandomAccess. it implements RandomAccess interface. choose this over a LinkedList when you need fast iteration. but use not as likely to be doing a lot of insertion,deletion.
Vector:Vector,HashTable were the two original collection in before java2..
->Vector methods are Synchronized for thread safety.
->Vector also implements RandomAccess
->if ArrayList wants to thread safety it can use Collection(class) utility methods.
LinkedList:
->it is ordered by index position
->it is doubly Linked to one another.
->LinkedList is implemented by queue so it now supports peck(),poll(),offer().
Vector:Vector,HashTable were the two original collection in before java2..
->Vector methods are Synchronized for thread safety.
->Vector also implements RandomAccess
->if ArrayList wants to thread safety it can use Collection(class) utility methods.
LinkedList:
->it is ordered by index position
->it is doubly Linked to one another.
->LinkedList is implemented by queue so it now supports peck(),poll(),offer().
About Collection framework ?
In collection framework, The key interface we use are
Collection, Set, SortedSet, List, Map, SortedMap, Queue.
Classes are
Map : HashMap, Hashtable, TreeMap, LinkedHashMap
Set : HashSet, LinkedHashSet, TreeSet
List: ArrayList, Vector, LinkedList.
Queue : PriorityQueue
The Utility classes available are Collections, Arrays
Collection, Set, SortedSet, List, Map, SortedMap, Queue.
Classes are
Map : HashMap, Hashtable, TreeMap, LinkedHashMap
Set : HashSet, LinkedHashSet, TreeSet
List: ArrayList, Vector, LinkedList.
Queue : PriorityQueue
The Utility classes available are Collections, Arrays
Monday, June 28, 2010
About JSP implicit Objects
By default JSP creates some prebuild objects. These are request, response, session, application, page, out, exception, pageContext.
request is a HttpServletRequest Object.
response is a HttpServletResponse Object.
session is a HttpSession Object.
config is a ServletConfig Object.
application is a ServletContext Object.
page is a JspPage Object.
pageContext is a PageContext Object.
out is a JspWriter Object.
exception is a Throwable Object.
request is a HttpServletRequest Object.
response is a HttpServletResponse Object.
session is a HttpSession Object.
config is a ServletConfig Object.
application is a ServletContext Object.
page is a JspPage Object.
pageContext is a PageContext Object.
out is a JspWriter Object.
exception is a Throwable Object.
Monday, June 21, 2010
Tools to be used to run java Applications or Database ?
Eclipse or NetBeans : IDE for java
MySQL Query Browser : GUI tool for MySql
TOAD : GUI tool for Oracle
ANT : Tool for compiling, deploying, running java applications.
DBVisualizer : Provides relationship diagram for a database.
SOAPUI : Tool for calling a SOAP webservice. It acts like a SOAP Client.
Tomcat : Its a web server for running java web applications.
JBOSS : Its a application server running java Enterprise applications.
MySQL Query Browser : GUI tool for MySql
TOAD : GUI tool for Oracle
ANT : Tool for compiling, deploying, running java applications.
DBVisualizer : Provides relationship diagram for a database.
SOAPUI : Tool for calling a SOAP webservice. It acts like a SOAP Client.
Tomcat : Its a web server for running java web applications.
JBOSS : Its a application server running java Enterprise applications.
Difference between Array and ArrayList ?
•array is the one which can save similar data typed elements.And the size is limited. arraylist is a collection which is capable of saving different data typed objects, And is growable.
•ArrayList can hold objects(custom...or...defined)
•It provides an overloaded method to perform binary search on its objects.
•Array is for homogeneous data. i.e data of same data type.
Whereas Arraylist is for Heterogeneous data.
•ArrayList can hold objects(custom...or...defined)
•It provides an overloaded method to perform binary search on its objects.
•Array is for homogeneous data. i.e data of same data type.
Whereas Arraylist is for Heterogeneous data.
Lifecycle of all EJB Components
Life Cycle of a Stateless Session Bean:
Since the Stateless session bean does not passivates across method calls therefore a stateless session bean includes only two stages. Whether it does not exist or ready for method invocation. A stateless session bean starts its life cycle when the client first obtains the reference of the session bean. For this, the container performs the dependency injection before invoking the annotated @PostConstruct method if any exists. After invoking the annotated @PostConstruct method the bean will be ready to invoke its method by the client.

The above figure demonstrates how the Stateless Session Beans are created and destroyed. The container calls the annotated @PreDestroy method while ending the life cycle of the session bean. After this, the bean is ready for garbage collection.
Life Cycle of a Stateful Session Bean: A Stateful session bean starts its life cycle when the client first gets the reference of a stateful session bean. Before invoking the method annotated @PostConstruct the container performs any dependency injection after this the bean is ready. The container may deactivate a bean while in ready state (Generally the container uses the least recently use algorithm to passivates a bean). In the passivate mechanism the bean moves from memory to secondary memory. The container invokes the annotated @PrePassivate method before passivating the bean. If a client invokes a business method on the passivated bean then the container invokes the annotated @PostActivate method to let come the bean in the ready state.

The above image shows the various states of the Stateful Session Beans While ending the life cycle of the bean, the client calls the annotated @Remove method after this the container calls the annotated @PreDestroy method which results in the bean to be ready for the garbage collection.
The EntityManager Interface: The EntityManager API creates and removes persistent entity instances, finds entities by the entity’s primary key, and allows queries to be run on entities. To obtain an EntityManager instance, inject the entity manager into the application component: @PersistenceContext EntityManager em; Managing an
Entity Instance’s Life Cycle: You manage entity instances by invoking operations on the entity by means of an EntityManager instance. Entity instances are in one of four states: new, managed, detached, or removed. New entity instances have no persistent identity and are not yet associated with a persistence context. Managed entity instances have a persistent identity and are associated with a persistence context. Detached entity instances have a persistent identify and are not currently associated with a persistence context. Removed entity instances have a persistent identity, are associated with a persistent context, and are scheduled for removal from the data store.

Different callback annotations supported by Entity Bean are
• @PostLoad
• @PrePersist
• @PreUpdate
• @PreRemove
• @PostPersist
• @PostUpdate
• @PostRemove
Since the Stateless session bean does not passivates across method calls therefore a stateless session bean includes only two stages. Whether it does not exist or ready for method invocation. A stateless session bean starts its life cycle when the client first obtains the reference of the session bean. For this, the container performs the dependency injection before invoking the annotated @PostConstruct method if any exists. After invoking the annotated @PostConstruct method the bean will be ready to invoke its method by the client.
The above figure demonstrates how the Stateless Session Beans are created and destroyed. The container calls the annotated @PreDestroy method while ending the life cycle of the session bean. After this, the bean is ready for garbage collection.
Life Cycle of a Stateful Session Bean: A Stateful session bean starts its life cycle when the client first gets the reference of a stateful session bean. Before invoking the method annotated @PostConstruct the container performs any dependency injection after this the bean is ready. The container may deactivate a bean while in ready state (Generally the container uses the least recently use algorithm to passivates a bean). In the passivate mechanism the bean moves from memory to secondary memory. The container invokes the annotated @PrePassivate method before passivating the bean. If a client invokes a business method on the passivated bean then the container invokes the annotated @PostActivate method to let come the bean in the ready state.
The above image shows the various states of the Stateful Session Beans While ending the life cycle of the bean, the client calls the annotated @Remove method after this the container calls the annotated @PreDestroy method which results in the bean to be ready for the garbage collection.
The EntityManager Interface: The EntityManager API creates and removes persistent entity instances, finds entities by the entity’s primary key, and allows queries to be run on entities. To obtain an EntityManager instance, inject the entity manager into the application component: @PersistenceContext EntityManager em; Managing an
Entity Instance’s Life Cycle: You manage entity instances by invoking operations on the entity by means of an EntityManager instance. Entity instances are in one of four states: new, managed, detached, or removed. New entity instances have no persistent identity and are not yet associated with a persistence context. Managed entity instances have a persistent identity and are associated with a persistence context. Detached entity instances have a persistent identify and are not currently associated with a persistence context. Removed entity instances have a persistent identity, are associated with a persistent context, and are scheduled for removal from the data store.
Different callback annotations supported by Entity Bean are
• @PostLoad
• @PrePersist
• @PreUpdate
• @PreRemove
• @PostPersist
• @PostUpdate
• @PostRemove
About InnoDB and MYISAM Table Engines
.Inno DB is a Trasactional support like rollback and savepoint. But MyISAM has no trasactional support.
.Inno DB is having row level locking and MyISAM has Table level locking.
.Inno DB is having low performance based on above reasons and MyISAM is having High performance based on above reasons
.Inno DB is having Crash recovery support and MyISAM has no crash recovery.
.Inno DB is having forign key support and MyISAM has no forign key support.
.InnoDB stores data rows physically in primary key order MyISAM typically stores them mostly in the order in which they are added.
.Inno DB is having row level locking and MyISAM has Table level locking.
.Inno DB is having low performance based on above reasons and MyISAM is having High performance based on above reasons
.Inno DB is having Crash recovery support and MyISAM has no crash recovery.
.Inno DB is having forign key support and MyISAM has no forign key support.
.InnoDB stores data rows physically in primary key order MyISAM typically stores them mostly in the order in which they are added.
JSP to Servlet generation.
Whenever server gets the request to the jsp file, server (Here example is Tomcat or JBOSS) internally generates a lifecycle methods jspInit(),_jspService(),jspDestroy() in work/catalina/localhost(for Tomact) . Or work\jboss.web\localhost\project\org\apache\jsp(for JBOSS). So the life cycle methods generation will happen only at the time of server gets the request. Thats why we no need to deploy if we do some changes in JSP file.
PHP Email Grabber
If you login in the following link with Gmail , yahoo, or any social networking site credentials you can see all contact list from corresponding mail. Try this. Its useful for Email Marketing.
http://openinviter.com/demo/
http://openinviter.com/demo/
Difference b/w GenericServlet and HTTPServlet ?
• GenericServlet belongs to javax.servlet package GenericServlet is an abstract class which extends Object and implements Servlet, ServletConfig and java.io.Serializable interfaces. The direct subclass to GenericServlet is HttpServlet.It is a protocol-independent servlet. To write a GenericServlet you need abstract service() to be overridden. HttpServlet: HttpServlet belongs to javax.servlet.http package This is an abstract class which extends GenericServlet and implements java.io.Serializable A subclass of HttpServlet must override at least one method of doGet(), doPost(),doPut(), doDelete(), init(), destroy(), getServletInfo().
• Http servlets provides methods that supports cookies,sessions etc.
• Http servlets provides methods that supports cookies,sessions etc.
Sunday, June 20, 2010
Difference Between abstract and interface?
• A class may implement any number of interfaces, but a class can extends only one abstract class or non-abstract class. • Every method in the interface should be public.
• Abstract class can have either abstract methods or concrete methods.
• The class which implements interface should implement all methods.
• Adding functionality is advantage of abstract class.
• If various implementations only share method signatures then it is better to use Interfaces, If various implementations are of the same kind and use common behaviour or status then abstract class is better to use.
• Abstract class can have either abstract methods or concrete methods.
• The class which implements interface should implement all methods.
• Adding functionality is advantage of abstract class.
• If various implementations only share method signatures then it is better to use Interfaces, If various implementations are of the same kind and use common behaviour or status then abstract class is better to use.
Difference between ServletConfig and ServletContext ?
when we deploy a web application the webcontainer reads the deployment descriptor(i.e,web.xml).If there is no problem then the webcontainer creates a ServletContext object for that web-application.the webcontainer removes the ServletContext objcet when the web application is stopped.so the no. of ServletContext objects present in web container depends on no.of web applications present in web.xml.for every web application a ServletContext object is created by web container.
and WebContainer creatse ServletConfig object for every servlet that is a part of web application.As part of web application there will be only one ServletContext object,but there can be multiple ServletConfig objects...
Subscribe to:
Posts (Atom)