JavaSpartans
Java J2ee Struts Hibernate Spring Interview Questions Java J2ee Struts Hibernate Spring Interview Questions
584 Results; Time:0.147 Sec; Page : 1 ; Results From 1 to 10. Results Per Page

1. What are the differences between sleep() and wait() methods in multi threading ?

  1. sleep() method is defined in class Thread and wait() method is in class Object.
  2. sleep() is a static method where as wait() is an instance method.
  3. sleep(1000) will wait exactly for 1 second wait(1000) wait up-to 1 second.
  4. sleep() object will keeps its locks. wait() object releases all its locks.
  5. wait(), notify(), notifyAll() methods should be called only from with in synchronized context or code.
  6. A thread could stop waiting earlier if it receives the notify() or notifyAll() call.

2. Can you tell the other names for Marker Interface ?

Tagged Interface , Ability Interface , Null Interface , Empty Interface, Blank Interface as it does not contain any fields or methods.

3. Can you give few examples for Marker Interfaces ?

java.io.Serializable ,
javax.servlet.SingleThreadModel ,
java.rmi.Remote,
javax.ejb.EnterpriseBean,
java.lang.Cloneable,
java.util.EventListener.

4. What is a Socket ?

In 1970 , Developed by the Berkeley University for C & UNIX to write network applications . Our java.net.* package internally uses sockets and it abstracts some implementation .

5. What is a self-executable jar ?

A jar which can be executed by it-self as an application by just clicking on that .

6. How can you create a self executable jar ?

Self executable jar is one which can be executed directly just by clicking on that with mouse like a .exe file in C Language.
By providing main class which contains the main() method, the starting point of application in the manifest file of the jar.

7. How do you implement synchronization ?

Synchronization is a process of restricting concurrent access to the shared resources. As synchronization is a performance issue, we should be very much careful fo decide at which part of the code the problem may occur. At that place provide a synchronized block or simply provide a synchronized method. just use the key word synchronized before the method or block. Please note that we can synchronize only blocks or methods. we can not synchronize variables or classes. By creating locks automatically by using wait(), notify() and notifyAll() methods  the Java Virtual machine taking care of inner implementation.

8. If all the threads in a Servlet are hanged. How do you come-out or debug from this situation ?

By Monitor thread .

9. What is the default size of Vector, ArrayList, Hashtable, HashMap, and HashSet in Java?

Vector, ArrayList are all growable array of objects so the size is not specific but depends upon the heap area of JVM. Vector has a default size of 0. A vector has its default capacity which is 10 elements, here size is different from capacity, after 10 element if we enter one element the capacity of vector changes to 20 were as size is 11 only, for example if you have entered 21 elements in a vector, then if you print v.size it results 21 but v.capacity it results 30.
Vector default size - 0;           default capacity 10,
ArrayList default size - 0; default capacity 10, 
Hashtable - default size 0;  Hashmap - 0, HashSet ? 0;
The default initial capacity : for Hashtable 11, for HashMap 11, for HashSet 16.

Consider the output for Vector :
Vector v = new Vector();
System.out.println("vsize"+v.size());  0
System.out.println("vcapacity"+v.capacity()); 10
v.add("Hello");
System.out.println("vsize"+v.size()); 1
System.out.println("vcapacity"+v.capacity()); 10
v.add("Hello1");v.add("Hello2");v.add("Hello3");v.add("Hello4");v.add("Hello5");
v.add("Hello6");v.add("Hello7");v.add("Hello8");v.add("Hello9");v.add("Hello10");
System.out.println("vsize"+v.size()); 11
System.out.println("vcapacity"+v.capacity()); 20

10. What is phantom memory and how it is useful ?

In JavaTM, an object is phantom reachable if it is neither strongly nor softly nor weakly reachable and has been finalized and there is a path from the roots to it that contains at least one phantom reference.

When the Java collector(1) determines that an object is phantom reachable, the reference objects containing the phantom references are enqueued.

The Java specification says that the phantom reference is not cleared when the reference object is enqueued, but actually, there's no way in the language to tell whether that has been done or not. In some implementations, JNI weak global references are weaker than phantom references, and provide a way to access phantom reachable objects.

In JavaTM terminology, phantom reference is used to mean a reference encapsulated in a reference object of class PhantomReference.

Phantom references form one of three kinds of weak reference(1) in Java. They are handy for performing clean-ups after an object has died and been finalized.

Other links: Java spec for class PhantomReference; Reference Objects and Garbage Collection.

A phantom reference lets you do final touch up closing on an object, even after it has been declared dead no longer referenced by any live object. Java has four orders of strength in holding onto Objects. In descending order from strongest to weakest they are:
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 finalized.

Java J2ee Struts Hibernate Spring Interview Questions
584 Results; Time:0.147 Sec; Page : 1 ; Results From 1 to 10. Results Per Page
Menu - javaspartans.com - Java J2ee Struts Spring Hibernate Interview Questions
Hostens.com - A home for your website
Ads By Google