Day 23...... 🚀 Today’s Java Learning: Strings & Their Superpowers Hey LinkedIn fam 👋 Today I explored one of the most important concepts in Java — Strings. Here’s a quick and clear recap of what I learned 👇 💡 What is a String? A String is a sequence of characters enclosed in " " and it is an object in Java. 🔹 Types of Strings in Java ✅ Immutable Strings (String) • Cannot be changed once created • Used for fixed data like Name, Gender, DOB ✅ Mutable Strings (StringBuffer, StringBuilder) • Can be modified • Used for editable data like Passwords, Messages, Email IDs ⚔️ String Comparison Methods • equals() – Compares content • equalsIgnoreCase() – Ignores case • compareTo() – Lexicographical comparison ➕ String Concatenation • Using + → Stored in String Constant Pool (literals) • Using concat() → Creates a new object in Heap memory 🧩 Commonly Used String Methods toUpperCase() toLowerCase() length() charAt() contains() startsWith() endsWith() indexOf() lastIndexOf() replace() isEmpty() isBlank() split() toCharArray() 🛠️ Mutable Strings – Quick Comparison • StringBuffer → Thread-safe, slower • StringBuilder → Not thread-safe, faster 💡 Key Takeaway: Understanding Strings (memory, mutability, and methods) helps write cleaner, faster, and more efficient Java code 💪 #Java #StringHandling #LearningJourney #CodingInJava #FullStackDeveloper #DailyLearning
Java Strings: Immutable & Mutable Types & Methods
More Relevant Posts
-
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 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
-
-
🚀 Learning Core Java – Immutable Strings & String Comparison Today, I learned more about Immutable Strings in Java and the different ways to compare them. In Java, the String class is immutable, which means once a string object is created, its value cannot be changed. Any modification results in a new object being created in memory. Because strings are objects, Java provides multiple built-in methods to compare them in different ways. ⸻ 🔹 1️⃣ == (Reference Comparison) The == operator compares references (memory addresses), not actual content. If two string variables point to the same object, it returns true. Otherwise, false — even if the content is the same. ⸻ 🔹 2️⃣ equals() (Value Comparison) The equals() method compares actual string values (content). It checks whether the characters inside both strings are the same. ⸻ 🔹 3️⃣ compareTo() (Character-by-Character Comparison) The compareTo() method compares strings lexicographically (character by character). • Returns 0 → if both strings are equal • Returns positive value → if first string is greater • Returns negative value → if first string is smaller ⸻ 🔹 4️⃣ equalsIgnoreCase() This method compares string values while ignoring uppercase and lowercase differences. ⸻ 🔹 5️⃣ compareToIgnoreCase() This compares strings character by character, ignoring case differences. ⸻ 🔎 Key Takeaway: • Use == for reference comparison • Use equals() for content comparison • Use compareTo() for sorting or lexicographical comparison • Use ignore-case methods when case sensitivity doesn’t matter Understanding these differences helps avoid common bugs and write more predictable Java programs. Excited to keep strengthening my Java fundamentals! 🚀 #CoreJava #JavaProgramming #ImmutableString #JavaDeveloper #StringComparison #ProgrammingFundamentals #LearningJourney #StudentDeveloper
To view or add a comment, sign in
-
-
Day 21: Strings in Java Today’s learning was all about understanding how Strings work internally in Java from creation to comparison and concatenation. 🔹 What is a String? A String is a sequence of characters enclosed in double quotes (" " ), whereas a character uses single quotes (' ' ). ➡️ Multiple characters cannot be stored in single quotes. 🔹 Types of Strings Strings are classified into two types: Mutable Strings – values can be changed Immutable Strings – values cannot be changed (default in Java) 🔹 Ways to Create a String in Java Using new keyword Using string literals Using character arrays 🔹 String Comparison Methods Java provides multiple ways to compare strings: == → compares reference (memory address) equals() → compares values/content equalsIgnoreCase() → compares values ignoring case compareTo() → compares character by character (lexicographically) 🔹 Where Are Strings Stored in Memory? Strings are stored in the Heap Segment of the JRE Heap is divided into: Constant Pool – no duplicates allowed Non-Constant Pool – duplicates allowed 🔹 String Pool Concept Strings created without new keyword → Constant Pool Strings created using new keyword → Non-Constant Pool 🔹 String Concatenation String concatenation means combining multiple strings to form a new string. Can be done using: + operator concat() method 📌 Understanding Strings is crucial for memory management and performance in Java. #Day21 #Java #StringsInJava #CoreJava #Programming #LearningJourney #TapAcademy #JavaDeveloper
To view or add a comment, sign in
-
-
Day 15 – Learning Java Full Stack. Today, let’s strengthen two important fundamentals in Java: 🔹 Scanner (User Input) 🔹 Identifiers & Naming Conventions Scanner Class-Scanner is a built-in class present in the java.util package. It is used to read input from the keyboard. Step 1: Import Scanner Java import java.util.Scanner; Step 2: Create Scanner Object Java Scanner sc = new Scanner(System.in); Step 3: Read Values int val = sc.nextInt(); System.out.println("value = " + val); 📌 Common Scanner Methods nextInt() → reads integer nextFloat() → reads float nextDouble() → reads double nextBoolean() → reads boolean next() → reads single word nextLine() → reads full line If invalid input is entered → InputMismatchException occurs. 🔹 Reading a Character (Important Trick) Scanner does not provide a direct method to read char. So we use: char ch = sc.next().charAt(0); Here:next() reads input as String charAt(0) extracts the first character Identifiers – Naming in Java Any name given by the programmer is called an Identifier. Examples: Class names Method names Variable names 📌 Rules for Identifiers ✔ Must start with an alphabet ✔ Numbers are allowed (but not as first character) ✔ Cannot use Java keywords ✔ Cannot contain spaces ✔ Special characters like $ and _ are allowed but not recommended 🔹 Industry Naming Conventions ✔ Class Names → PascalCase ex- class StudentDetails class DatabaseTriggerManager ✔ Method & Variable Names → camelCase ex- void printBill() int employeeSalary void generateTextReport() Clean naming improves: Readability Maintainability Professionalism #Java #JavaFullStack #CoreJava #Scanner #Identifiers #CleanCode
To view or add a comment, sign in
-
🚀 Learning Update: Java — Method Overloading, Type Promotion, CLI Args & Encapsulation (OOP) In today’s live Java session, I revised some core concepts that are frequently tested in interviews and also form the foundation for Object-Oriented Programming. ✅ Key Learnings: 🔹 Method Overloading (Compiler-based / Compile-time Polymorphism) Multiple methods with the same name in the same class Java Compiler checks in order: Method Name Number of Parameters Type of Parameters If all 3 are the same → Duplicate method error If exact match isn’t found → Java tries Type Promotion (closest match) If more than one method becomes eligible after promotion → Ambiguity error 🔹 Can we overload main()? ✅ Yes, main method can be overloaded But JVM always starts execution from: public static void main(String[] args) Other overloaded main() methods can be called manually using an object/reference. 🔹 Command Line Arguments (CLI) Inputs passed in terminal get stored in String[] args Args are always Strings (even numbers) + with args performs concatenation, not addition (unless you convert manually) 🔹 OOP Introduction + Encapsulation (1st Pillar) Encapsulation = Protecting the most important data + giving controlled access Use private variables for security Provide controlled access using: ✅ Setter → set/update data (usually void) ✅ Getter → get/return data (has return type) Add validations inside setter (ex: prevent negative bank balance) 📌 Realization: These concepts are not just theory — they directly relate to writing secure, industry-ready code. #Java #OOP #Encapsulation #MethodOverloading #CommandLineArguments #LearningUpdate #FullStackDevelopment #PlacementPreparation #TapAcademy #SoftwareDevelopment TAP Academy
To view or add a comment, sign in
-
-
Day8 🚀: Variables & Memory Structure in Java Today’s learning was about what is variable and Types of variables and how Java uses RAM when a program executes. and how program execution works in java This helped me understand what happens behind the scenes when we run a Java program. A variable is a container that stores data values. In Java, every variable must be declared with a specific data type. 🔹 Syntax: data Type variable Name = value; 🔹 Example: int age = 21; double salary = 25000.50; char grade = 'A'; String name = "Theja"; 🔹 Types of Variables Covered 1️⃣ Local Variables *Declared inside methods *Stored in Stack memory *Created when method starts and destroyed when method ends 2️⃣ Instance Variables *Declared inside a class but outside methods *Stored in Heap memory *Each object has its own separate copy 🔹 How Java Uses RAM During Execution When we run a Java program, memory is divided into different segments: 🧠 1. Code Segment °Stores the compiled bytecode °Contains the program instructions 🧠 2. Static Segment °Stores static variables °Memory is allocated only once 🧠 3. Stack Segment °Stores local variables °Stores method calls °Works in LIFO (Last In First Out) order 🧠 4. Heap Segment °Stores objects and instance variables °Managed by Garbage Collector 🔹 How Program Execution Works in Java 1️⃣ Code is written and compiled into bytecode 2️⃣ JVM loads the class into memory 3️⃣ main() method is pushed into Stack 4️⃣ Objects are created in Heap 5️⃣ Variables are allocated memory 6️⃣ After execution, unused objects are removed by Garbage Collector 🔹 What I Understood Today Understanding variables is not enough. Knowing where they are stored in memory and how Java manages RAM gives deeper clarity about performance and program behavior. Learning how Java works internally is making my foundation stronger 💻🔥 #Java #MemoryManagement #JVM #Programming #LearningJourney #Day8
To view or add a comment, sign in
-
-
Day 14 – Learning Java Full Stack Today’s let's learn about the most interesting concepts in Java — Recursion. Recursion happens when a method calls itself. A method (or function) is said to be recursive if it solves a problem by calling itself again and again until a stopping condition is met. 🔹 Two Scenarios in Recursion 1️⃣ Indirect Recursion In this scenario, one method calls another method, and that method calls the first method back. Example flow: disp() → test() → disp() → test() → ... This creates a cycle between methods. 2️⃣ Direct Recursion In this scenario, a method calls itself directly. Example idea: display() → display() → display() → ... Important Note- If recursion is not properly controlled using a condition, it will lead to Stack Overflow Error. So every recursive method must have: ✔ A base condition (stopping condition) ✔ A recursive call 🔹 Controlled Recursion Example (Concept) A method prints a value and calls itself with an updated value until a condition becomes false. Example idea: display(1) if value <= 5 → increment → call display again This ensures recursion stops at the right time. Key Takeaway: Recursion is powerful, but it must be used carefully. Without a proper base condition, it can crash the program. Understanding recursion improves logical thinking and prepares you for advanced data structures like trees and graphs. #Java #JavaFullStack #Recursion #ProgrammingBasics #LearningInPublic #CoreJava
To view or add a comment, sign in
-
-
🚀 Learning Core Java – Mutable Strings in Java Today I explored Mutable Strings in Java and how they differ from immutable String objects. Unlike the String class (which is immutable), mutable strings allow us to modify the same object without creating new objects in memory. Java provides two classes for mutable strings: 🔹 StringBuffer 🔹 StringBuilder ⸻ 🔹 Default Capacity Both StringBuffer and StringBuilder have a default capacity of 16 characters. When the content exceeds the current capacity, Java automatically increases the size using this formula: 👉 New Capacity = (Current Capacity × 2) + 2 This allows dynamic resizing without manual memory handling. ⸻ 🔹 Important Methods ✔ append() Adds new content to the end of the existing string without creating a new object. ✔ delete() Allows modification by removing specific characters from the existing string. ✔ trimToSize() Reduces the capacity to match the current content length, optimizing memory usage. ⸻ 🔹 Key Difference The main difference between the two: ✔ StringBuffer → Thread-safe (synchronized) ✔ StringBuilder → Not thread-safe (faster in single-threaded environments) In most modern applications, StringBuilder is preferred unless thread safety is required. ⸻ 🔎 Key Takeaway: Use mutable strings when frequent modifications are needed to improve performance and reduce unnecessary object creation. Excited to keep strengthening my Java fundamentals! 🚀 #CoreJava #JavaProgramming #MutableStrings #StringBuilder #StringBuffer #JavaDeveloper #ProgrammingFundamentals #LearningJourney
To view or add a comment, sign in
-
-
Day 32 of Sharing What I’ve Learned 🚀 Static in Java — One Keyword, Many Powerful Uses ⚡ In Java, the static keyword belongs to the class rather than objects. This means the member is shared across all instances. ❗ 👉 Understanding static is crucial for memory efficiency, utility design, and interview questions. 🔹 Static Variables — Shared Across Objects A static variable has only one copy per class. ✅ Shared by all objects ✅ Stored in class memory (not object memory) ✅ Ideal for common properties Example: class Student { static String college = "TAP Academy"; String name; Student(String name) { this.name = name; } } 👉 All students belong to the same college ✔ 🔹 Static Methods — Called Without Objects Static methods belong to the class itself. ✅ Can be called using class name ✅ Cannot access non-static members directly ✅ Commonly used for utility functions Example: class MathUtil { static int square(int x) { return x * x; } } // Call MathUtil.square(5); 👉 No object creation needed ✔ 🔹 Static Block — Runs Once When Class Loads Used for one-time initialization. ✅ Executes before main() ✅ Runs only once ✅ Useful for complex setup Example: class Demo { static { System.out.println("Static block executed"); } } 🧠 Key Rules at a Glance ✔ Static → Belongs to class, not objects ✔ One copy shared across all instances ✔ Static methods can’t directly use instance variables ✔ Static members accessed using ClassName.member ✔ Static block runs only once 🎯 Why This Matters ✔ Improves memory efficiency ✔ Essential for utility classes ✔ Important for understanding JVM behavior ✔ Frequently asked in interviews 🧠 Key Takeaway Objects may come and go… But static members stay with the class 💡 👉 Use static when data or behavior should be shared globally 🚀 #Java #JavaDeveloper #CoreJava #OOP #BackendDevelopment #SoftwareDevelopment #CodingJourney #InterviewPreparation #DeveloperJourney #Day32 Grateful for the guidance from Sharath R, Harshit T, TAP Academy
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