->A simple Java concept that’s easy to overlook 👇 Immutable Strings 🔒 String str = "hello"; str.concat(" world"); System.out.println(str); // still "hello" Strings don’t change after creation. Operations like concat() create a new object instead ♻️ str=str.concat(" world"); System.out.println(str); // "hello world" Small detail ⚡ But important while writing logic 🧠 #Java #BackendDevelopment #Programming
Java Strings are Immutable
More Relevant Posts
-
Last post we discussed why String is immutable in Java. So what if you need to modify strings frequently? 🤔 That’s where StringBuilder and StringBuffer come in. Both are mutable, but choosing the right one matters. 👉 StringBuilder = faster for single-threaded use 👉 StringBuffer = thread-safe for shared multithreaded use Swipe → to understand the real difference. 💬 Comment “code” for more Java examples. #Java #Backend #JavaDeveloper #Programming #InterviewPrep #StringBuilder
To view or add a comment, sign in
-
🚨 Java fact about constructors 👇 Constructors don’t have a return type… But something still returns an object 🤯 Example: class User { User() { System.out.println("Constructor called"); } } User user = new User(); 👉 What’s actually happening? - "new" keyword creates the object - Allocates memory - Calls the constructor - Returns the reference 👉 Important: Constructor itself does NOT return anything 👉 "new" keyword returns the object --- 👉 This is NOT a constructor: class User { void User() { } ❌ } 👉 It becomes a normal method 💡 Many people think constructor returns object… but actually new keyword does that Did you know this? 👇 #Java #CoreJava #Programming #BackendDeveloper #Coding #TechLearning
To view or add a comment, sign in
-
💻 Day 23 – Strings in Java Today I explored Strings in Java, one of the most fundamental and important concepts. I learned about different types of string handling: 🔹 String – Immutable (cannot be changed) 🔹 StringBuilder – Mutable and faster 🔹 StringBuffer – Mutable and thread-safe Understanding immutability was a key highlight today, as it plays an important role in memory management and performance. 💡 Key takeaway: Choosing the right type of string handling improves both performance and efficiency in Java applications. Continuing to strengthen my core Java concepts step by step 🚀 #Java #Strings #Programming #LearningInPublic #CodingJourney #Day23
To view or add a comment, sign in
-
-
Topic of the day String? Why String is Immutable? 👉 In Java, a String is immutable, which means once it is created, its value cannot be changed. Example: String s = "Hello"; s.concat(" World"); 👉 You might expect: "Hello World" 👉 But actual output: "Hello" Because concat() creates a new object, instead of modifying the existing one. 🔍 Why did Java designers make String immutable? ✔️ Security – Strings are used in sensitive areas (like DB connections, file paths, network URLs) ✔️ Thread Safety – No need for synchronization (safe in multithreading) ✔️ Performance – Enables String Pool (memory optimization) ✔️ Caching – Hashcode can be cached (used in HashMap) If you are doing multiple string modifications, prefer: 👉 StringBuilder (faster, not thread-safe) 👉 StringBuffer (thread-safe) #Java #JavaConcepts #InterviewPreparation #Programming #Developers #Programming #Development #Coding
To view or add a comment, sign in
-
📒 Day 27: final Keyword in Java 🔥 Java’s way of saying: “Modify me? Compile error loading…” 😎 In Java, the final keyword is used to apply restrictions on variables, methods, and classes to ensure immutability and controlled usage in object-oriented programming. 👉 Uses of final keyword: » 🔹 final variable → value cannot be changed once assigned » 🔹 final method → cannot be overridden in a subclass » 🔹 final class → cannot be extended or inherited 💡 Conclusion: The final keyword helps in achieving security, consistency, and controlled design in Java applications. #Java #CoreJava #OOP #Programming #Coding #LearnInPublic #100DaysOfCode #SoftwareDevelopment #JavaDeveloper #CodingJourney #final #finalkeyword
To view or add a comment, sign in
-
LeetCode Practice - 11. Container with Most Water The program is solved using JAVA. 🔑 Logic Summary 1. Take two pointers (start and end) 2. Calculate area 3. Store max area 4. Move smaller height pointer 5. Repeat until pointers meet #LeetCode #Java #CodingPractice #ProblemSolving #DSA #Array #DeveloperJourney #TechLearning
To view or add a comment, sign in
-
-
This Java snippet trips up even experienced developers 👇 Integer a = 127; Integer b = 127; Integer c = 128; Integer d = 128; System.out.println(a == b); System.out.println(c == d); One prints true. One prints false. At first glance, both comparisons look identical. Same type. Same assignment. Same operator. So what’s going on? If you know the reason, you’ve got a deeper grasp of how Java actually works under the hood. Drop your explanation below — no Googling 👇 #Java #Programming #SoftwareEngineering #DevCommunity #CodeChallenge
To view or add a comment, sign in
-
💻 Understanding Multithreading in Java 🧵⚡ Most beginners watch multithreading… but don’t actually understand how it works internally. So today, I broke it down visually 👇 👉 In Java, multithreading allows multiple tasks to run concurrently within the same process. 👉 All threads share the same memory space, making execution faster and more efficient. 🔍 What’s happening behind the scenes? The main thread starts execution The JVM manages threads & memory Multiple threads run tasks in parallel Once completed → control returns to the main thread ⚡ Why it matters? ✔ Better CPU utilization ✔ Faster execution ✔ Improved application responsiveness 💡 Real-world use cases: Background tasks (file processing, logging) Web servers handling multiple requests Games & real-time systems 🚀 Key takeaway: Don’t just learn syntax — understand how things work under the hood. That’s what separates a coder from a developer. #Java #Multithreading #Concurrency #BackendDevelopment #100DaysOfCode #Learning #SoftwareEngineering
To view or add a comment, sign in
-
-
💻 Understanding Multithreading in Java 🧵⚡ Most beginners watch multithreading… but don’t actually understand how it works internally. So today, I broke it down visually 👇 👉 In Java, multithreading allows multiple tasks to run concurrently within the same process. 👉 All threads share the same memory space, making execution faster and more efficient. 🔍 What’s happening behind the scenes? The main thread starts execution The JVM manages threads & memory Multiple threads run tasks in parallel Once completed → control returns to the main thread ⚡ Why it matters? ✔ Better CPU utilization ✔ Faster execution ✔ Improved application responsiveness 💡 Real-world use cases: Background tasks (file processing, logging) Web servers handling multiple requests Games & real-time systems 🚀 Key takeaway: Don’t just learn syntax — understand how things work under the hood. That’s what separates a coder from a developer. #Java #Multithreading #Concurrency #BackendDevelopment #100DaysOfCode #Learning #SoftwareEngineering
To view or add a comment, sign in
-
-
Solved Simple Array Sum using LinkedList in Java 8 💻📊 Today I worked on the Simple Array Sum problem and implemented it using LinkedList in Java 8. 💡 What I learned: How to convert a List into a LinkedList Traversing elements efficiently using loops Using Java 8 Streams for cleaner and shorter code ⚙️ Approach: Converted input list into a LinkedList Iterated through elements and calculated sum Also explored stream().mapToInt().sum() for optimized solution 📌 Key Takeaway: Even simple problems help strengthen core concepts like data structures and improve coding efficiency. ⚡ Time Complexity: O(n) ⚡ Space Complexity: O(n) 👨💻 Consistent practice is helping me improve my problem-solving skills step by step. #Java #Java8 #LinkedList #Coding #ProblemSolving
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development
Great 👍