Day - 3 : Methods in Java A method is a function written inside the class. Since Java is the object oriented programming language, we need to write the method inside same class. ● Calling a method : A method can be called by creating the object of the class in which the method exists followed by the method call. ● Void return type : When we don't want our method to return anything, we use void as the return type. ● Static Keyword: Static keyword is used to Associate a method of a given class with the class with the class rather than the object . Static method in a class is shared by all objects. ● Syntax : datatype name( ) { // method body; } ● Example : class java { static void add(int a, int b) { System.out.println("Sum = " + (a + b)); } public static void main(String[] args) { add(10, 20); } } #Java #CoreJava #Arrays #MultidimensionalArray #FullStackJava #LearningInPublic EchoBrains
Java Methods: Functions Inside Classes
More Relevant Posts
-
Understanding Variables in Java – The Building Blocks of Every Program In Java, variables are used to store data that a program can use and manipulate. Think of them as containers that hold values during program execution. What is a Variable? A variable is a named memory location that stores a specific type of data. Syntax: dataType variableName = value; Types of Variables in Java 1️⃣ Local Variables -> Declared inside a method or block -> Accessible only within that method -> Must be initialized before use 2️⃣ Instance Variables -> Declared inside a class but outside methods -> Each object gets its own copy -> Represent object-level data 3️⃣ Static Variables -> Declared using the static keyword -> Shared among all objects of the class -> Used for constants or common properties 🔹 Why Variables Matter 1. Store and manage data 2. Improve code readability 3. Enable dynamic behaviour in programs TAP Academy #Java #Programming #JavaBasics #Coding #SoftwareDevelopment #LearnJava
To view or add a comment, sign in
-
-
✨DAY-17: 🌳 Understanding Strings in Java – A Real-World Example Learning Java becomes easier when we connect concepts to real life. This image explains Strings in Java using trees as an example: 🔹 Single Tree with One Rope – Just like a simple string reference. 🔹 Multiple Trees Connected by Ropes – Represents the String Pool, where identical string values share memory. 🔹 Separate Trees with Separate Ropes – Represents new String() objects, which create new memory even if the value is the same. 💡 Key Insight: In Java, string literals share memory inside the String Pool to optimize performance, while using new String() creates a new object in heap memory. Understanding this concept helps in: ✅ Writing memory-efficient code ✅ Avoiding unnecessary object creation ✅ Improving performance in large applications Sometimes, the best way to understand programming is to visualize it in nature 🌱 #Java #Programming #CodingLife #JavaDeveloper #LearningJourney #TechConcepts
To view or add a comment, sign in
-
-
✨DAY-17: 🌳 Understanding Strings in Java – A Real-World Example Learning Java becomes easier when we connect concepts to real life. This image explains Strings in Java using trees as an example: 🔹 Single Tree with One Rope – Just like a simple string reference. 🔹 Multiple Trees Connected by Ropes – Represents the String Pool, where identical string values share memory. 🔹 Separate Trees with Separate Ropes – Represents new String() objects, which create new memory even if the value is the same. 💡 Key Insight: In Java, string literals share memory inside the String Pool to optimize performance, while using new String() creates a new object in heap memory. Understanding this concept helps in: ✅ Writing memory-efficient code ✅ Avoiding unnecessary object creation ✅ Improving performance in large applications Sometimes, the best way to understand programming is to visualize it in nature 🌱 #Java #Programming #CodingLife #JavaDeveloper #LearningJourney #TechConcepts
To view or add a comment, sign in
-
-
🚀 Mastering Java Strings: More Than Just Text! Around 60–70% of the world’s data—from usernames to encrypted passwords—is stored as String data. In Java, a String is not a primitive; it’s an object representing a sequence of characters. 🔄 Immutable vs. Mutable Immutable (String): Cannot be changed once created; modifications create new objects. Mutable (StringBuilder, StringBuffer): Can be modified without creating new objects—ideal for frequent updates. 🧠 Memory: SCP vs. Heap String Constant Pool (SCP): String s = "Java"; → Reuses objects (no duplicates). Heap: String s = new String("Java"); → Always creates a new object. ⚖️ Comparison == → Compares references. .equals() → Compares values. .equalsIgnoreCase() → Compares values ignoring case. Grateful to have learned this so clearly—well taught by Sharath R sir at Tap Academy using engaging animations that made the concepts easy to grasp. 💡 #Java #Coding #SoftwareDevelopment #LearningJourney #JavaStrings #ProgrammingTips
To view or add a comment, sign in
-
-
Today I focused on understanding the types of variables in Java and how their behavior changes depending on where they are declared. At first it looked simple, but while going through examples, I realized that the real difference is not the datatype — it is the scope, initialization, and memory behavior of the variable. Things that became clear: - Local variables exist only inside methods, blocks, or constructors and must be initialized before use - Their scope is limited to the method in which they are declared - Instance variables are declared inside a class but outside methods and are automatically initialized with default values by the compiler - These default values depend on datatype, such as 0 for numeric types, false for boolean, '\0' for char, and null for objects - Instance variables are accessible across all methods of the same class, showing how objects maintain state Seeing the object example made the concept clearer, an object holds its own copy of instance variables, which get real values only after initialization. The biggest realization from this topic was simple - Understanding Java is less about syntax and more about how memory, scope, and initialization actually work. Small concept, but an important foundation for everything ahead. #java #programming #learninginpublic #javabasics #codingjourney
To view or add a comment, sign in
-
Today’s focus was on understanding why StringBuilder exists and how it changes the way strings are handled in Java. What changed from the previous learning: - Strings are immutable, so every modification creates a new object and increases memory usage - StringBuilder is mutable, which means changes happen in the same object without creating new ones - Common operations like append, insert, delete, reverse, and setCharAt make real text manipulation much more efficient A simple practice example: StringBuilder sb = new StringBuilder("Hello"); sb.append(" World"); // Hello World sb.insert(5, ","); // Hello, World sb.replace(7, 12, "Java"); // Hello, Java sb.delete(5, 6); // Hello Java sb.reverse(); // avaJ olleH This made it clear that performance and memory efficiency are the real reasons StringBuilder is used in real applications. The biggest realization: - Working with strings is not only about syntax - It is about choosing the right structure for efficiency Not perfect yet, but progress is visible, especially in understanding how Java handles text internally. #java #stringbuilder #datastructures #codingjourney #learninginpublic #softwaredevelopment
To view or add a comment, sign in
-
Remove Duplicates from a List of Strings using Java Streams: Java Streams make it super easy to eliminate duplicates from a list with just one line of code. import java.util.*; import java.util.stream.Collectors; public class RemoveDuplicates { public static void main(String[] args) { List<String> names = Arrays.asList("Java", "Python", "Java", "C++", "Python"); List<String> uniqueNames = names.stream() .distinct() .collect(Collectors.toList()); System.out.println(uniqueNames); } } ✅ Output : [Java, Python, C++,] 💡 Why use distinct()? Removes duplicate elements Maintains insertion order Cleaner and more readable than traditional loops 📌 Pro tip: distinct() internally uses hashCode() and equals() — so it works perfectly for Strings and well-defined objects. #Java #JavaStreams #Coding #Programming #CleanCode #Developers #LearnJava
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
-
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