Top 100 Java Interview Questions
Top 100 Java Interview Questions
Strings
○ String: immutable
19.equals() vs hashCode()?
equals() checks equality, hashCode() provides hash value for hashing structures.
20."abc" + 1 + 2 vs 1 + 2 + "abc"?
○ "abc" + 1 + 2 → "abc12"
○ 1 + 2 + "abc" → "3abc"
Collections
○ Set: No duplicates.
24.ArrayList vs LinkedList?
ArrayList is faster in access; LinkedList is better for insertion/deletion.
25.HashSet vs TreeSet?
HashSet is unordered, TreeSet is sorted.
28.HashMap vs Hashtable?
HashMap is non-synchronized; Hashtable is synchronized.
29.What is ConcurrentHashMap?
Thread-safe version of HashMap without locking entire map.
30.Fail-fast vs fail-safe?
Exception Handling
36.What is multithreading?
Ability of CPU to execute multiple threads simultaneously.
40.What is synchronization?
Prevents thread interference by locking shared resources.
42.What is a deadlock?
Two or more threads waiting on each other indefinitely for resources.
Inner Classes