java interview questions and answers

Core java interview questions and answers for beginners and professionals on Basics, OOPs, Methods, Overloading, Overriding, Inheritance, Polymorphism, Interfaces, Packages, Abstract classes, String handling, Exception handling, IO, Collections, Multithreading, Serialization and more. Java interview questions why java is platform independent and jvm is platform dependent? List any five features of java? What all memory areas … Read more

Garbage collector in java

The garbage collector is a program which runs on the Java Virtual Machine which gets rid of objects which are not being used by a Java application anymore. It is a form of automatic memory management.

Comparable vs Comparator in java

Both Comparable and Comparator interfaces are used to perform sorting operation on collection of objects. Java also provide few in-build methods to sort array of primitive types or array/list of Wrapper class elements. But when it comes to the sorting of custom class objects then java.lang.Comparable and java.util.Comparator interfaces are used. Example: sort array of … Read more

Collection vs Collections in java

Both Collection and Collections in Java, have some similarities like Both (Collection and Collections) are part of the Java Collections Framework. Both (Collection and Collections) are present in java.util package. Both (Collection and Collections) are added to jdk in java version 1.2 Besides these similarities, they have few differences also. Collection Collection interface represents the … Read more

HashSet vs HashMap vs HashTable in java

HashMap and Hashtable stores values in key-value pair. HashSet contains unique elements and HashMap, HashTable contains unique keys. Having these similarities they have some differences also.   HashSet: HashSet inherits AbstractSet class and implements Set interface. Set objects are always unique and no duplicate objects are allowed. One null key value is allowed. The hashing … Read more

HashMap vs LinkedHashMap vs TreeMap vs HashTable in Java

All four (HashMap, LinkedHashMap, TreeMap, HashTable) in Java, implements the Map interface. With this similarity, they have some differences also. Map Hierarchy: HashMap: HashMap contains the objects in key-value pair form. It extends AbstractMap class and implements the Map interface. It does not maintains any order for it’s objects. Duplicate keys are not allowed in … Read more

HashSet vs LinkedHashSet vs TreeSet In Java

All HashSet, LinkedHashSet, and TreeSet In Java have some similarities, Like: Can not contain duplicate items: All HashSet, LinkedHashSet, and TreeSet are implements Set interface. So they are not allowed to contains duplicates elements or objects. Not Thread Safe: All three are not synchronized and hence not Thread safe. Cloneable and Serializable: All three (HashSet, … Read more