There are several types of inner classes.
Inner classes
method-inner classes
Anonymus inner classes
static nexted inner classes
The usage of each inner class has shown below :
Inner class:
class Outer
{
class Inner
{
public void innerClassMethod()
{
System.out.println("You are in the method of inner class");
}
}
public void outerClassMethod()
{
Inner i=new Inner();
i.innerClassMethod();
}
}
The above represents the how to create a inner classes and how to use them. As you know when we compile a java file there will be a class files will be generated for all the classes defined in the java file. For inner classes also it will generate the class file as Outer$Inner.class.(But we can not run using Outer$Inner directly).
We can also use the innerClassMethod() in the main also (not only in outerClassMethod()) by creating the object of inner class in the main as below
Outer.Inner innerInstance= new Outer.new Inner()
innerInstance.innerClassMethod();
method-inner classes:
class Outer
{
public void outerClassMethod()
{
class Inner
{
public void innerClassMethod()
{
System.out.println("You are in the method of inner class");
}
}
Inner i=new Inner();
i.innerClassMethod();
}
}
Creating object for method inner classes:
We can only create the object of method-inner classes only in the methods in which the inner class is defined like above.
Anonymous Inner Classes :
class A{
public void sampleMethod() {
System.out.println("Sample Method");
}
}
class B{
A p = new A() {
public void sampleMethod() {
System.out.println("anonymous Sample Method");
}
};
}
If you observe class B, there is class defined with the name outer method A. We can consider that method subclass of class A. But without name. Thats why it is called as Anonymous inner classes.
Static inner classes:
class BigOuter {
static class Nest {void go() { System.out.println("hi"); } }
}
class Broom {
static class B2 {void goB2() { System.out.println("hi 2"); } }
public static void main(String[] args) {
BigOuter.Nest n = new BigOuter.Nest(); // both class names
n.go();
B2 b2 = new B2(); // access the enclosed class
b2.goB2();
}
}
Above i have defined two types of using static inner classes.
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, August 11, 2010
Friday, August 6, 2010
Differences between jar, war, ear files ?
jar - java archive,These files are with the .jar extension. The .jar files contain the libraries, resources and accessories files like property files.
war - web archive : These files are with the .war extension. The war file contains the web application that can be deployed on the any servlet/jsp container. The .war file contains jsp, html, javascript and other files for necessary for the development of web applications.
EAR - enterprise archive, These files are with the .ear extension.
All .jar and .war are packaged as JAR file with .ear extension and deployed into Application Server.
we can say EAR= WAR+JAR.
These three types of files called as jar files with different extensions. If we want to generate these files we will use JAR as a command in the command prompt.
war - web archive : These files are with the .war extension. The war file contains the web application that can be deployed on the any servlet/jsp container. The .war file contains jsp, html, javascript and other files for necessary for the development of web applications.
EAR - enterprise archive, These files are with the .ear extension.
All .jar and .war are packaged as JAR file with .ear extension and deployed into Application Server.
we can say EAR= WAR+JAR.
These three types of files called as jar files with different extensions. If we want to generate these files we will use JAR as a command in the command prompt.
OOPs Concepts ?
Object oriented Programming includes
Objects
Classes
Data abstraction and Encapsulation
Inheritance
Polymorphism
Dynamic Binding
Message Passing
Objects
Classes
Data abstraction and Encapsulation
Inheritance
Polymorphism
Dynamic Binding
Message Passing
Tuesday, August 3, 2010
Default values of a instance variables ?
The default values of INSTANCE variables are
Object reference - NULL
byte, short, int, long - 0
float, double - 0.0
boolean - false
char - '\uooo' // Unicode character
Object reference - NULL
byte, short, int, long - 0
float, double - 0.0
boolean - false
char - '\uooo' // Unicode character
How to Sort a Collection ? or About Comparable,Comparator interface ?
Here is the example of a sorting a collection ArrayList of String objects.
ArrayList stringList=new ArrayList();
stringList.add("world");
stringList.add("hello");
Collections.sort(stringList); //Collections is a utility class using that we can sort.
After this method the resultant list contains 2 strings with sorted. That means we are able to sort the ArrayList (collection) successfully.
Similarly, If we try to sort a user defined class objects instead of String objects like..
ArrayList dvdList=new ArrayList();
.........
.........
Collections.sort(dvdList); // It will not sort like Sting objects collection.
Because compiler does not know on which basis it has to sort. So, we have to tell programatically to sort the collection by implementing DVDInfo class to Comparable interface. For your information, String objects are implementing Comparable interface internally.
If we implement Comparable interface to our class DVDInfo, we have to implement or override the one of following method.
public int compareTo(Object obj) { .......} or
public int compareTo(DVDInfo obj){ .......}.
Using compareTo() we can have only one sort sequence. To want many sort sequences we use Comaparator and its method compare(). compare() method takes 2 arguments. First argument is which class is to be sorted, second is as which basis the class is to be sorted which should implement Comparator and override the method compare().
String, Wrapperclasses, Date, Calender classes are implicitly implement the Comparable interface.
ArrayList
stringList.add("world");
stringList.add("hello");
Collections.sort(stringList); //Collections is a utility class using that we can sort.
After this method the resultant list contains 2 strings with sorted. That means we are able to sort the ArrayList (collection) successfully.
Similarly, If we try to sort a user defined class objects instead of String objects like..
ArrayList
.........
.........
Collections.sort(dvdList); // It will not sort like Sting objects collection.
Because compiler does not know on which basis it has to sort. So, we have to tell programatically to sort the collection by implementing DVDInfo class to Comparable interface. For your information, String objects are implementing Comparable interface internally.
If we implement Comparable interface to our class DVDInfo, we have to implement or override the one of following method.
public int compareTo(Object obj) { .......} or
public int compareTo(DVDInfo obj){ .......}.
Using compareTo() we can have only one sort sequence. To want many sort sequences we use Comaparator and its method compare(). compare() method takes 2 arguments. First argument is which class is to be sorted, second is as which basis the class is to be sorted which should implement Comparator and override the method compare().
String, Wrapperclasses, Date, Calender classes are implicitly implement the Comparable interface.
Monday, August 2, 2010
Difference between String, StringBuffer, StringBuilder ?
String Objects are immutable. That means we can not change the value of a String Object. For example,
String s="Hello"; // A object creates in the heap memory and 's' refers to it.
String s2=s.concat("World");// A new object creates with the "Hello World" and s2 refers to it instead of using the same memory for "Hello" Object
So, Here there is a wastage of memory for 's' object.
Unlike Strings, StringBuffer and StringBuilder are mutable. We can change the value in these objects.
The only difference between StringBuffer and StringBuilder is that StringBuilder is unsynchronized whereas StringBuffer is synchronized. So when the application needs to be run only in a single thread then it is better to use StringBuilder. StringBuilder is more efficient than StringBuffer.
String s="Hello"; // A object creates in the heap memory and 's' refers to it.
String s2=s.concat("World");// A new object creates with the "Hello World" and s2 refers to it instead of using the same memory for "Hello" Object
So, Here there is a wastage of memory for 's' object.
Unlike Strings, StringBuffer and StringBuilder are mutable. We can change the value in these objects.
The only difference between StringBuffer and StringBuilder is that StringBuilder is unsynchronized whereas StringBuffer is synchronized. So when the application needs to be run only in a single thread then it is better to use StringBuilder. StringBuilder is more efficient than StringBuffer.
Friday, July 30, 2010
About java finalize() method ?
Its a method defined in Object(Which is a base class of all the classes) class. Java dont have destructors instead it uses finalize() method. finalize() method not guarantee to run. For any given object finalize() method will be called only once by the garbage collector. Calling finalize() method can actually result in saving an object from deletion. If finalize() method contains the code of assigning a reference so that the object is not eligible for Garbage Collector. The second time the garbage collector will delete it. Because finalize() method run only one time for a given object.
Thursday, July 29, 2010
The list of interfaces we use in javax.servlet.http package ?
The javax.servlet.http package contains a number of classes and interfaces that describe and define the contracts between Servlet class running under a HTTP Potocol and the runtime environment provided for an instance of such a class by a conforming Servlet container.
The List of interfaces and classes in javax.servlet.http package are as follows.
HttpServletRequest
HttpServletResponse
HttpSession
HttpSessionListener
HttpServlet
Cookie
The List of interfaces and classes in javax.servlet.http package are as follows.
HttpServletRequest
HttpServletResponse
HttpSession
HttpSessionListener
HttpServlet
Cookie
The list of interfaces we use in javax.servlet package ?
The javax.servlet package contains a number of classes and interfaces that describe and define the contracts between Servlet class and the runtime environment provided for an instance of such a class by a conforming Servlet container.
The List of interfaces and classes in javax.servlet package are as follows.
Servlet
ServletConfig
ServletRequest
ServletResponse
RequestDispatcher
Filter
FilterConfig
FilterChain
GenericFilter
ServletOutputStream
ServletInputStream
ServletException
The List of interfaces and classes in javax.servlet package are as follows.
Servlet
ServletConfig
ServletRequest
ServletResponse
RequestDispatcher
Filter
FilterConfig
FilterChain
GenericFilter
ServletOutputStream
ServletInputStream
ServletException
Wednesday, July 28, 2010
What is a Java Thread and How to create them ?
Threads are lightweight processes that appear to run in parallel with your main program. Unlike a process a thread shares memory and data with the rest of the program. The word thread is a contraction of "thread of execution".An example of where threads can be useful is in printing. When you click on a print button you probably don't want the main program to stop responding until printing has finished. What would be nice is that the printing process started running "in the background" and allowed you to continue using the main portion of the program.
There are 2 ways to create a java thread.
1. By extending the class with the Thread class.
2. By implementing the Runnable interface.
In both the cases we have to implement run() method.
The best way to create the thread is to implement Runnable interface. Because, As you know java will not support multiple inheritance so, if we extend the class with the Thread class we cant extend with any other class. If we implement the class with Runnable interface, we can extend any other class
There are 2 ways to create a java thread.
1. By extending the class with the Thread class.
2. By implementing the Runnable interface.
In both the cases we have to implement run() method.
The best way to create the thread is to implement Runnable interface. Because, As you know java will not support multiple inheritance so, if we extend the class with the Thread class we cant extend with any other class. If we implement the class with Runnable interface, we can extend any other class
Tuesday, July 27, 2010
Calling Java Garbage Collector ?
We can request (not demand) the java garbage collector to run by using 2 ways.
1. Runtime rt = Runtime.getRuntime();
rt.gc();
2. System.gc();
Using Runtime object rt you can call more methods to know JVM memory. Examples,
rt.totalMemory(), Will return the total memory of JVM.
rt.freeMemory(), will return the free memory of JVM.
1. Runtime rt = Runtime.getRuntime();
rt.gc();
2. System.gc();
Using Runtime object rt you can call more methods to know JVM memory. Examples,
rt.totalMemory(), Will return the total memory of JVM.
rt.freeMemory(), will return the free memory of JVM.
Which Objects eligible for Garbage Collection in Java ?
The Objects which are eligible for garbage collection are
1. StringBuffer sb=new stringBuffer("Hello");
System.out.println(sb); // "Hello" is NOT ELIGIBLE here for Garbage Collection.
sb=null; //"Hello" is ELIGIBLE here for Garbage Collection.
2. StringBuffer sb1=new stringBuffer("Hello");
StringBuffer sb2=new stringBuffer("goodbye");
s1=s2; //"Hello" is ELIGIBLE here for Garbage Collection.
3. Public static Date getDate(){
Date d2=new Date();
StringBuffer now=new StringBuffer(d2.toString());
System.out.println(now);
return d2;// Here d2 is NOT ELIGIBLE for Garbage Collection. But now is
ELIGIBLE for Garbage Collection
}
1. StringBuffer sb=new stringBuffer("Hello");
System.out.println(sb); // "Hello" is NOT ELIGIBLE here for Garbage Collection.
sb=null; //"Hello" is ELIGIBLE here for Garbage Collection.
2. StringBuffer sb1=new stringBuffer("Hello");
StringBuffer sb2=new stringBuffer("goodbye");
s1=s2; //"Hello" is ELIGIBLE here for Garbage Collection.
3. Public static Date getDate(){
Date d2=new Date();
StringBuffer now=new StringBuffer(d2.toString());
System.out.println(now);
return d2;// Here d2 is NOT ELIGIBLE for Garbage Collection. But now is
ELIGIBLE for Garbage Collection
}
Wednesday, July 14, 2010
Advantages of struts2 over struts1.0
• Struts 1 supports separate Request Processors (lifecycles) for each module, but all the Actions in the module must share the same lifecycle, Struts 2 supports creating different lifecycles on a per Action basis via Interceptor Stacks. Custom stacks can be created and used with different Actions, as needed.Struts 1 integrates with JSTL, so it uses the JSTL EL, Struts 2 can use JSTL, but the framework also supports a more powerful and flexible expression language called "Object Graph Notation Language" (OGNL).(Object graph navigation language)( It is aimed to be used in J2EE applications with taglibs as expression language.)
• Struts 1 Actions have dependencies on the servlet API since the HttpServletRequest and HttpServletResponse is passed to the execute method when an Action is invoked. Struts 2 Actions are not coupled to a container. Most often the servlet contexts are represented as simple Maps.
• Struts 1 Actions are singletons and must be thread-safe since there will only be one instance of a class to handle all requests for that Action. Struts 2 Action objects are instantiated for each request, so there are no thread-safety issues.
• Struts 1 requires Action classes to extend an abstract base class. A common problem in Struts 1 is programming to abstract classes instead of interfaces. Struts 2 , we can use interfaces.
3. Interceptors
• These are request pre-processors or post processors
• Examples create-session, params, prepare, validation, exception and logger.
o Create-session, which creates HTTPSession.
o Prepare, to run prepare() method.
o Fileupload, to validate a file object
o Exception, handling exceptions.
o Roles, It checks the allowed roles and disallowed roles using intercept() method.
o Servlet-config sets the action properties, based on the different interface implemented.
o Validation, checks the action against all validation rules.
• Struts 1 Actions have dependencies on the servlet API since the HttpServletRequest and HttpServletResponse is passed to the execute method when an Action is invoked. Struts 2 Actions are not coupled to a container. Most often the servlet contexts are represented as simple Maps.
• Struts 1 Actions are singletons and must be thread-safe since there will only be one instance of a class to handle all requests for that Action. Struts 2 Action objects are instantiated for each request, so there are no thread-safety issues.
• Struts 1 requires Action classes to extend an abstract base class. A common problem in Struts 1 is programming to abstract classes instead of interfaces. Struts 2 , we can use interfaces.
3. Interceptors
• These are request pre-processors or post processors
• Examples create-session, params, prepare, validation, exception and logger.
o Create-session, which creates HTTPSession.
o Prepare, to run prepare() method.
o Fileupload, to validate a file object
o Exception, handling exceptions.
o Roles, It checks the allowed roles and disallowed roles using intercept() method.
o Servlet-config sets the action properties, based on the different interface implemented.
o Validation, checks the action against all validation rules.
Monday, July 12, 2010
What is JDK, JRE, JVM ?
JDK (Java Development Kit)
Java Development Kit contains tools needed to develop the Java programs, and JRE to run the programs. The tools include compiler (javac.exe), Java application launcher (java.exe), Appletviewer, etc…
Compiler converts java code into byte code. Java application launcher opens a JRE, loads the class, and invokes its main method.
You need JDK, if at all you want to write your own programs, and to compile the m. For running java programs, JRE is sufficient.
JRE is targeted for execution of Java files
i.e. JRE = JVM + Java Packages Classes(like util, math, lang, awt,swing etc)+runtime libraries.
JDK is mainly targeted for java development. I.e. You can create a Java file (with the help of Java packages), compile a Java file and run a java file
JRE (Java Runtime Environment)
Java Runtime Environment contains JVM, class libraries, and other supporting files. It does not contain any development tools such as compiler, debugger, etc. Actually JVM runs the program, and it uses the class libraries, and other supporting files provided in JRE. If you want to run any java program, you need to have JRE installed in the system
The Java Virtual Machine provides a platform-independent way of executing code; programmers can concentrate on writing software, without having to be concerned with how or where it will run.
If u just want to run applets (ex: Online Yahoo games or puzzles), JRE needs to be installed on the machine.
JVM (Java Virtual Machine)
As we all aware when we compile a Java file, output is not an 'exe' but it's a '.class' file. '.class' file consists of Java byte codes which are understandable by JVM. Java Virtual Machine interprets the byte code into the machine code depending upon the underlying operating system and hardware combination. It is responsible for all the things like garbage collection, array bounds checking, etc… JVM is platform dependent.
The JVM is called "virtual" because it provides a machine interface that does not depend on the underlying operating system and machine hardware architecture. This independence from hardware and operating system is a cornerstone of the write-once run-anywhere value of Java programs.
There are different JVM implementations are there. These may differ in things like performance, reliability, speed, etc. These implementations will differ in those areas where Java specification doesn’t mention how to implement the features, like how the garbage collection process works is JVM dependent, Java spec doesn’t define any specific way to do this.
Java Development Kit contains tools needed to develop the Java programs, and JRE to run the programs. The tools include compiler (javac.exe), Java application launcher (java.exe), Appletviewer, etc…
Compiler converts java code into byte code. Java application launcher opens a JRE, loads the class, and invokes its main method.
You need JDK, if at all you want to write your own programs, and to compile the m. For running java programs, JRE is sufficient.
JRE is targeted for execution of Java files
i.e. JRE = JVM + Java Packages Classes(like util, math, lang, awt,swing etc)+runtime libraries.
JDK is mainly targeted for java development. I.e. You can create a Java file (with the help of Java packages), compile a Java file and run a java file
JRE (Java Runtime Environment)
Java Runtime Environment contains JVM, class libraries, and other supporting files. It does not contain any development tools such as compiler, debugger, etc. Actually JVM runs the program, and it uses the class libraries, and other supporting files provided in JRE. If you want to run any java program, you need to have JRE installed in the system
The Java Virtual Machine provides a platform-independent way of executing code; programmers can concentrate on writing software, without having to be concerned with how or where it will run.
If u just want to run applets (ex: Online Yahoo games or puzzles), JRE needs to be installed on the machine.
JVM (Java Virtual Machine)
As we all aware when we compile a Java file, output is not an 'exe' but it's a '.class' file. '.class' file consists of Java byte codes which are understandable by JVM. Java Virtual Machine interprets the byte code into the machine code depending upon the underlying operating system and hardware combination. It is responsible for all the things like garbage collection, array bounds checking, etc… JVM is platform dependent.
The JVM is called "virtual" because it provides a machine interface that does not depend on the underlying operating system and machine hardware architecture. This independence from hardware and operating system is a cornerstone of the write-once run-anywhere value of Java programs.
There are different JVM implementations are there. These may differ in things like performance, reliability, speed, etc. These implementations will differ in those areas where Java specification doesn’t mention how to implement the features, like how the garbage collection process works is JVM dependent, Java spec doesn’t define any specific way to do this.
Wednesday, June 30, 2010
Describe HashMap, Hashtable, LinkedHashMap, TreeMap ?
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
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
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)