Monday, April 26, 2010

what will happen if I serialize and de-serialize a singleton instance in same JVM?

what will happen if I serialize and de-serialize a singleton instance in same JVM?

We will get two instances of Singleton object. To avoid that we should use a readResolve() method which returns the singleton instance.


Implementing a Serializable Singleton:

public class MySingleton implements Serializable
{
static MySingleton singleton = new MySingleton();
private MySingleton() {
}
// This method is called immediately after an object of this class is deserialized.
// This method returns the singleton instance.
protected Object readResolve()
{
return singleton;
}
}


You might also like ..


SHARE & SAVE
Delicious Digg Furl Stumbleupon Technorati Squidoo Reddit live Yahoo MySpaceGoogle Yahoo Buzz Facebook Twitter Orkut Google Buzz Email this postby bbP

what is JIT - Just In Time Compiler?

what is JIT - Just In Time Compiler?

JIT is sometimes called as Dynamic translation is a technique to improve the run time performance of a computer system.
JIT builds upon two earlier ideas in run-time environments: bytecode compilation and dynamic compilation.
It converts code at runtime prior to executing it natively, for example bytecode  into native machine code.

In a bytecode-compiled system, source code is translated to an intermediate representation known as bytecode. Bytecode is not the machine code for any particular computer, and may be portable among computer architectures. The bytecode may then be interpreted by, or run on, a virtual machine. A just-in-time compiler can be used as a way to speed up execution of bytecode. At the time the bytecode is run, the just-in-time compiler will compile some or all of it to native machine code for better performance. This can be done per-file, per-function or even on any arbitrary code fragment; the code can be compiled when it is about to be executed (hence the name "just-in-time").

Resource: http://en.wikipedia.org/wiki/Just-in-time_compilation


You might also like ..


SHARE & SAVE
Delicious Digg Furl Stumbleupon Technorati Squidoo Reddit live Yahoo MySpaceGoogle Yahoo Buzz Facebook Twitter Orkut Google Buzz Email this postby bbP

Difference between page and pageContext

  page  and pageContext are implicit variables.

   page :   page is of class java.lang.Object,and it refers to instance of generated servlet.It is declared as

          Object page=this;

                          // this refers to the instance of this servlet

     page cannot be used to directly call the servlet methods.

1) <%=page.getServletInfo()%>

  Error bcoz page is  java.lang.Object type

 2)          <%=((servlet)page).getServletInfo()%>  <----OK:typecast

    3)       <%=this.getServletInfo()%> <-------OK

pageContext :

           pageContext is of type javax.servlet.jsp.PageContext.

          pageContext class is an abstract class.

it do following things;

 1.provide convenience methods to get and set attributes in diff scopes.

 2.provide convenience methods for transfering requests to other resources in the web application

      void include(String relativeURL)  & void forward(String relativeURL)

  Ex; pageContext.forward("suman.jsp");

3.store the references to implicit objects


You might also like ..


SHARE & SAVE
Delicious Digg Furl Stumbleupon Technorati Squidoo Reddit live Yahoo MySpaceGoogle Yahoo Buzz Facebook Twitter Orkut Google Buzz Email this postby bbP