Feb 28, 2015

Textual description of firstImageUrl

Functions in python

In earlier posts we used python interpreter and executed lines of code to see the output.Suppose we want to execute a block of code lines, then function comes for rescue.Functions and methods are used interchangeably in other programming language.However, when we look python from object oriented perspective, their is a subtle difference :
In general term function is used to describe a traditional, stateless function that is invoked without the context of a particular class or an instance of that class. However, method is used to describe a member function that is invoked upon a specific object. Here we will discuss python functions.
Syntax of function in python is:
def function_name(arguments) # def is keyword in python and function_name is an identifier
     body of function # Please mind proper indentation
For better understanding we will write a sample program. Suppose we have an list containing numbers. We have to find how many 2's are there in this list.
Open IDLE(GUI tool of python) and create a file count.py and type following code snippet in it and execute, it will display no of 2's in the list.5
input_list = [12,2,34,56,2,4,5,6,78,12,2,3] #Total no of 2's is 3 

# Definition of countNoOf2 function 
def countNoOf2(input_list_formal):
      count= 0
      for var in input_list_formal:
            if var==2:
                 count= count+1;
      return count

# call countNoOf2 function

countOf2Is = countNoOf2(input_list)
print "Number of 2's is %d" % (countOf2Is )
Let's walk through the code : First we created a list input_list of integers. After that we define a function to count number of 2's: as mentioned earlier def is the Keyword which indicate that we are writing a function and countNoOf2  is an function name(it can be any valid name) , input_list  is the formal parameter to the function and with proper indentation we write body of the function.This function returns count to the caller. At the end, we call  this function
countOf2Is = countNoOf2(input_list). Here countOf2Is is place holder to store returned value from function call and input_list is actual parameter.

Note : 1. Python is a dynamically typed language, and therefore a Python signature does not designate the types of those parameters as we are forced to do in java and c++.

2. Each time a function is called, python creates an activation record which manages list of identifiers which are in local scope of the function. In above example, count,var having local scope to the function.

3. A return statement will be the final command within the body of the function.If return is executed without explicit argument then None is returned. None will also be returned if the flow of control ever reaches the end of a function body without having executed a return statement.

4.In python,while passing information to and from a function objects are not copied. Same object is referenced by formal and actual parameters.
Both input_list and input_list_formal is referring to same list
5. when a parameter is a mutable object then that object can be modified inside body of the function. When we execute input_list_formal.append(99) inside body of the function, input_list is also
affected since formal parameter(input_list_formal) is an alias for the actual parameter(input_list).Consider following sample code and execute using python IDLE.  .
input_list = [12,2,34,56,2,4,5,6,78,12,2,3] #Total no of 2's is 3 

# Definition of countNoOf2 function 
def countNoOf2(input_list_formal):
      count= 0
      input_list_formal.append(99) # input_list_formal is modified 
      for var in input_list_formal:
            if var == 2:
                 count= count+1;
      return count

# call countNoOf2 function

print input_list # input list is: [12, 2, 34, 56, 2, 4, 5, 6, 78, 12, 2, 3]
countOf2Is = countNoOf2(input_list)
print input_list # Modified list is: [12, 2, 34, 56, 2, 4, 5, 6, 78, 12, 2, 3, 99
After executing the above sample code the Modified list will be as follows :
6.Python support default parameter values in functions.Lets's consider following function:
def fun_with_default_parameter(input1, default1='Address', default2='PhoneNo'):
      #Body of function
there are three parameters in the above function call, the last two of which offer default values. We can call the above function like :
fun_with_default_parameter(Nikhil, 'Hyderabad', '500081') # default value is overridden
fun_with_default_parameter(Ranjan) # default value is used

7.Python support Keyword Parameters in functions. Above function can be modified to use keyword parameter passing.
def fun_with_keyword_parameter(name = 'Default_name',                    
                                                      address ='default_Address', Phone='default_PhoneNo'):
      #Body of function
here all three parameters having default values.We can override specific parameters via function call like this :
fun_with_keyword_parameter(name = 'Nikhil', phone = '88888888888')
fun_with_keyword_parameter(address= 'Madhapur, Hyderabad', phone = '88888888888')

8. Python support various in built functions which makes python simple and efficient. Few of them are listed below:

9.global statement: It is possible to assign a value to a variable defined outside a function using
global statement. Lets execute following sample code to understand it :
x = 50
def fun_global):
    global x     # x is marked global
    print 'x before reassign is ', x
    x = 2
    print 'Changed global x to', x
func()
print 'Value of x after reassign inside function', x 
Outcome of above program is : 
x before reassign is 50
Changed global x to 2
Value of x after reassign inside function 2
Since, x is marked global inside fun_global() so when x is reassigned with new value 2, it is available outside function too.

Previous : Python Data Structures - Non Sequence                    Next : Python Input and Output

Feb 21, 2015

Textual description of firstImageUrl

Python data structure - Non sequence types

In the previous post we discussed about sequence types data structure. Here we will be discussing about non sequence types in built data structure of python. Set, frozenset and dict classes are  non -sequence types in python.

set class:

1. Sets are unordered collections of objects and without duplicates.
2. No inherent order for objects is maintained. i.e: Order of object is not important.
3. Since it is based on a data structure known as a hash table so it has a highly optimized method for
    checking whether a specific element is contained in the set. 
4. Only instances of immutable types can be added to a Python set.
5. Sets are mutable data structure. 
Question : Why "set of lists" and "set of sets" is not possible, only set of tuples is feasible ?
Answer: Since only instances of immutable types can be added to a Python set so set of lists and set of sets are not feasible as sets and lists are mutable. However, tuples are immutable so set of tuples can be created.
Please note, objects such as integers, floating-point numbers, and character strings are eligible to be elements of a set. Since they are also immutable.
6. Python uses curly braces { and } as delimiters for a set.
Note: { } does not represent an empty set; it represents an empty dictionary.
   {17}, {'red','green'} are examples of set.
7. If an iterable parameter is sent to the constructor, then the set of distinct elements is produced.
    For example, set( hello ) produces set(['h', 'e', 'l', 'o']).  # Duplicates are not allowed in set

dict class:

In python dict class is represented by dictionary. Dictionary is a collection of key/value pairs. 
1. Keys are unique for the dictionary and only immutable objects (like strings) for the keys is 
    allowed. Values can be immutable or mutable. 
2. Order is not important in dictionary. 
3. An empty dictionary can be  created like dic_one = { } # An empty dictionary
   
ad_book = {'nikhil' : 'nikhilranjan@gmail.com', 'ranjan': 'ranjan@hotmail.com' }
    # An dictionary of name as Key and emil as  value 

4. Add and remove Key/value pair in dictionary :
    # Adding a key-value pair
       ad_book ['Rahul'] = 'rahulk@hotmail.com'  #Rahul is added
>>> print ad_book
{'ranjan': 'ranjan@hotmail.com', 'nikhil': 'nikhilranjan@gmail.com', 'Rahul': 'rahulk@hotmail.com'}
   # Deleting a key-value pair
      del ad_book ['Nikhil']
>>> print ad_book  # nikhil is deleted 
{'ranjan': 'ranjan@hotmail.com', 'Rahul': 'rahulk@hotmail.com'}

5. List of dictionary functions/methods are as follows :

Previous : Python data structure - sequence type Next: Functions in python

Feb 14, 2015

Reverse elements of a stack using stack operations and without using any extra space (In place)

Problem statement:- Given a stack filled with elements, write a program to reverse the elements of stack without using any extra space.

Algorithm:-

1. Do pop() operation and recursively call the same method until stack is empty and keep track of popped elements.
2. While returning from recursive method call, push popped elements in the stack and call method recursively to add elements at the bottom.
3. Since, stack follows LIFO protocol and so last popped element is push back in stack it bubble up to top of stack and elements of stack gets reversed.

Below is the sample code which reverse elements of linked list:- 
/* Recursive method to reverse elements of stack */
public void reverseStackElemetsWithStackOperations(CustomStack stack) {
if (stack.isEmplty()) {
return;
}
int temp = stack.pop();
/* call recursively to reach at bottom of stack */
reverseStackElemetsWithStackOperations(stack);
/* Call another recursive method to bubble up the bottom elements */
pushElementAtBottom(stack, temp);
}

/* Recursive call to this method - to bubble up the bottom most element to top*/
private void pushElementAtBottom(CustomStack stack, int data) {
if (stack.isEmplty()) {
stack.push(data);
return;
}
int temp = stack.pop();
/* recursive call with data to be inserted */
pushElementAtBottom(stack, data);
stack.push(temp);
}

Complete sample program to reverse elements of a stack without using any extra space and just stack operations:-

package com.devinline.stacks;

import com.devinline.stacks.SinglyLinkedListCustom.Node;

public class ReverseStackElements {
CustomStack stack;

public ReverseStackElements() {
stack = new CustomStack();
}

/* Recursive method to reverse elements of stack */
public void reverseStackElemetsWithStackOperations(CustomStack stack) {
if (stack.isEmplty()) {
return;
}
int temp = stack.pop();
/* call recursively to reach at bottom of stack */
reverseStackElemetsWithStackOperations(stack);
/* Call another recursive method to bubble up the bottom elements */
pushElementAtBottom(stack, temp);
}

/*
* Recursive call to this method - to bubble up the bottom most element to
* top
*/
private void pushElementAtBottom(CustomStack stack, int data) {
if (stack.isEmplty()) {
stack.push(data);
return;
}
int temp = stack.pop();
/* recursive call with data to be inserted */
pushElementAtBottom(stack, data);
stack.push(temp);
}

public static void main(String[] args) {
CustomStack stack = new CustomStack();
stack.push(20);
stack.push(21);
stack.push(24);
stack.push(40);
stack.push(111);
stack.push(784);
System.out.println("Stack before reversing its elements "
+ stack.toString());
new ReverseStackElements()
.reverseStackElemetsWithStackOperations(stack);
System.out.println("Stack after reversing its elements "
+ stack.toString());
}
}

class SinglyLinkedListCustom {
Node head = null;

public static Node createNewNode(int data) {
return new SinglyLinkedListCustom().new Node(data);
}

/* get first element */
public Node getFistNode() {
if (head == null)
return null;
else
return head;
}

/* Delete First node,return new head */
public Node deleteFirstNode() {
if (head == null)
return null;
Node temp = head.next;
Node delNode = head;
head.next = null;// garbage collected
head = temp;
return delNode;
}

/* Display data of nodes/iterate linked list */
public String iterateLinkedList() {
StringBuffer sbf = new StringBuffer();
Node current = head;
if (head != null) {
sbf.append("[");
while (current != null) {
sbf.append(current.data + " ");
current = current.next;
}
sbf.append(" ]");
} else {
System.out.println("Linked list is empty.");
}
return sbf.toString();

}

/* Add New node at start of linked list */
public void insertFirst(int data) {
Node newNode = createNewNode(data);
if (head == null) {
head = newNode;
} else {
newNode.next = head;
head = newNode;
}
}

class Node {
public int data;
public Node next;

public Node(int data) {
this.data = data;
this.next = null;
}
}

}

class CustomStack {
Node node = null;
int top = -1;
SinglyLinkedListCustom list;

public CustomStack() {
createStack();
}

void createStack() {
top = -1;
list = new SinglyLinkedListCustom();
}

int pop() {
if (list.getFistNode() != null) {
top--;
return list.deleteFirstNode().data;
} else
return -1;
}

void push(int data) {
list.insertFirst(data);
++top;
}

int peek() {
return list.getFistNode().data;
}

boolean isEmplty() {
return (top == -1) ? true : false;
}

public String toString() {
return list.iterateLinkedList();
}

public int getSize() {
return top + 1;
}
}

============Sample output===============
Stack before reversing its elements [784 111 40 24 21 20 ]
Stack after reversing its elements [20 21 24 40 111 784 ] ======================================

Feb 13, 2015

Textual description of firstImageUrl

Python Data Structures - Sequence types

Python has various inbuilt data structure like List, Set , Tuple, Dict which can be broadly classified in two categories.
  1. Sequence Types: The list, tuple, and str classes are sequence types in Python, representing a collection of values where order is significant. 
  2. Non- sequence types : The set, frozenset and dict classes non -sequence types in python, where order of elements is not important. 

list class: 

List is referring to each of the object being stored.
  1. The list is a referential structure which stores a sequence of references to the objects being stored. 
  2. Lists are array-based sequences and are zero-indexed.
  3. The items in a list need not be of the same type.Consider below example which indicates in a given list(list_1) are storing strings and numbers together.
    list_1 = ['physics', 'chemistry', 1997, 2000]; #String and Number both in the same list
    list_2 = [1, 2, 3, 4, 5 ];                  # Only Number in this list
    list_3 = ["a", "b", "c", "d"];    # One Character as string, Python does not have a
                                                    # separate class for characters; they are just strings with length one.
   4. Python list allows None to be present in the list. None is similar to NULL of Java.
   5. List is mutable data structure i.e:  list_1[0] = 'Math'  # first value is changed of list_1

Operations on list:-
 

List is very versatile data structure in python and it has various inbuilt methods to perform sorting , slicing, adding elements ,finding length, etc. Below we will see operation performed on list.
List creation:-
An empty list can be created as:  list = [ ]

Insert element in List: 
list.insert(<index>,<value>)
list.insert(0,"apple")
list.insert(1,"mango")
list.insert(0,"carrot")
list.insert(1,"banana")
now our modified list looks like :  ['apple', 'mango', 'carrot', 'banana']

Consider the following list  for all operations performed:
        fruits = ['apple', 'mango', 'carrot', 'banana']
  1. Find length of list : Python has inbuilt method len() to find length of list.
  2. >>> len(fruits)
    4
  3. Iteration/looping of list :  It displays each of the elements one by one as follows:
     'apple', 'mango', 'carrot', 'banana'
 for fruit in fruits: # fruits is the list to be iterated, fruit is variable pointing each of the object
     print fruit
   3. Adding an element in list using append : Python has append() method which adds object in list.
>>> fruits.append("Guava"); # Adding guava in list
>>> print fruits
['apple', 'mango', 'carrot', 'banana', 'guava']
  4.  Sorting list : python support sorting on list using sort() method.
>>> fruits.sort(); # Sorting list
>>> print fruits
['apple', 'banana', 'carrot', 'guava' ,'mango']
5. Index based access : Python's list can be accessed by index(Zero based index used). If we use negative value then it will count from end. For -1 it will give end of element of list.
>>> fruits[4] # apple is at index 0,
mango
>>> fruits[-1] # mango is at index 4 (end of list),
mango
>>> fruits[-3] # carrot is at third from last 
carrot
6. Slicing of list : Python's list can be sliced by giving< start:end> index which we want to retain(end index value is excluded).
>>>  fruits[0:3]
['apple', 'banana', 'carrot']
>>>  fruits[1:3] # No end index means go up to last
['banana', 'carrot', 'guava' ,'mango']
7. Concatenation of list  : Python's list can be added with one another.
>>> fruits = ['apple', 'banana', 'carrot', 'guava' ,'mango']
>>> fruits+=['None']
>>> fruits
['apple', 'banana', 'carrot', 'guava', 'mango', 'None']

8. List comprehension  : Python support concise way of applying an operation to a collection of objects. Iterating over an open file gives us sequence of its lines.
>>> import json
path = 'input.txt'
records = [json.loads(line) for line in open(path)]
Note :- If the data need to be stored has an identifiable structure, consider using something other than a list.

What's the difference between the list methods append() and extend()? - append vs extend 


append()- Appends object at end.
for example : fruits = ['apple', 'banana', 'carrot', 'guava' ,'mango']
fruits.append(['papaya', 'pineapple'])
print fruits
['apple', 'banana', 'carrot', 'guava' ,'mango',['papaya', 'pineapple']]

However, extend() - Eextends list by appending elements from the iterable.
in continuation of above example
fruits = ['apple', 'banana', 'carrot', 'guava' ,'mango',['papaya', 'pineapple']]
fruits.extend(['strawberry','grapes'])
print fruits
['apple', 'banana', 'carrot', 'guava' ,'mango',['papaya', 'pineapple'],'strawberry','grapes']

tuple class: 

Tuple in python is similar to list except tuple is immutable like strings i.e. you cannot modify tuples. An empty tuple can be created as follows: 
tuple_empty = ( )   #Tuples are defined by specifying items separated by commas within an optional                               # pair of parentheses. 
Lets consider following tuple :     
     animals = ('python', 'elephant', 'penguin')  
this tuple may be created without opening and closing braces like this :
     animals = 'python', 'elephant', 'penguin' 
 however, it is best practices to use opening and closing braces to indicate start and end of tuple.
1. length of tuple:  As in the list, length of tuple can be obtained using len() method.
     >>>len(animals)
     3
2. Create new tuple from existing tuple : New tuple is created from existing tuple like this :
     new_zoo = 'monkey', 'camel', animals # new_zoo tuple is created from existing tuple animals 
3. Tuple with 0 or 1 items : tuple with  0 items or empty tuple can be created as follows 
      tuple_zero_element = ( )
    tuple with 1 items needs special attention and it is created like this : 
      tuple_one_element = ( "one",)  # comma is mandatory to include in tuple with element
      Why comma is important to include ? : Because python can differentiate between a tuple and a 
      pair of parentheses surrounding the object in an expression.
4. tuple is immutable  : If we try to add(assign) or modify we get an error as follows
>>> str = (1,2,3) # tupe of 3 elements
>>> str[0]
1
>>> str[0] = 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
5. Concatenation of tuple : Python's tuple can be added with another tuple. New elements are not added, new tuple is added to existing one.
>>> animals = ('python', 'elephant', 'penguin')
>>> animals += ('cow',)
>>> animals
('python', 'elephant', 'penguin', 'cow')

Question: If tuple is immutable how we can add elements new elements in it without creating new tuple ? This is a hypothetical question since why we will take immutable data structure to modify it :)
Solution: Convert tuple into list , add elements into it and again convert back to tuple. Actually, we replaced the old tuple with new one, we did not modify old tuple.
>>> elements = ('Element-1', 'Element-2', 'Element-3')
>>> elements  = list(elements)
>>> elements.insert(3, 'Element-4')
>>> elements = tuple(elements)
>>> print elements
('Element-1', 'Element-2', 'Element-3', 'Element-4')

string class:

string in python is created by enclosing immutable sequence of characters in single or double quotes. For example : 
str_1 = "SAMPLE"  or 'SAMPLE'
#python string is an indexed sequence of characters.
Indexed sequence of characters
 1.Python string support escape character in order include quote delimiter or special character as part 
     of string. Example : 'Don\' t worry' , \' is used to make ' as part of the string.
2. Unicode characters can be included, such as 20\u20AC for representing string like "20 "€ .
3.  Python also support delimiter ''' or """, to enclose multi line strings and new line character can be
     embedded naturally.
>>> print("""Welcome to the GPA calculator.
... Please enter all your letter grades, one per line.
... Enter a blank line to designate the end.""")
Welcome to the GPA calculator.
Please enter all your letter grades, one per line.
Enter a blank line to designate the end.
4. Sub-string of a string obtained using slice method.
>>> var1 = 'Hello World!'
 >>> var1[1:5]  # slice string from position 1 to 5
'ello'
5. String special operators : Consider a = 'Hello' and b =  'Python',
    'Hello' + 'python' =  'Hellopython'
     'Hello'*2 = 'HelloHello'


6. String formatting operator(%): This operator is unique to strings and it is similar to printf() function of C language. Consider the following example,%s and %d is replaced by 'Nikhil' and 2000.
>>> print "My first name is %s and salary is %d" % ('Nikhil', 2000)
My first name is Nikhil and salary is 2000
Here is the list of complete set of symbols which can be used along with %

7. Built-in string methods : Python includes the following built-in methods to manipulate strings. Here is complete list of the same. 


Previous: Python fundamentals Next: Python Data Structures - Non Sequence types

Feb 7, 2015

Interview at Informatica Hyderabad- Senior software engineer

The interview process took one day and comprised of 4 technical round and 1 HR, just casual talk.
All interview rounds were mainly revolving around Data structure (DS) and algorithm/Java related stuff/ puzzles / problem solving.

First round (F2F):  Data structure and algorithm related questions
 1.It started with as usual first Question Can you introduce yourself and your work in previous
    companies ?
2. Can your explain different traversal we can have in tree DS ? Just as follow up question was asked
     to write the sequence of node visit for Inorder and Postorder, for a given tree.
3. Can you write sample code for iterative level order traversal for a binary tree ?
4. Consider a stack full of elements. Can you write a sample code to reverse the elements in-place
    (No extra space being used) ?
5.A famous puzzle question :  8 ball (7 with equal weight and 1 unequal) are placed a bag.In many
    weighing we can find odd ball ?
6. Some questions related to fundamentals of Heap DS.

Second round (F2F) :  Core java and its related technologies stack, SQL query related questions.
1. How do you rate your-self in java?  (Please give a convincing answer which you can justify)
2. He gave a sample code and asked what will be output. The fundamental concept behind this
    question was String immutability.
3. Have you used Interface and abstract class ? And on what basis did you decide to use it ?
    As a followup, there was a discussion on Importance of Interface in software development.
    Discussion on one of the SOLID principle, Always code to interface.
4. What is overloading and over-ridding, was asked to write some valid sample code.
     What happens in compile time binding and run time ? Fundamental differences.
     As a followup, many other questions related to over-ridding (Considering inheritance perspective).
5.  Do you thered in java and can you explain its life cycle ?
     what are different ways we can  create thread ? (Runnable and Thread class)
     When we will use Runnable and Thread ? Important point need to be mentioned for this question
      is that:  when we use Thread we  have full control over thread. I did not recall this point however
      reached at that point after getting some hint from him.
6. What are design patterns have you used?
     I mentioned few of them(factory, abstract factory, Front controller, MVC, signleton etc) .
     As a followup : Where I used it in my project ?  (Trick: Just mention only those you have really
     used and understands well)
7.  How can we make it possible to generate only one object of a class per JVM?
     Indirect way of asking write a sample code for singleton class.
     As a followup , some questions related to synchronization and  volatile keyword.
     Fundamental of Java memory model (JMM) is important to know to answer very clearly.
8.  One question from SQL query : write a query to find all employee who are also manager ?
     I did not do well here, I made it work with some help from interviewer, Answer to this question
     was related to self-join.

Third round (F2F) : Question from each of the technologies item mentioned in my resume, and where I used. And Data structure related stuff.
1. How we write Junit code ?   Sample code for a working junit.
    What are the annotations we have in Junit?
    As a followup : how these annotation works ?
2. Dependency injection ? How it is helpful ?
    How annotation are good or bad with respect to Dependency injection.
3.Abstract data structure ?
   Implement stack using linkedlist ? A working sample code?
   As a followup discussed coding standard? Why this , why not this?
    How it will affect , if we change the visibility and how performance will improve ?
4. Where did I use Hibernate ? (Hibernate was mentioned in my resume)
     How it makes life of developer easy?
     Some fundamental questions from hibernate.
And many more questions from my projects mentioned my resume.
Moral of the story : Do not lies with resume , it reflects what you are.

Fourth round (F2F): Java related stuff / Puzzle   
1. Some fundamental questions from exception handling?
    Sample code for the same.
2. equls()/hashCode() contract ?  How they are important ?
3. How hashMap internally works ? And followup questions how it is diff from other collections ?
4. A sample code was given to predict output :
     What will happen when we put two return statement : one in try and other in finally ?
     As a followup : why finally value is returned ? What happens to try return statement ?
     I answered it , but not convincing.
5.  Puzzle: In wine bottle, we find big apple inside, with very small opening at top. How apple can be
     placed inside?

Fifth round (F2F): HR discussion
Normal HR questions .
Most difficult question , why I want to change. Its just 1.5 years at Oracle.
Finally, shows over!!


Related post : 
1. Interview experience at Oracle India Pvt Ltd- Application engineer 2

Interview at Informatica Hyderabad- Senior software engineer

The interview process took one day and comprised of 4 technical round and 1 HR, just casual talk.
All interview rounds were mainly revolving around Data structure (DS) and algorithm/Java related stuff/ puzzles / problem solving.First round (F2F):  Data structure and algorithm related questions
 1.It started with as usual first Question Can you introduce yourself and your work in previous  companies ?
2. Can your explain different traversal we can have in tree DS ? Just as follow up question was asked  to write the sequence of node visit for Inorder and Postorder, for a given tree.
3. Can you write sample code for iterative level order traversal for a binary tree ?
4. Consider a stack full of elements. Can you write a sample code to reverse the elements in-place  (No extra space being used) ?
5.A famous puzzle question :  8 ball (7 with equal weight and 1 unequal) are placed a bag.In many  weighing we can find odd ball ?
6. Some questions related to fundamentals of Heap DS.Second round (F2F) :  Core java and its related technologies stack, SQL query related questions.
1. How do you rate your-self in java?  (Please give a convincing answer which you can justify)
2. He gave a sample code and asked what will be output. The fundamental concept behind this  question was String immutability.
3. Have you used Interface and abstract class ? And on what basis did you decide to use it ? As a followup, there was a discussion on Importance of Interface in software development.Discussion on one of the SOLID principle, Always code to interface.
4. What is overloading and over-ridding, was asked to write some valid sample code.What happens in compile time binding and run time ? Fundamental differences. As a followup, many other questions related to over-ridding (Considering inheritance perspective).
5. Do you thered in java and can you explain its life cycle ? what are different ways we can  create thread ? (Runnable and Thread class)When we will use Runnable and Thread ? Important point need to be mentioned for this question is that: when we use Thread we have full control over thread. I did not recall this point however 
reached at that point after getting some hint from him.
6. What are design patterns have you used?I mentioned few of them(factory, abstract factory, Front controller, MVC, signleton etc) .As a followup : Where I used it in my project ?  (Trick: Just mention only those you have really used and understands well)
7. How can we make it possible to generate only one object of a class per JVM?Indirect way of asking write a sample code for singleton class.As a followup , some questions related to synchronization and  volatile keyword.Fundamental of Java memory model (JMM) is important to know to answer very clearly.
8. One question from SQL query : write a query to find all employee who are also manager ?I did not do well here, I made it work with some help from interviewer, Answer to this question was related to self-join.Third round (F2F) : Question from each of the technologies item mentioned in my resume, and where I used. And Data structure related stuff.
1. How we write Junit code ?   Sample code for a working junit.What are the annotations we have in Junit?As a followup : how these annotation works ?
2. Dependency injection ? How it is helpful ?How annotation are good or bad with respect to Dependency injection.
3. Abstract data structure ?Implement stack using linkedlist ? A working sample code? As a followup discussed coding standard? Why this , why not this?
How it will affect , if we change the visibility and how performance will improve ?
4. Where did I use Hibernate ? (Hibernate was mentioned in my resume)
How it makes life of developer easy? Some fundamental questions from hibernate.
And many more questions from my projects mentioned my resume.
Moral of the story : Do not lies with resume , it reflects what you are. :)
Fourth round (F2F)Java related stuff / Puzzle    
1. Some fundamental questions from exception handling?Sample code for the same.
2. equls()/hashCode() contract ?  How they are important ?
3. How hashMap internally works ? And followup questions how it is diff from other collections ?
4. A sample code was given to predict output :
 What will happen when we put two return statement : one in try and other in finally ?
  As a followup : why finally value is returned ? What happens to try return statement ?
  I answered it , but not convincing.
5.Puzzle: In wine bottle, we find big apple inside, with very small opening at top. How apple can be 
  placed inside?Fifth round (F2F): HR discussion
Normal HR questions .
Most difficult question , why I want to change. Its just 1.5 years at Oracle.

Finally, shows over with good news!!