Try this 🤔
Integer a = 100; Integer b = 100;
System.out.println( a == b) // true
Integer x = 200; Integer y = 200; // false
you know why?! #Java#Programming 👇
The Tricky Part: == vs .equals()
This is where == gets tricky! == checks if two references point to the exact same object. For numbers in the pool, they often do. Outside the pool, even if values are identical, they're separate objects. Always use .equals() for value comparison
Key Takeaways:
Java's String Pool reuses literals.
new String() always creates new objects.
intern() forces pooling.
== vs .equals() is crucial for comparison
Classic Gotcha: `==` vs `.equals()`
Comparing user input (often dynamically created Strings) with constant literals using == will likely fail! ❌ Always use .equals() for content comparison. Remember: == for reference, .equals() for value.
Q: How do you share variable in thread life cycle?
A: Java ThreadLocal class allows the storage of data that is specific to each thread separately.
It is often used to implement thread-specific context or to avoid synchronisation for thread-local data