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?
  • Thursday, July 15, 2010

    My CSC Rendezvous....


  • How vector/arrayList add/delete is implemented?

  • What is the use of View Resolver?

  • Scheduling Algorithms in OS.

  • What happens when a thread starts?

  • What is Generics and what are its advantages?

  • How will you configure a logger for a set of servlets?

  • How will you create a pdf file instead of html in jsp/servlets mapping?

  • Wednesday, June 9, 2010

    Absolutely Singleton.....

    Many of Java developers know about singleton pattern and how to create it. But, creating a thread safe Singleton is the real absolute singleton. Otherwise, there are chances for ending up with different objects for different threads, which is totally against singleton.

    A sample program given in the discusion here clearly explains how a singleton which is not thread safe can create different objects w.r.t different threads.

    Saturday, May 8, 2010

    Servlet, JSP..

  • What is the difference between JSP and Servlet?
  • How can JSP and Servlet communicate with each other?
  • How to track an user? (Session and cookies)
  • How to create a session in servlets?
  • How will you implement a page counter using Jsp/Servlet? Where will you initialize the variable and where will it get incremented? What will happen to it, when the server crashes?
  • Do you have used any Servlet filters? What is a filter?
  • Can a servlet have a constructor? (No.)
  • Saturday, March 27, 2010

    Unix Questions

  • How to find and delete files older than a year in Unix?
  • Write the awk command print the 5th column of 'ls -l'?
  • What will be the default permissions of a file created in Unix?
  • How would you execute a script file and how to execute the script file from a different directoy?
  • Write the grep command to find pattern "Vinod" and "Vinney" from a file.
  • what is SED and AWK?
  • Adding Questions

  • What are the conditions underwhich finally() wont be called?
  • Differences between wait() and sleep()?
  • What is static/early binding and dynamic/late binding?
  • How to create user defined exceptions? How to use throw and throws?
  • What is synchrnization? What are threads and why do we need them?
  • Static block

    Updated on 8th May 2010

  • I have a design, which gets changed often. In this case, which is to be used either abstract class or interface?
  • Difference b/w wait() and sleep()?
  • Difference b/w Hashmap and Hashtable? How to synchronize my HashMap()?
  • Features in Java1.5
  • Difference b/w stringBuffer and stringBuilder?
  • Reflection
  • Saturday, February 20, 2010

    Interesting Questions....

  • What is the difference between NoclassDefFoundError and ClassNotFoundException?

  • Is it possible to declare a method in scriptlet? What is the use of declaration tag in JSP?
  • Friday, February 19, 2010

    JSP:Can a method be declared in scriptlets?

    Can we declare a method in scriptlets? If so, what is the use of declaration tag?
    If you want the answers, just Click here