Friday, February 24, 2017

Core Java Interview Question

Comparable vs Comparator

Iterator Vs Iterable
http://davisfiore.co.uk/?q=node/123


HashSet Implementation
http://javaconceptoftheday.com/how-hashset-works-internally-in-java/

Hash Map Implementation

What is time complexity ?collision ..bucket finding ...linked list or RB Tree...hashfunction.  equals and hashcode
what type of key to be used for key in hashmap
  • The concept of hashing
  • Collision resolution in HashMap
  • Use of equals () and hashCode () and their importance in HashMap?
  • The benefit of the immutable object?
  • Race condition on HashMap  in Java
  • Resizing of Java HashMap


Read more: http://javarevisited.blogspot.com/2011/02/how-hashmap-works-in-java.html#ixzz4XeXMiAOL


HashMap Changes in JDK 1.7 and JDK 1.8

There is some performance improvement done on HashMap and ArrayList from JDK 1.7, which reduce memory consumption. Due to this empty Map are lazily initialized and will cost you less memory. Earlier, when you create HashMap e.g. new HashMap() it automatically creates an array of default length e.g. 16. After some research, Java team found that most of this Map are temporary and never use that many elements, and only end up wasting memory. Also, From JDK 1.8 onwards HashMap has introduced an improved strategy to deal with high collision rate. Since a poor hash function e.g. which always return location of same bucket, can turn a HashMap into linked list, i.e. converting get() method to perform in O(n) instead of O(1) and someone can take advantage of this fact, Java now internally replace linked list to a binary true once certain threshold is breached. This ensures performance or order O(log(n)) even in the worst case where a hash function is not distributing keys properly.


ConcurrentHashMap

http://javahungry.blogspot.com/2015/02/how-concurrenthashmap-works-in-java-internal-implementation.html


ArrayList Vs Linked List
http://javaconceptoftheday.com/arraylist-vs-linkedlist-java/

HashSet vs LinkedHashSet Vs TreeSet
http://javaconceptoftheday.com/hashset-vs-linkedhashset-vs-treeset-in-java/

Serialization
serialversionuid = 1L
The serialVersionUID is a universal version identifier for a Serializable class. Deserialization uses this number to ensure that a loaded class corresponds exactly to a serialized object. If no match is found, then an InvalidClassException is thrown. 


Synchronization

Differences Between wait() And sleep() Methods In Java http://javaconceptoftheday.com/difference-between-wait-and-sleep-methods-in-java/

Difference between DI and IOC

Dependency Injection(DI):
Dependency injection generally means passing a dependent object as a parameter to a method, rather than having the method create the dependent object
What it means in practice is that the method does not have a direct dependency on a particular implementation; any implementation that meets the requirements can be passed as a parameter.


Inversion of Control(IoC) Container:
This is common characteristic of frameworks, IOC manages java objects 
– from instantiation to destruction through its BeanFactory. 
-Java components that are instantiated by the IoC container are called beans, and the IoC container manages a bean's scope, lifecycle events, and any AOP features for which it has been configured and coded



Sleep,yield,join

This instance method causes the currently running thread to join the end of the thread “t”. You will get it after this example…
Executor framework
fork-join framework in Java?

Thrashing in Java
Types of Garbage collector
Spring with design pattern
Spring with Webservices


To read about cocurrency n cover all topic
http://tutorials.jenkov.com/java-util-concurrent/executorservice.html





String reversal program without using any function-:

public class Reverse
{
static int i,c=0,res;

static void stringreverse(String s)
{
char ch[]=new char[s.length()];
for(i=0;i < s.length();i++)
ch[i]=s.charAt(i);
for(i=s.length()-1;i>=0;i--)
System.out.print(ch[i]);
}

public static void main (String args[])
{
System.out.println("Original String is : ");
System.out.println("my name is lakhan ");
Reverse.stringreverse(" my name is lakhan ");
}
}


Insertions and Removals from any position in the LinkedList are faster than the ArrayList. Because there is no need to shift the elements after every insertion and removal. Only references of previous and next elements are to be changed.


Retrieval of elements in LinkedList is very slow compared to ArrayList. Because to retrieve an element, you have to traverse from beginning or end (Whichever is closer to that element) to reach that element.



Design patternhttp://www.journaldev.com/171/thread-safety-in-java-singleton-classes-with-example-code


Deep cloing and shallow cloning
refactoring

No comments:

Post a Comment

Interview Prep: Java full stack

 SOLID principle :  https://www.educative.io/answers/what-are-the-solid-principles-in-java Design Pattern:  Creational:  https://medium.com...