Thursday, November 6, 2008

Technical Interview Questions: Java & C++

Which sorting algorithm is fastest?
Quicksort, Merge-sort

How much time it will take to find largest number in a array

What will happen to the lock object when the thread is in sleep state.
the thread will hold the lock and it will not do anything until it explicitly releases the lock by calling notify or exiting from the synchronized block.

How to make a Java program faster?
one possible answer is use the java's concurrent apis

In a given connection object in a client-server application, there are 2 client session open simultaneously, but the 2nd client is not able to connect, getting connection failure message. Assume that singleton pattern is used here. What might be the problem?
The problem can be the singleton pattern will only work per JVM, assuming the connection object is singleton, the 2 clients might be running in two separate JVMs, which might be causing 2nd client unable to connect with connection failure message.

Write in-order or post order traversal program of a binary tree.
Quick solution is to implement it through stack.
For e.g.,
struct {
struct node* left;
struct node* right;
int value;

struct node* root;
//initialize with some elements;
//initialize a stack

void traverse(struct node* anode) {

struct node* next;
while ((next=stack.pop())!=null) {



Traversing without recursion, can be done using stack

Sample code:
      public void visit(Node node)
  sb.append(node.val + " ");

public String traverse(Node node)
  if(node.left == null && node.visit==false)
  else if(!node.left.visit)
  if(node.right !=null)
 return sb.toString();

What are marker interface in Java?
Null interfaces, they do not have any method declarations, used for naming a set of classes. Examples are Serializable, Clonable

What is difference between hashmap and hashtable?

Describe singleton design pattern.

1 comment:

Anonymous said...

Great Job...… the blog is indeed really very helpful… I found a similar link that serves the same purpose and is equally good, providing Interview Questions, besides Placement Papers for almost all major IT Companies….

For more details, visit

Check out yourself at