Wrapping up the core concepts of the Strings module today. The final focus was on understanding what actually happens inside memory when strings are created and compared. Concepts like immutability, string interning, and the difference between == and .equals() made it clear that strings are not just simple text values, but structured objects with specific behavior. String a = "hello"; String b = "hello"; String c = new String("hello"); System.out.println(a == b); // true System.out.println(a == c); // false System.out.println(a.equals(c)); // true What became clear : - Strings in Java are immutable, meaning their value cannot be changed after creation - The string pool allows memory reuse when identical literals are created - "==" compares references, while ".equals()" compares actual content - Understanding memory behavior is essential for writing correct and efficient programs This felt like the point where Strings moved from simple syntax to real computer science understanding. Completed the core learning of the Strings module today. #Java #DSA #Strings #LearningInPublic #ProblemSolving #CodingJourney #Programming #JavaDeveloper #DeveloperJourney
Java Strings: Immutability, Interning, and Equality
More Relevant Posts
-
Arrays look simple. But they introduce one of the most important ideas in programming: 𝗜𝗻𝗱𝗲𝘅𝗲𝗱 𝗺𝗲𝗺𝗼𝗿𝘆. When you create an array in Java: 𝐢𝐧𝐭[] 𝐧𝐮𝐦𝐛𝐞𝐫𝐬 = 𝐧𝐞𝐰 𝐢𝐧𝐭[𝟓]; You’re not just storing values. You’re allocating a fixed block of memory. That decision has consequences. Arrays: • Have fixed size • Store elements of the same type • Use zero-based indexing Zero-based indexing confuses beginners, but it exists because arrays map directly to memory offsets. The first element isn’t at position 1. It’s at offset 0 from the starting address. Understanding this removes mystery. It explains: • Why 𝗔𝗿𝗿𝗮𝘆𝗜𝗻𝗱𝗲𝘅𝗢𝘂𝘁𝗢𝗳𝗕𝗼𝘂𝗻𝗱𝘀𝗘𝘅𝗰𝗲𝗽𝘁𝗶𝗼𝗻 happens • Why loops usually start at 0 • Why performance with arrays is fast Today was about: • How arrays are stored internally • Why indexing starts at 0 • The tradeoff between fixed size and speed Data structures are not random inventions. They are memory decisions. And memory decisions affect performance. #Java #Arrays #DataStructures #ProgrammingFundamentals #SoftwareEngineering #LearningInPublic
To view or add a comment, sign in
-
-
Started learning Strings in Java today. After working with arrays and matrices, this felt like moving into how real programs actually handle text and user input. The focus was on understanding how strings are created, how input is taken, and how basic built-in methods like charAt() and length() work internally. String s = "Pratim"; System.out.println(s.charAt(0)); // Output : P System.out.println(s.length()); // Output : 6 What became clear today: - Strings are not primitive values; they behave like objects with built-in functionality - Accessing characters requires methods like charAt() instead of direct indexing - length() is a method call, not a property like in arrays - Even simple text handling introduces a different way of thinking compared to numbers This felt like the starting point of working with real-world data, where most problems involve text rather than just numbers. Beginning the Strings module today. #Java #DSA #Strings #LearningInPublic #ProblemSolving #CodingJourney #Programming #JavaDeveloper #DeveloperJourney
To view or add a comment, sign in
-
Day-10 Understanding Arrays in Java – 3D & Jagged Arrays 🔹 Exploring the concepts of Three-Dimensional Arrays and Jagged Arrays in Java with clear structure and visualization. 📌 In this post, I covered: ✔️ Structure of 3D arrays (blocks, rows, columns) ✔️ How memory is organized internally ✔️ Difference between regular and jagged arrays ✔️ Variable column lengths in jagged arrays ✔️ Practical Java implementation with nested loops Understanding multidimensional arrays is essential for handling complex data structures efficiently in Java. Always learning. Always building. 💻✨ #Java #Programming #DataStructures #LearningJourney #ComputerScience #Coding
To view or add a comment, sign in
-
-
🚀 Day 3/30 – Java DSA Challenge 🔎 Problem 22: 118. Pascal's Triangle (LeetCode – Easy) Today’s problem was about pattern logic + mathematical formula building 🔥 🧠 Problem Statement Given an integer numRows, return the first numRows of Pascal’s Triangle. In Pascal’s Triangle: ✔ First and last element of every row is 1 ✔ Every other element is the sum of the two elements directly above it Example (numRows = 5): [1] [1,1] [1,2,1] [1,3,3,1] [1,4,6,4,1] 💡 Approach Used – Binomial Coefficient Logic Instead of calculating each value using previous row storage, I used the mathematical formula: [ C(n, k) = C(n, k-1) * (n-k+1) / k ] ✔ Start each row with 1 ✔ Use formula to calculate next element ✔ Store each row inside List<List<Integer>> This avoids extra computations and keeps logic clean. ⏱ Time Complexity: O(n²) 📦 Space Complexity: O(n²) – Storing triangle 📌 Key Learning Understood combinatorics in coding Learned optimized way to generate Pascal’s Triangle Strengthened nested loop + mathematical logic 22 Problems Completed 🔥 Day 3 building strong fundamentals 💪🚀 #Day3 #30DaysOfCode #Java #DSA #LeetCode #PascalTriangle #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
100 Days of Coding Challenge – Day 17 📌 Problem: String Compression 💻 Language: Java 🧠 Concept Used: Two Pointers + In-place Array Manipulation 🔍 Platform: LeetCode Today’s challenge was to compress a character array in-place by replacing consecutive repeating characters with the character followed by its count. Example: Input: ["a","a","b","b","c","c","c"] Output: ["a","2","b","2","c","3"] Approach: ✔ Use two pointers — one for reading characters and one for writing compressed output ✔ Count consecutive repeating characters ✔ Write the character once and append the count if it is greater than 1 ✔ Modify the array directly without creating extra space Time Complexity: O(n) Space Complexity: O(1) 🔗 Problem Link: https://lnkd.in/eeeWBA4X 🔗 Code: https://lnkd.in/enj4Qcy9 #100DaysOfCode #Day17 #Java #DSA #LeetCode #Strings #TwoPointers #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 10 – How Arrays Really Work in Java Today I went beyond basic syntax and understood how arrays actually work internally in Java. 🔎 What I explored: ✔️ How arrays are stored in contiguous memory locations ✔️ How index-based access works (0-based indexing) ✔️ How array size is fixed after creation ✔️ How reference variables point to array objects in memory ✔️ Time complexity of accessing elements – O(1) Understanding the internal working of arrays helped me realize why they are fast for accessing elements but limited when it comes to resizing. This concept is very important before moving to advanced data structures like ArrayList, LinkedList, and more. 🙏 Special thanks to Aditya Tandon Sir for explaining the internal memory concept so clearly. #Day10 #Java #Arrays #DataStructures #LearningJourney #Programming #Coding #JavaDeveloper
To view or add a comment, sign in
-
-
🚀 Day 15 / 180 – DSA with Java 🚀 📘 Topic Covered: Strings & Two-Pointer Technique 🧩 Problem Solved: Valid Palindrome Problem: Check whether a given string is a palindrome, considering only alphanumeric characters and ignoring cases. Approach: Used two pointers starting from both ends of the string. Skipped non-alphanumeric characters and compared characters in a case-insensitive manner to determine whether the string reads the same forward and backward. Key Learning: ✔️ Applying two-pointer technique on strings ✔️ Handling edge cases like special characters ✔️ Writing clean logic for real-world string validation If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Strings #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Just Learned: Transpose of a Matrix in Java Today I practiced how to transpose a matrix using Java. Matrix transpose means converting rows into columns and columns into rows. It is a very useful concept in programming, especially in data processing, image manipulation, and mathematical computations. While working on this problem, I improved my understanding of: • 2D arrays and nested loops • Index swapping logic (arr[i][j] → arr[j][i]) • Writing clean and optimized code • Problem-solving approach for matrix-based questions Learning these concepts step by step is helping me build a strong foundation in Data Structures and Java programming. Every small concept adds up to big improvements in coding skills. Looking forward to practicing more matrix problems and strengthening my logic building skills #Java #CodingJourney #DSA #Programming #LearningInPublic #Matrix #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 4 — Restarting My Java Journey with Consistency Today, went deeper — beyond syntax — into how computers actually store numbers in memory. One fascinating concept I studied was 2’s complement, the method used to store negative numbers. For example, to store -42: • Write +42 in binary • Invert the bits (1’s complement) • Add 1 → gives the 2’s complement It ensures there is **only one representation of zero** and allows the CPU to perform both addition and subtraction using the same hardware circuitry — making computation simpler and faster. Another fascinating topic was floating-point representation (IEEE 754 format). A float , (double) in Java uses 32 bits , (64bits) divided into: • 1 bit , (1bit) → Sign • 8 bits , (11 bits)→ Exponent • 23 bits, (52 bits)→ Mantissa The value is calculated using the formula: (-1)^sign × (1 + mantissa) × 2^(exponent − bias) Now comes an important question — how is bias calculated and why is it needed? Bias formula: bias = 2^(k−1) − 1 where k = number of exponent bits So, • For float → k = 8 → bias = 2^(8−1) − 1 = 127 • For double → k = 11 → bias = 2^(11−1) − 1 = 1023 Why bias is used: Bias allows the exponent to represent both positive and negative powers while storing only positive binary values. This makes comparison and hardware implementation simpler and more efficient. This also answered an interesting question: Why does printing float a = 0.7f not always give the exact value? Because many decimal numbers cannot be represented exactly in binary, so the computer stores the closest possible approximation. Learning daily with Coder Army and Aditya Tandon Bhaiya and Rohit Negi Bhaiya #Day3 #Java #Consistency #BackendDevelopment #LearningJourney #SoftwareEngineering #CoderArmy #AdityaTandon
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