Top 10 Java confusion questions like this (very high interview probability)
Here are Top 10 Java Confusion Questions (very high interview probability) β explained clearly with examples π 1. == vs .equals() String a = new String("Java");String b =β¦
Here are Top 10 Java Confusion Questions (very high interview probability) β explained clearly with examples π
1. == vs .equals()
String a = new String("Java");
String b = new String("Java");System.out.println(a == b); // false β
System.out.println(a.equals(b)); // true β
π Key Point
==β reference comparison.equals()β value comparison
2. final vs finally vs finalize()
finalβ keyword (constant, no override)finallyβ block (always executes)finalize()β GC method (deprecated β)
3. ArrayList vs Array
- Array β fixed size
ArrayListβ dynamic
π Interview line:
βArrayList resizes internally, array does not.β
4. HashMap vs Hashtable
HashMapβ not synchronizedHashtableβ synchronized (legacy)
5. String vs StringBuilder vs StringBuffer
| Type | Thread Safe | Mutable |
|---|---|---|
| String | β | β |
| StringBuilder | β | β |
| StringBuffer | β | β |
6. Comparable vs Comparator
Comparableβ natural sorting (compareTo)Comparatorβ custom sorting (compare)
7. checked vs unchecked exception
- Checked β compile-time (IOException)
- Unchecked β runtime (NullPointerException)
8. overloading vs overriding
- Overloading β same method name, different params
- Overriding β same method in child class
9. this vs super
thisβ current classsuperβ parent class
10. length vs length() vs count()
Array β length
String β length()
Stream β count()
Bonus (Very Tricky)
Arrays.asList() Trap
List<int[]> list = Arrays.asList(new int[]{1,2,3});
π Not List<Integer> β
π‘ How to Use in Interview
If asked:
π βTell some Java differencesβ
Pick any 2β3 and explain deeply instead of listing all.
π Pro Tip
Focus most on:
== vs equalsArrayList vs ArrayComparable vs ComparatorString vs StringBuilder
π These are asked almost every time