
★ Sr Backend Developer | 9+ years Experience ★ Sharing my experience via tweets & threads ★ Explains complex concepts
Punjab
Joined May 2022
- Tweets2.1K
- Following126
- Followers1.4K
- Likes611
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 👇
1
49
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
1
37
Ever wonder why "hello" == "hello" is true, but new String("hello") == new String("hello") is false? Let's unravel this 👇
The String Pool
1
47
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.
1
36
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
4
1,093
6 Effective error handling in Java:
Discover the best practices and strategies to ensure smooth sailing in our Java applications! 🚀🔍
Handle Resource Cleanup with try-with-resources: Use try-with-resources when dealing with resources like as files or database connections to guarantee that resources are automatically closed at the conclusion of the block, limiting the possibility of resource leaks.
1
256
That's a wrap;
I hope you find this thread helpful
Share your Java coding best practises and experiences. Let's create a developer community devoted to writing code that's fun to work with! 🤝📷🚀
Thanks for reading.
- RT/Like below tweet
teapawt.net/java_experts/status/16…
6 Effective error handling in Java:
Discover the best practices and strategies to ensure smooth sailing in our Java applications! 🚀🔍
211





