Ebeworld’s Weblog

Trying to create

Applet event sequence

What is the order of method invocation in an applet? LF

The Applet’s life cycle methods are as follows:

• public void init() : Initialization method called only once by the browser.

• public void start() : Method called after init() and contains code to start processing. If the user leaves the

page and returns without killing the current browser session, the start () method is called without being

preceded by init ().

• public void stop() : Stops all processing started by start (). Done if user moves off page.

• public void destroy() : Called if current browser session is being terminated. Frees all resources used by the

applet.

October 14, 2008 Posted by ebeworld | Interview Questions, Java | , | No Comments Yet

Socket for interprocess communication

Sockets are communication channels, which facilitate inter-process communication. Never thought in this way, i always thought socket is for network related stuffs only.

October 14, 2008 Posted by ebeworld | Interview Questions, Java | , | No Comments Yet

Java Synchronized collection

Returns a synchronized (thread-safe) collection backed by the specified collection. In order to guarantee serial access, it is critical that all access to the backing collection is accomplished through the returned collection.It is imperative that the user manually synchronize on the returned collection when iterating over it:

  Collection c = Collections.synchronizedCollection(myCollection);
     ...
  synchronized(c) {
      Iterator i = c.iterator(); // Must be in the synchronized block
      while (i.hasNext())
         foo(i.next());
  }

October 14, 2008 Posted by ebeworld | Interview Questions, Java | | No Comments Yet

Java checked and unchecked exceptions

exceptFig4

October 14, 2008 Posted by ebeworld | Interview Questions, Java | | No Comments Yet

Java Reference Types

  1. The JVM holds onto regular Objects until they are no longer reachable by either clients or any container. In other words Objects are garbage collected when there are no more live references to them. Dead references don’t count.
  2. Soft references can be deleted from a container if the clients are no longer referencing them and memory is tight.
  3. Weak references are automatically deleted from a container as soon clients stop referencing them.
  4. Phantom references point to objects that are already dead and have been finalised.

 

 

 

Soft vs Weak vs Phantom References
Type Purpose Use When GCed Implementing Class
Strong Reference An ordinary reference. Keeps objects alive as long as they are referenced. normal reference. Any object not pointed to can be reclaimed. default
Soft Reference Keeps objects alive provided there’s enough memory. to keep objects alive even after clients have removed their references (memory-sensitive caches), in case clients start asking for them again by key. After a first gc pass, the JVM decides it still needs to reclaim more space. java.lang.ref.SoftReference
Weak Reference Keeps objects alive only while they’re in use (reachable) by clients. Containers that automatically delete objects no longer in use. After gc determines the object is only weakly reachable java.lang.ref.WeakReference
java.util.WeakHashMap
Phantom Reference Lets you clean up after finalization but before the space is reclaimed (replaces or augments the use of finalize()) Special clean up processing After finalization. java.lang.ref.PhantomReference

October 13, 2008 Posted by ebeworld | Interview Questions, Java | , | No Comments Yet