Monday, November 22, 2010

Open Closed principle

Coming soooooon.....

Friday, November 19, 2010

Unsafe Singleton

Many mighy think, is there something called unsafe singleton? Singleton is the property, which lets just only one object floats at a time and there are no more than one object. This singleton program will create more than one object under multi threaded environment, which is totally against rationale.

public class SingletonUnsafeDemo
{
public static void main( String[] args )
{
Thread t1 = new Thread()
{
public void run()
{
System.out.println( "UnsafeSingleton: " + UnsafeSingleton.getInstance() );

}
};

Thread t2 = new Thread()
{
public void run()
{
System.out.println( "UnsafeSingleton: " + UnsafeSingleton.getInstance() );

}
};


t1.start();
t2.start();
}
}

class UnsafeSingleton
{
static UnsafeSingleton instance;

public static UnsafeSingleton getInstance()
{
if ( instance == null )
{
Thread.yield(); // !!

instance = new UnsafeSingleton();
}

return instance;
}
}

Tuesday, August 10, 2010

Round VI

  • write singleton pattern. explain. how will you create a thread safe singleton pattern?

  • diff between serialization and externalization.

  • Talk about stack.

  • what is the use of linked list?

  • use any data structure and implement stack. (i did use arrays and explained push() pop())

  • implement linked list using Arrays. (i did come up with a logic and explained to him, he asked more on this.)

  • difference between pass by value and pass by reference. How it is w.r.t java?
  • Round V

  • Jmeter(more questions on this)

  • web services.

  • How will you get a bean using spring?

  • xeta architecture.

  • tomcat authentication.

  • Java Debugger. Hibernate( i told whatever I know and she too acknowledged it)
  • Round IV

  • Is it possible to access a private method outside it's class? Done using reflection.

  • Iterator and ListIterator

  • how to delete a element from a collection.

  • Singleton, which is threadsafe.

  • difference between statement and preparedStatement object.

  • what is outer join?

  • synchronization - how to synchronize static methods?

  • Jmeter, i did talk more about pathway on NSK and it acutally load balances.

  • any singleton classes available in java. Runtime() I dint say this.

  • Runtime class for finding memory.

  • did ask about synchronizedset, synchronizedlist and synchronizedmap.

  • factory pattern. gave a complete picture about this w.r.t NSJSP manager code.
  • Round III

  • What do you know about deadlock?

  • What is yield() in threads?

  • what is a volatile variable in java?

  • How will you implement Least Recently Used Cache using java.util.Collections? Told a logic like add a flag to each element with last accessed time and can use this to check the newly accessed elemnt's time and implement it. If there are more elements, this method has to serially see all elements, which is not feasible.

  • What are indexes? what are inner and outer joins?

  • What is "open closed" priciple?(Open for extension and closed for modification)

  • What is dependecy injection? He stressed on getting answers from me for this. He gave some examples too.

  • What is decorator design pattern?
  • Round II

  • What are transport layer protocols? What are application layer protocols?

  • What is TCP/IP? What is UDP?

  • What connection is TCP/IP? What protocol does a landline phone uses?
    synchronized methods vs synchronized blocks.

  • what is deadlock? Write a code which exhibits deadlock?

  • write xml and spring.xml file mapping?

  • What is a LinkedHashSet?

  • What is ref and depends means in spring.xml file? (I did say about depends in Ant script)

  • What are the design patterns used in your project? I told singleton, Factory Pattern. I explained about Factory pattern too.

  • About parsers. DOM and sAX parsers. Have you worked on XML?
  •