Tag: Core java interview
What is WeakHashMap in Java? It is exactly same as HashMap except for the following difference:- In the case of HashMap even though object doesn’t have any reference it is not eligible for GC. If it is associated with HashMap that is HashMap dominates Garbage collector. But in the . . . Read more
What is IdentityHashMap? In journal == operator meant for reference comparison (address comparison) and equals() method meant for content comparison. It is exactly same as HashMap(including methods and constructors) except the following difference. In the case of normal HashMap, JVM will use .equals() method to identify duplicates keys, which is meant for content . . . Read more
Java Set is a collection of elements (Or objects) that contains no duplicate elements. Java Set is an interface that extends Collection interface. Unlike List, Java Set is NOT an ordered collection, it’s elements does NOT have a particular order. Java Set does NOT provide a control over the position where you . . . Read more
Explain ArrayList and difference between ArrayList and Vector? ArrayList is a class, that uses a dynamic array for storing the elements. It extends AbstractList class and implements List interface. The underlying data structure is a Resizable array or growable array. Duplicates are allowed. Insertion order is preserved. Heterogeneous objects are . . . Read more
How many ways can we make an object eligible for GC? Even through programmer is not responsible to destroy useless objects it is highly recommended to make an object eligible for GC. If it no longer a requirement. The garbage collector will look for objects which aren’t being used anymore . . . Read more
Difference between yield(), join(), sleep() method? We can prevent thread execution by using the following method. yield() join() sleep() public static native void yield()Â yield() method causes to pause current executing thread to give the chance for waiting threads of the same priority. If there is no waiting thread or . . . Read more
Explain thread priority and what is default thread priority? Every thread in java has some priority. It may be default priority generated by JVM or customized priority provided by the programmer. The valid range of thread priorities is 1-10. where 1 is min priority and 10 is the max priority. . . . Read more
Difference between final & finally & finalize keyword? The keyword final is an access modifier, finally is a block and finalize is a method. The keyword final is applicable to the classes, variables and methods of the classes finally is a block associated with the try catch block that is . . . Read more
What is finally block in Java? It is not recommended to maintain cleanup code inside try block because there is no guarantee for the execution of every statement inside the try block. It is not recommended to maintain cleanup code inside the catch block. Because if there is no exception . . . Read more
What is the checked and unchecked exception? The exceptions which are checked by the compiler for smooth execution of the program are called checked exceptions. In our program, if there is a chance of raising checked exception then compulsory we should handle that checked exception either by try-catch or by . . . Read more