Does Hashtable allows null key or value?
In Java, Hashtable does not allow null key or value.
Can two objects which are not equal can have same hash code?
Yes, two object which are not equal by
equals() method can still return same hash code.
What is the difference between ArrayList and Vector?
What is the difference between ArrayList and LinkedList?
Consider the following statements:-
final Map oMap = new HashMap(); oMap.put("1",1); oMap.put("2",2); oMap.put("3",3);
Is it correct? How?
Yes. Because final marks to reference, not to the object. You can't make the reference point to a different hash map. But you can do anything to that object, including adding and removing things.
Can static methods be synchronized?
Yes. As static methods are class methods and have only one copy of static data for the class, only one lock for the entire class is required. Every class in java is represented by java.lang.Class instance. The lock on this instance is used to synchronize the static methods.
Can two threads call two different static synchronized methods of the same class?
No. The static synchronized methods of the same class always block each other as only one lock per class exists. So no two static synchronized methods can execute at the same time.
Why Runtime exceptions were categorized as unchecked exceptions?
Runtime exceptions represent problems that are detected by the runtime system.
This includes arithmetic exceptions, pointer exception and indexing exceptions.
Runtime exceptions can occur anywhere in the program and in a typical program can be very numerous.
Having to add runtime exceptions in every method would reduce a program's clarity.
Thus the compiler does not require that you catch or specify runtime exception.
NOTE:- If a client can reasonably be expected to recover from an exception, make it a checked exception. If a client can't do anything to recover from the exception, make it an unchecked exception.
If you are implementing
equals() method, which other method you need to override?
HashCode method. As per Java specification overriding one and not other will break the contract between them.
Refer http://modernpathshala.com/Article/2/hashcode-and-equals-method-in-java to understand relationship between hashcode and equals method in detail.
What is the contract between hashCode and equals method?