Hey Dev Community! 👋

Whether you're just getting started with Java or you've been in the game for a while, there are always little things that can trip you , quirks, subtleties, and things that just don’t work the way you'd expect.

Let’s go through a friendly, developer-first list of Java features and differences that many developers overlook. This list is here to save you from hours of debugging and head-scratching. And please, share your own gotchas in the comments. Let's help each other out!

1. == vs .equals()

  • == compares object references.
  • .equals() compares values.
String a = new String("hello");
String b = new String("hello");
System.out.println(a == b);      // false
System.out.println(a.equals(b)); // true

📎 Reference: Java Equals and HashCode

2. String (double quotes) vs char (single quotes)

  • Use double quotes (") for String.
  • Use single quotes (') for char.
char letter = 'A';
String word = "A"; // Not the same!

🔍 A common beginner error is to confuse the two.

3. ArrayList vs LinkedList

  • ArrayList is faster for access.
  • LinkedList is faster for insertion/removal in the middle.

📎 ArrayList vs LinkedList Performance

4. static vs non-static

  • static = belongs to the class.
  • Non-static = belongs to the instance.
static int count;
int instanceVar;

5. final, finally, finalize()

  • final: can't be changed.
  • finally: used in try blocks.
  • finalize(): method called before garbage collection (now deprecated).

📎 Java Final Keyword

6. String vs StringBuilder vs StringBuffer

  • String: immutable.
  • StringBuilder: mutable (not thread-safe).
  • StringBuffer: mutable (thread-safe).

📎 Difference Between String, StringBuilder, and StringBuffer

7. Checked vs Unchecked Exceptions

  • Checked: must be handled (e.g. IOException).
  • Unchecked: runtime errors (NullPointerException).
try {
    // risky code
} catch(IOException e) {
    // must catch!
}

📎 Checked vs Unchecked Exceptions

8. Primitive vs Wrapper Types

  • int vs Integer, boolean vs Boolean

🔍 Wrappers can be null, primitives can't.

Integer x = null;
int y = x; // NullPointerException!

9. Constructors vs Methods

  • Constructor: same name as class, no return type.
  • Method: can have any name and return type.

10. this() vs super()

  • this() calls a constructor in the same class.
  • super() calls a constructor in the parent class.
public Child() {
    super(); // calls parent constructor
    this.setup();
}

11. Inheritance vs Composition

  • Inheritance: is-a
  • Composition: has-a

🔍 Prefer composition for flexibility.

12. interface vs abstract class

  • Interface: only method signatures (until Java 8 added default methods).
  • Abstract class: can have implementations, fields.

📎 Abstract Class vs Interface

13. var keyword (Java 10+)

  • var enables type inference.
var name = "Kudzai"; // compiler infers String

Still statically typed! var just helps reduce verbosity.

14. Enhanced switch (Java 14+)

String result = switch(day) {
    case MONDAY -> "Start";
    case FRIDAY -> "End";
    default -> "Midweek";
};

📎 Switch Expressions

15. Lambda Expressions (Java 8+)

List<String> list = Arrays.asList("a", "b");
list.forEach(item -> System.out.println(item));

📎 Lambdas in Java

16. Streams API

  • Functional-style processing of collections.
list.stream().filter(e -> e.length() > 3).collect(Collectors.toList());

📎 Java Streams

17. Method Overloading vs Overriding

  • Overloading: same method name, different params.
  • Overriding: same method signature in subclass.

18. Java Memory Model (Heap vs Stack)

  • Stack: stores method calls and local variables.
  • Heap: stores objects.

19. Optional (Java 8+)

  • Avoid null by using Optional.
Optional<String> name = Optional.of("Kudzai");
name.ifPresent(System.out::println);

📎 Java Optional

20. Access Modifiers

  • public, protected, private, (default/package-private)

Know their scope well — it's essential for clean API design.

21. Serialization and transient

  • transient fields are not serialized.
private transient String password;

📎 Java Serialization Guide

✨ Your Turn!

These are just a few of the Java quirks, differences, and design choices that are easy to miss.

👉 What tripped you up when you were learning Java?
👉 Did we miss your favorite gotcha?
👉 Have a tip or experience to share?

Now, it's a high time we need to let’s learn from each other. 💬

Thanks for reading, and happy coding!