Comparison and equality
Use == for primitives, but for String and objects compare with .equals():
String a = "hello";
String b = new String("hello");
System.out.println(a == b); // false (different objects)
System.out.println(a.equals(b)); // true (same content)
== compares references for objects; .equals() compares logical content.
Short-circuit evaluation
With &&, if the left side is false the right side never runs. With ||, if the left side is true the right side never runs. This is handy for null checks:
if (str != null && str.length() > 5) {
// safe: short-circuits before calling length()
}
Without short-circuiting, str.length() would throw a NullPointerException.