Friday, December 29, 2017

Java Interview Qustions and topics ..

Few sites for java ..

https://www.journaldev.com/
http://javarevisited.blogspot.in/
java67.com

hot topics - will be asked in almost every interivew  ...
singleton , immutable, cloning , serialization,
producer consumer multithreading problem,
java 8 features,
polimorphism - overloading, overriding in very deep
interface vs abstract class
oops concepts with examples
print even odd using two threads
collection , hashmap - equals and hashcode
Jvm architecture,
volatile and transient keyword
garbage collection
try-catch-finally
Design patterns - Singleton, Factory, Builder, Decorator, Observer ( these are sufficient )

my interivew questions --
https://anytechnicalnotes.blogspot.in/?m=1


Monday, November 6, 2017

Accolite Interview - Set 2

Company Name - Accolite Bangalore

Date - 6 - 11 - 2017

Round - 1st Telephonic, questions are mostly in Java

Questions -

1. Reversing of linked list
2. Sorted Rotated array. find minimum element.
3. Binary search algorithm
4. Volatie keyword use and drawbacks - not useful in multithreading
5. Immuatable classes uses and how to create one
6. All method to create singleton and uses of each
  . Uses of singleton in code ( provide singleentry point , window manager, logger class)
7. Generics uses
8. Print even and odd sequence using two threads
9. Factory method - how to create and uses
10. how hashmap works internally, put and get method
( how string makes good key in hashmap - coz they are immuatable and they do not calculate hash value again in get method instead they get it from string pool)
11. Annotations in Java
12.


Wednesday, September 27, 2017

Interview questions to review

Digit to word converter 
http://javahungry.blogspot.com/2014/05/convert-math-number-to-equivalent-readable-word-in-java-code-with-example.html 



file - find and replace string in file 
large file , moving files scrolling

Very Common interview questions- must know
Merging k sorted list or arrays
Search in dictonary for a word
How will you implement dictonary
find i, j and k where i2 + j2 = sum2
find i, j and k where i + j = sum
find 2/3 element whose sum is close to zero
Sort array of 0 and 1 or 0 , 1 and 2
String anagrams
Permutation of string
First repeating/ Non repeating charactor
external sorting , counting sort, bucket sort and radix sort questions
quicksort, heapsort and mergesort
topological sort
BFS, DFS
left, right, bottom, top view of the binary tree

Longest common substring
longest common subsequence length
longest palindrom substring/ subsequence



Subex interview

Company Name - Subex
Data - Aug, 2017
Rounds - Face to Fcae

Round 1 -
Core java full

Round 2
1. what happens if you import multiple jar files having same class structure(fully qualified name is aame)
2. what java version you use
3. immutable classes other than string
4. stock problem - find maximum profit of buy and selling
5. Singleton

Apponomic Interview

Company Name - Apponomic 


Date - 25 - 9 - 2017

Round - 1st Telephonic

Questions -

1. Suppose you want to repeat a time in every 5 hours, How you will achieve it in multi threading.
(using Timer Task )
2. what does volatile keyword do and how 
3. Difference between synchronized and volatile
4. how we make sure a method does not accessed by more than 10 threads at a time
    ( newFixedthreadPool(10), call submit() )
5. can static method be synchronised. what happens when you put sync keyword in static method
6. how to synchronised a method using multiple blocks 
( divide in multiple blocks and use lock object) 
7. what is hashcode()
8. internal working of hashmap
9. A global counter variable - should be accessed by multiple threads and give proper value
    (take atomic variable) 
10  Questions on java.util.concurrent package like below
11. problems in hashmap
12. How concurrenthashmap works
13. how concurrenthashmap achieve multiple concurrency level
14. what all collections you used
15  what is queue and about priority queues
16. how to check if binary tree is BST or Not
17. difference between interfaces and abstract classes
18. LRU cache implement

Accolite Interview

Company Name - Accolite Bangalore

Date - 25 - 9 - 2017

Round - 1st Telephonic, questions are mostly in Java

Questions -

1. Internal working of HashMap
2. Cycle detection in LinkedList(Floyd algo)
3. Overriding Static methods in Java - no overriding in static methods, will be called as per object ref.
4. Overridign methods in java - derived method will hide base methods
5. Overriding variables in java - Not possible we simple get base variable

Examples -
class Parent{ int x, void method() { }}
class Child extends Parent { int y, void method(){ }}

Parent p = new child();
sysout(p.x) // ok
sysout(p.y) // CE
sysout(p.method()) // method in derived class

imagin method in decleared static in base or child any - Now its not overridden
p.staticmethod() // calls to parent class method since object decleared as parent class


6. Public Static Void main(String [] arg)
6. What if you change public and static place - No problem
7. What if you change return type of main method(it will be overloaded, give us RE- Main method not found)
8. try , catch , finally - remember finally always get called)
9. immutable classes
10. clone method (deep and shallow copy)
11. Two way hashmap design

Sapient Interview

Company Name - Sapient Corporation

Date - 20 - 9 - 1017

Round - 1st Telephonic, questions are mostly in Java

Questions -


1. OOPS concepts and examples
2. Solid principles ( SOLID)
3. Singleton, (write code using volatile and double checking of null and explain why use double checking),
4. how to break singleton pattern (reflextion, serialize , overriding clone method)
5. Tell me about enum
6. Expection heriercy and how to create custom exceptions
7. Immuatable class , why, how you write immuatable classes
8. Deep and shaloow copy in cloning (differnce and effect in immutable classes if we use shallow in place of deep copy)
9. how set internally implemented ( set is internally implemented using map , and in place of value , it uses random object)
10. which all design patterns you know(singleton , adaptor, factory, observer, decorator, builder are common ( must know 2 -3 and example in code )
11. What is Marker interface (Interface with not method) ,
12. Why we need marker interface when it has no method
13. Static method override (We don't actually override them)
14. JDBC working steps
15. Java Generics - Example of what happens if you don't use generics
16. hashcode() and equals() methods, why we need to override equals
17. Comparator Interface in java
18. Write program to check if Number/String is palindrom or not
19. Take bank account, design system where person has multiple accounds in Same bank

Monday, July 10, 2017

Bottom, Top, Left and right view of Tree

class Max{
int max_level ;
}

class Print{
//Max max_level = new Max();
int max_level = 0 ;

// left and right view can be obtained using queue ( level order traversals )

void leftViewUtil(Node node, int level)
    {
        // Base Case
        if (node==null) return;
        // If this is the first node of its level
        if (max_level < level)
        {
// print first max level in from left side.
            System.out.print(" " + node.data);
            max_level = level;
        }
        // Recur for left and right subtrees
        leftViewUtil(node.left, level+1);
        leftViewUtil(node.right, level+1);
    }


void rightViewUtil(Node node, int level) {
if(node == null) return;
if(max_level < level) {
sysout(node.data);
max_level = level;
}
rightViewUtil(node.right, level+1);
rightViewUtil(node.left, level+1);
}

BottomView / TopView : -


// Java Program to print Bottom View of Binary Tree
import java.util.*;
import java.util.Map.Entry;
// Tree node class
class Node
{
    int data; //data of the node
    int hd; //horizontal distance of the node
    Node left, right; //left and right references
    // Constructor of tree node
    public Node(int key)
    {
        data = key;
        hd = Integer.MAX_VALUE;
        left = right = null;
    }
}

//Tree class
class Tree
{
    Node root; //root node of tree
    // Default constructor
    public Tree() {}
    // Parameterized tree constructor
    public Tree(Node node)
    {
        root = node;
    }
    // Method that prints the bottom view.
    public void bottomView()
    {
        if (root == null)
            return;
        // Initialize a variable 'hd' with 0 for the root element.
        int hd = 0;
        // TreeMap which stores key value pair sorted on key value
        Map map = new TreeMap<>();
         // Queue to store tree nodes in level order traversal
        Queue queue = new LinkedList();
        // Assign initialized horizontal distance value to root
        // node and add it to the queue.
        root.hd = hd;
        queue.add(root);
        // Loop until the queue is empty (standard level order loop)
        while (!queue.isEmpty())
        {
            Node temp = queue.remove();
            // Extract the horizontal distance value from the
            // dequeued tree node.
            hd = temp.hd;
            // Put the dequeued tree node to TreeMap having key
            // as horizontal distance. Every time we find a node
            // having same horizontal distance we need to replace
            // the data in the map.
            map.put(hd, temp.data);
            // If the dequeued node has a left child add it to the
            // queue with a horizontal distance hd-1.
            if (temp.left != null)
            {
                temp.left.hd = hd-1;
                queue.add(temp.left);
            }
            // If the dequeued node has a left child add it to the
            // queue with a horizontal distance hd+1.
            if (temp.right != null)
            {
                temp.right.hd = hd+1;
                queue.add(temp.right);
            }
        }
        // Extract the entries of map into a set to traverse
        // an iterator over that.
        Set> set = map.entrySet();
        // Make an iterator
        Iterator> iterator = set.iterator();
        // Traverse the map elements using the iterator.
        while (iterator.hasNext())
        {
            Map.Entry me = iterator.next();
            System.out.print(me.getValue()+" ");
        }
    }
}
// Main driver class
public class BottomView
{
    public static void main(String[] args)
    {
        Node root = new Node(20);
        root.left = new Node(8);
        root.right = new Node(22);
        root.left.left = new Node(5);
        root.left.right = new Node(3);
        root.right.left = new Node(4);
        root.right.right = new Node(25);
        root.left.right.left = new Node(10);
        root.left.right.right = new Node(14);
        Tree tree = new Tree(root);
        System.out.println("Bottom view of the given binary tree:");
        tree.bottomView();
    }
}


Vertical sum of Binary Tree:

// Method to be called by the consumer classes
    // like Main class
    public void VerticalSumMain() { VerticalSum(root); }
  
    // A wrapper over VerticalSumUtil()
    private void VerticalSum(TreeNode root) {
  
        // base case
        if (root == null) { return; }
  
        // Creates an empty hashMap hM
        HashMap hM =
                   new HashMap();
  
        // Calls the VerticalSumUtil() to store the
        // vertical sum values in hM
        VerticalSumUtil(root, 0, hM);
  
        // Prints the values stored by VerticalSumUtil()
        if (hM != null) {
            System.out.println(hM.entrySet());
        }
    }
  
    // Traverses the tree in Inoorder form and builds
    // a hashMap hM that contains the vertical sum
    private void VerticalSumUtil(TreeNode root, int hD,
                         HashMap hM) {
  
        // base case
        if (root == null) {  return; }
  
        // Store the values in hM for left subtree
        VerticalSumUtil(root.left(), hD - 1, hM);
  
        // Update vertical sum for hD of this node
        int prevSum = (hM.get(hD) == null) ? 0 : hM.get(hD);
        hM.put(hD, prevSum + root.key());
  
        // Store the values in hM for right subtree
        VerticalSumUtil(root.right(), hD + 1, hM);
    }















x

Ericsson Interview

Round 1 : mostly Java 1. SingleTon - In multiple servers in a culstered envirnment. 2. HashMap put method internally, how that works 3....