As a part of my core java learning journey TAP Academy Today I learn about the String Concatenation in Java String concatenation is the process of combining two or more strings into a single string. In Java, this can be done using the + operator or the concat() method. 1️⃣ Using String Literals (+ operator) When concatenation involves only literals, the result is stored in the String Constant Pool (SCP). Example: "Java" + "Python" = "JavaPython" → stored in SCP 2️⃣ Using Reference Variables When concatenation involves string references, the result is created in the Heap memory. Example: s1 = "Java" s2 = "Python" s1 + s2 = JavaPython → stored in Heap 3️⃣ Reference + Literal Example: s1 + "Python" = JavaPython→ stored in Heap 4️⃣ Literal + Reference Example: "Java" + s2 = JavaPython→ stored in Heap 5️⃣ Using concat() Method The concat() method also combines strings, and the result is always stored in Heap memory. Example: s1.concat(s2) = JavaPython → stored in Heap Understanding how Java handles concatenation helps in optimizing memory usage and improving performance. TAP Academy #Java #String #Programming #FullStackDeveloper #LearningJourney
Java String Concatenation Methods and Memory Usage
More Relevant Posts
-
📚 Day 20 at Tap Academy – Learning Strings in Java Today I learned about Strings in Java, a fundamental concept used in almost every program. 🔹 What is a String? A String is a collection of characters enclosed within double quotes (" "). In Java, Strings are objects, not primitive data types. 🔹 Types of Strings ✔️ Immutable Strings - Cannot be changed once created - Example: Name, Gender, DOB ✔️ Mutable Strings - Can be modified after creation - Example: Email ID, Password 🔹 Memory Concept - Strings created using literals are stored in the String Constant Pool (SCP) - Strings created using "new" keyword are stored in Heap Memory 🔹 Ways to Create Strings String s1 = "JAVA"; String s2 = new String("JAVA"); char[] ch = {'J','A','V','A'}; String s3 = new String(ch); 🔹 String Comparison ✔️ "==" → compares reference ✔️ ".equals()" → compares values String a = "Hello"; String b = "Hello"; System.out.println(a == b); // true System.out.println(a.equals(b)); // true 💡 Key Takeaway: Strings are powerful in Java, and understanding how they work helps in writing efficient and optimized code. #Java #Programming #Coding #JavaDeveloper #LearningJourney #TapAcademy #Day20
To view or add a comment, sign in
-
-
📚 Today’s Learning: String Concatenation & "concat()" Method in Java In today’s class, I explored an important concept in Java called String Concatenation and the "concat()" method. 🔹 String Concatenation String concatenation is the process of combining two or more strings into a single string. In Java, this is commonly done using the "+" operator. It helps developers create meaningful text outputs by joining variables and messages together. 🔹 "concat()" Method Java also provides the "concat()" method, which is a built-in method of the String class. This method is used to append one string to another string, producing a new combined string. 🔹 Important Concept – String Immutability One key concept behind these operations is that Strings in Java are immutable. This means the original string cannot be changed; instead, a new string object is created when concatenation happens. 💡 Key Takeaway: - "+" is an operator used for concatenation - "concat()" is a method of the String class used to join strings Learning these fundamental concepts strengthens my Java programming foundation and helps me understand how strings work internally. #Java #Programming #LearningJourney #StudentDeveloper #Coding TapAcademy
To view or add a comment, sign in
-
-
📚 Day 16 at Tap Academy – Learning Arrays in Java Today I learned about Arrays in Java, which are used to store multiple values of the same data type in a single variable. 🔹 What is an Array? An array is a collection of elements of the same data type stored in contiguous memory locations. Each element is accessed using an index. 🔹 Syntax to Declare an Array int[] arrayName; 🔹 Creating an Array int[] a = new int[5]; 🔹 Accessing Elements Array elements are accessed using index values. Index starts from 0 and goes up to (n-1). Example: a[0] = 10; 🔹 Example Program in Java public class ArrayExample { public static void main(String[] args) { int[] ages = new int[5]; ages[0] = 18; ages[1] = 19; ages[2] = 20; ages[3] = 21; ages[4] = 22; System.out.println("Student Ages:"); for(int i = 0; i < ages.length; i++) { System.out.println(ages[i]); } } } 💡 Key Points ✔ Arrays store multiple values in a single variable ✔ All elements must be of the same data type ✔ Index starts from 0 ✔ Useful for storing and managing large amounts of data efficiently 🎯 Example Use Case: Storing the ages of students in a classroom. #Java #Programming #Arrays #LearningJourney #TapAcademy #Coding
To view or add a comment, sign in
-
-
DAY 16: CORE JAVA TAP Academy 🚀 Deep Dive into Java Strings: Memory, Methods, and Manipulation If you're learning Java, you quickly realize that Strings aren't just simple data types—they are objects with unique memory management rules! I’ve been brushing up on the fundamentals and mapped out some key concepts. Here’s a breakdown of what I’ve been diving into: 🧠 1. String Memory Management The difference between SCP (String Constant Pool) and the Heap is crucial for performance: * Direct Literals: Using "A" + "B" creates the string in the SCP. No duplicates allowed! * Variables/Objects: Concatenating variables (e.g., s1 + s2) or using the concat() method always creates a new object in the Heap. * The Result: Two strings can have the same value but different memory references. This is why we use .equals() for content and == for reference! 🛠️ 2. Essential String Methods Java provides a robust toolkit for string manipulation. Some of my favorites from today’s practice: * substring(start, end): To extract specific parts of a string. * indexOf() & lastIndexOf(): To track down character positions. * toCharArray() & split(): Perfect for breaking strings down for complex algorithms. ⚖️ 3. Mastering compareTo() Unlike .equals() which just gives a True/False, compareTo() returns an integer based on Lexicographical order: * Negative: s1 < s2 (comes before) * Positive: s1 > s2 (comes after) * Zero: They are a perfect match! Understanding these nuances is the first step toward writing memory-efficient Java code. #Java #Programming #CodingTips #SoftwareDevelopment #LearningToCode #TechCommunity #JavaStrings
To view or add a comment, sign in
-
-
Day 39 of My Java Learning Journey – Polymorphism Today I learned one of the most powerful concepts in Polymorphism in Java. 📌 What is Polymorphism? Polymorphism comes from two Greek words: Poly → Many Morphs → Forms 👉 So, polymorphism means “many forms.” In Object-Oriented Programming, it allows one reference to behave differently depending on the object it refers to. ✈️ Example from my practice I created a parent class Plane with a method fly(). Then I created three child classes: CargoPlane PassengerPlane FighterPlane Each class overrides the fly() method with different behavior. Example behavior: CargoPlane → flying at low height PassengerPlane → flying at medium height FighterPlane → flying at great height Using a parent reference (Plane ref), I assigned different child objects: Plane ref; ref = cp; ref.fly(); ref = pp; ref.fly(); ref = fp; ref.fly(); This demonstrates Runtime Polymorphism (Method Overriding). ⚠️ Important Concept I Learned Using a parent reference, we can only call: ✔ Inherited methods ✔ Overridden methods But we cannot directly access child-specific methods like: carryCargo() carryPassenger() carryWeapons() To access them, we must use Downcasting. Example: ((CargoPlane) ref).carryCargo(); 🎯 Advantages of Polymorphism ✔ Code Reusability ✔ Flexibility ✔ Reduced Complexity #Java #JavaProgramming #OOP #Polymorphism #MethodOverriding #ProgrammingJourney
To view or add a comment, sign in
-
-
🚀 Learning Java Star Patterns and Pattern Logic Today I practiced some Java pattern programs using nested loops in VS Code and ran them using the command prompt (javac and java). Along with writing the code, I also tried to understand the logic behind each pattern. 1. X Pattern * * * * * * * * * • Use two nested loops for rows and columns. • Print * when the row number equals the column number (i == j). • Print * when the sum of row and column equals n + 1 (i + j == n + 1). • Otherwise print space. This creates two diagonals forming the X shape. 2.Inverted Triangle Pattern * ** *** **** ***** **** *** ** * • First loop prints stars increasing from 1 to n. • Second loop prints stars decreasing from n-1 to 1. • This combination creates a diamond-like pattern without spaces. 3.Alphabet Pattern – Letter D **** * * * * * * * * **** • First and last rows print continuous stars (****). • Middle rows print stars only at the first and last column. • Spaces are printed between them to form the shape of letter D. Grateful for the guidance from my mentors 🙏 Special thanks to: Dr. Tushar Ram Sangole sir Sushma Nair Mam Milind Ankleshwar sir #Java #Programming #CodingPractice #StarPatterns #LearningJava #ProblemSolving
To view or add a comment, sign in
-
-
Day 13 – Exploring Strings in Java | My Learning Journey Today I continued my journey of learning Java and explored more concepts related to Strings. Strings are one of the most commonly used data types in programming because they help us work with text data effectively. 🔹 1. String Concatenation in Java String concatenation means combining two or more strings into a single string. In Java, this is commonly done using the + operator or the concat() method. Example: String firstName = "Hello"; String secondName = "World"; System.out.println(firstName + " " + secondName); Output: Hello World 🔹 2. Built-in Methods in String Java provides many built-in methods in the String class that help us perform operations easily. Some commonly used methods include: length() – Returns the length of a string charAt() – Returns the character at a specific index toUpperCase() – Converts string to uppercase toLowerCase() – Converts string to lowercase contains() – Checks if a string contains a specific value substring() – Extracts part of a string Example: String text = "Java Programming"; System.out.println(text.toUpperCase()); 🔹 3. StringTokenizer StringTokenizer is used to split a string into multiple tokens based on a delimiter like space, comma, or any other character. Example: import java.util.StringTokenizer; String str = "Welcome to Java"; StringTokenizer st = new StringTokenizer(str); while(st.hasMoreTokens()){ System.out.println(st.nextToken()); } Output: Welcome to Java Understanding string concatenation, built-in string methods, and String Tokenizer helps in handling and manipulating text data efficiently in Java applications. 💡 Every day I’m learning something new and improving my programming skills step by step. #Java #LearningJava #JavaProgramming #CodingJourney #Strings #DaysOfCode #DeveloperJourney
To view or add a comment, sign in
-
-
🚀 Day 13 of My Java Learning Journey at Tapp Academy Today’s topic: Immutable & Mutable Strings in Java By default, Strings in Java are immutable. To work with mutable strings, Java provides two important classes: 🔹 StringBuffer 🔹 StringBuilder Here’s what I learned today 👇 🔸 StringBuffer • It is a class, so we must create an object. • Default capacity → 16 characters • Capacity growth formula → (currentCapacity × 2) + 2 • append() → Used to add content • length() → Returns the actual number of characters • trimToSize() → Adjusts capacity to match the actual length • delete(start, end) → Removes characters between given indexes • It is synchronized (thread-safe) Example: If the string contains 50 characters, the capacity might show 70. Using trimToSize() makes both length and capacity equal. 🔸 StringBuilder • Almost 90% similar to StringBuffer • Not synchronized • Faster compared to StringBuffer 📌 Key Difference: StringBuffer is thread-safe, while StringBuilder is not. Understanding these concepts helped me learn how Java manages memory, performance, and string manipulation efficiently. Learning step by step. Improving every day. 💻✨ Excited for Day 14! #Java #JavaProgramming #JavaDeveloper #StringBuffer #StringBuilder #ImmutableString #MutableString #CodingJourney #SoftwareDevelopment #WomenInTech #LearningEveryday #DeveloperJourney #100DaysOfCode #TechCareer #JavaLearning #ProgrammingLife
To view or add a comment, sign in
-
-
🚀 I completed Day 3 of my Java learning using the W3Schools platform.Today, I studied about java Operators, Strings, and Type Casting.” This helped me understand how Java handles data transformation and manipulation. First, I learned about Type Casting, which is used to convert one data type into another. I understood that Java is a strictly typed language, so data must be converted carefully when moving between different types. I also learned about automatic casting (widening) such as converting "int" to "double", and manual casting (narrowing) where a larger type like "double" is converted to a smaller type like "int", which may cause loss of decimal values. Next, I explored operators in Java, which act as the logic engine of a program. These include arithmetic operators ("+ - * / %"), assignment operators, comparison operators ("==, >, <, >=, <="), and logical operators ("&&, ||, !"). I also learned how the “+” operator can be used not only for arithmetic calculations but also for string concatenation. Another important concept I studied was Strings in Java. I learned that strings are objects with built-in methods that allow us to analyze and manipulate text. Some useful string methods include "length()", "charAt()", "indexOf()", and "toUpperCase()" which help in processing text data effectively. Finally, I saw how these concepts work together in a practical example where operators, type casting, and string concatenation are used to calculate and display a score percentage in a program. #Java #Programming #LearningJourney #SoftwareDevelopment #W3schools
To view or add a comment, sign in
-
🚀 Starting My Java Learning Journey – Day 10 🔹 Topic: Recursion in Java Recursion is a process where a method calls itself to solve a problem. It is mainly used to break down complex problems into smaller, simpler sub-problems. A recursive function must have: ✔ Base Case → condition to stop recursion ✔ Recursive Call → method calling itself Example: Factorial of a Number public class Main { static int factorial(int n) { if (n == 1) { // base case return 1; } return n * factorial(n - 1); // recursive call } public static void main(String[] args) { int result = factorial(5); System.out.println("Factorial: " + result); } } Output: Factorial: 120 ✔ Recursion solves problems by calling the same method repeatedly ✔ Every recursive method must have a base case ✔ Useful for problems like factorial, Fibonacci, tree traversal #Java #JavaLearning #Programming #BackendDevelopment #CodingJourney #Recursion
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