🚀 Day 11 at Tap Academy – Methods in Java ☕💻 ☘️Today I learned one of the most powerful concepts in Java – Methods. Methods help us organize, reuse, and simplify our code. Let’s understand it in a simple way 👇 🔹 What is a Method? A method is a block of code that performs a particular task. It is also called a function in Java. ✅ Methods help in: ♻️ Code Reusability (use same code many times) 📉 Code Reduction (avoid writing duplicate code) 🧩 Code Organization and Documentation Instead of writing the same code again and again, we can just call the method multiple times. 🔹 Methods and Objects Relationship Objects have: 🧾 State (Has) → Data (Data Types) ⚙️ Behavior (Does) → Methods Ex: A Car 🚗 Has → color, speed, model (State) Does → start(), stop(), accelerate() (Behavior → Methods) 🔹 Syntax of a Method access_modifier return_type methodName(input) { // method body } Ex: public void display() { System.out.println("Hello Java"); } ✔ access modifier → public, private,etc. ✔ return type → void, int, String,etc. ✔ method name → display() ✔ parentheses () → input parameters If method returns nothing → use void 🔹 4 Types of Methods in Java 1️⃣ No Input, No Output public void greet() { System.out.println("Hello Student"); } Call: obj.greet(); 📌Working: Heap → object stored Stack → greet() method called → prints output → removed from stack 2️⃣ Input, No Output public void printNumber(int num) { System.out.println(num); } Call: obj.printNumber(10); 📌 Working: Heap → object created Stack → printNumber(10) stored → executes → removed 3️⃣ No Input, Output public int getNumber() { return 100; } Call: int result = obj.getNumber(); 📌 Working: Stack → getNumber() runs returns 100 → stored in variable 4️⃣ Input, Output public int add(int a, int b) { return a + b; } Call: int sum = obj.add(10, 20); 📌 Working: Stack → add(10,20) executes returns 30 → stored in sum Execution → Result → Stack cleared 🔹 Types of Methods in Java 1️⃣ User-Defined Methods Methods created by programmer Ex: public void display() { System.out.println("User defined method"); } 2️⃣ Inbuilt Methods Methods already provided by Java Ex: Scanner sc = new Scanner(System.in); sc.nextInt(); sc.nextFloat(); sc.nextDouble(); sc.nextLine(); 🔹 Beauty of Methods ✨ Instead of writing: System.out.println("Hello"); System.out.println("Hello"); Write once: public void sayHello() { System.out.println("Hello"); } Call many times: obj.sayHello(); obj.sayHello(); ✔ Cleaner Code ✔ Less Code ✔ Better Structure 🔹 Key Points Summary ✔ Method = block of code ✔ Used for reuse and reduce code 🎯 My Learning Outcome – Day 11 Today I understood how methods make Java programs more structured, reusable, and efficient. Methods are the backbone of object behavior in Java. Learning step by step towards becoming a better Java developer 🚀 #Java #Methods #CoreJava #Programming #JavaLearning #TapAcademy #CodingJourney #JavaDeveloper #LearnJava #CodeReuse #ObjectOrientedProgramming
Java Methods: Code Reusability and Organization
More Relevant Posts
-
🚀 Day 13 TAP Academy | Understanding Methods in Java 💡 What is a Method? A method is a group of statements that together perform an operation. Methods help make programs modular, clean, and easy to maintain. Think of a method as a mini-program inside your main program — you define it once and call it whenever needed. 🧠 Syntax of a Method: returnType methodName(parameters) { // Method body // Code to perform the task } ✅ Example: public int add(int a, int b) { return a + b; } Here: public → Access modifier int → Return type add → Method name (int a, int b) → Parameters return a + b; → Method body 🔹 Why Methods Are Important ✔️ Eliminate code repetition ✔️ Increase code reusability ✔️ Simplify debugging and testing ✔️ Improve program readability and structure 🔸 Types of Methods in Java Java provides different types of methods based on their behavior and purpose 👇 🧩 1️⃣ Predefined (Built-in) Methods These are already defined in Java’s standard libraries. You just have to use them. ✅ Example: System.out.println("Hello Java!"); Math.sqrt(25); // returns 5.0 📚 These methods come from predefined classes like Math, String, System, etc. 🧱 2️⃣ User-defined Methods These are created by the programmer to perform specific tasks. ✅ Example: public class Calculator { void greet() { System.out.println("Welcome to TAP Academy!"); } int add(int a, int b) { return a + b; } public static void main(String[] args) { Calculator obj = new Calculator(); obj.greet(); System.out.println("Sum: " + obj.add(5, 10)); } } ✅ Output: Welcome to TAP Academy! Sum: 15 ⚙️ Based on Return Type TypeDescriptionExampleVoid MethodDoes not return any valuevoid greet() {}Return Type MethodReturns a value after executionint add() { return a+b; } 🧠 Based on Parameters TypeDescriptionExampleWithout ParametersDoesn’t accept any inputvoid display()With ParametersTakes input valuesvoid add(int a, int b) 🔁 Method Overloading When multiple methods have the same name but different parameters, it’s called method overloading. It increases code flexibility and reusability. ✅ Example: void show() { System.out.println("No Parameters"); } void show(int a) { System.out.println("Value: " + a); } 🧩 Difference Between Built-in and User-defined Methods FeatureBuilt-in MethodsUser-defined MethodsDefined byJava LibraryProgrammerPurposeCommon operationsSpecific tasksExamplesMath.pow(), System.out.println()add(), display() #TAPAcademy #JavaProgramming #Methods #LearningJourney #InternshipExperience #JavaDeveloper #CodingJourney #ProgrammingBasics #TechLearning #LearnToCode #CodeWithJava #SoftwareDevelopment #CodingCommunity #BuildInPublic #JavaConcepts #MethodOverloading
To view or add a comment, sign in
-
-
🚀 Week 8 at Tap Academy – Deep Dive into static in Core Java Week 8 was entirely focused on understanding the static keyword in Java — its purpose, behavior, memory impact, and execution flow. This topic helped me clearly understand the difference between class-level members and object-level members. 🔹 Understanding static in Java The static keyword indicates that a member belongs to the class itself, rather than to an instance (object) of the class. It can be applied to: Static variables Static methods Static blocks Static nested classes 🔹 Class Members vs Object Members In a Java class, we have: ▶ Class-Level Members (Static) Static variables Static methods Static blocks These belong to the class and are shared across all objects. ▶ Object-Level Members (Instance) Instance variables Instance methods Instance blocks Constructors These belong to each individual object. 🔹 Static Variables Stored in the method area (class area) of memory. *method area is also called as MetaData, Oldname of (method area) Permenent Generator short (PermGen). Only one copy exists per class, regardless of number of objects. Used when a value needs to be shared among all objects. Helps in memory efficiency because it avoids duplicate storage. Example use cases: Counters Common configuration values Shared constants 🔹 Static Methods Belong to the class. Can access only static members directly. Cannot directly access instance variables (because they require object reference). Can be called without creating an object. Important rule: 👉 Static methods cannot use this keyword. 🔹 Static Blocks Used for static initialization. Executed only once when the class is loaded into memory. Mostly used for initializing static variables. Useful for database driver loading, configuration loading, etc. 🔹 Instance Members ▶ Instance Variables Stored inside object memory (heap). Each object has its own copy. Can be accessed by instance methods directly. Can be accessed by static methods only through object reference. ▶ Instance Block Runs before the constructor. Used for object-level initialization logic. ▶ Constructor Used to initialize object state. Executes after instance block. 🔹 Execution Order in Java (Very Important) When a class is loaded: 1️⃣ Class loading happens 2️⃣ Static variables are initialized 3️⃣ Static blocks execute 4️⃣ Instance variables are initialized 5️⃣ Instance blocks execute 6️⃣ Constructor executes 7️⃣ Methods execute only when called This clarified the complete lifecycle of a class and object. 🔹 Why We Need static (Memory Perspective) Prevents unnecessary duplication of variables. Improves memory efficiency. Provides shared state across objects. Allows utility methods without object creation. Ensures class-level initialization before object creation. TAP Academy #TapAcademy #Week8Learning #CoreJava #StaticKeyword #JavaFundamentals #ClassLoading #MemoryManagement #LearningByDoing #FullStackJourney #VamsiLearns
To view or add a comment, sign in
-
-
🚀 Day 19 at TAP Academy – Exploring Java Arrays in Depth Today’s session was focused on gaining a deeper understanding of Java Arrays and how they are used in real programming scenarios. We started with a quick recap of the limitations of arrays, such as storing only homogeneous data, fixed size allocation, and the requirement of contiguous memory. 💡 One of the key topics covered was the three different ways to create arrays in Java: 1️⃣ Standard array creation using new keyword (most commonly used in real programs). 2️⃣ Creating arrays with predefined values using new int[]{} syntax. 3️⃣ Shorthand array initialization using {} without the new keyword. We also explored how arrays can be created for different primitive data types like byte, short, int, float, double, char, and boolean, along with the corresponding Scanner methods used to take input from users. 🔤 Another interesting concept was handling character input in Java, where we learned the workaround using: scan.next().charAt(0) since Java does not provide a direct nextChar() method. 📦 The session then moved to Arrays of Strings, which highlighted how Java treats Strings as objects and how they can be stored and accessed in arrays similar to primitive types. 👨💻 One of the most important parts of the class was learning about Arrays of Objects using an Employee class example. This helped in understanding: ✔ How objects are created and stored in arrays ✔ The concept of pass-by-reference ✔ How loops can be used to optimize code and avoid repetition when dealing with multiple objects This approach makes programs scalable and efficient, allowing the same logic to work whether we handle 2 objects or thousands of objects. ⚙️ Finally, we explored Command Line Arguments (String[] args), which clarified how Java programs can receive inputs directly from the command line during execution. This concept also introduced how all command-line inputs are treated as Strings, which leads into the next important topic — Java Strings. 📚 Key Takeaways from Today’s Session: • Different ways to create arrays in Java • Arrays with primitive data types and Scanner methods • Handling character input using charAt() • Working with arrays of Strings • Creating and managing arrays of objects • Understanding command line arguments in Java • Writing optimized and scalable code using loops Every session at TAP Academy continues to strengthen my core Java concepts and programming logic, bringing me one step closer to becoming a better developer. 💻✨ #Java #Programming #JavaArrays #LearningJourney #Coding #SoftwareDevelopment #TAPAcademy #JavaDeveloper 🚀
To view or add a comment, sign in
-
-
DAY 18: CORE JAVA TAP Academy 🚀 Understanding Method Overloading in Java Method Overloading is one of the core concepts of Compile-Time Polymorphism in Java. It allows a class to have multiple methods with the same name but different parameter lists. Let’s break down how method overloading is observed and identified 👇 🔹 1. Method Name The method name must be the same. Example: add() can have multiple definitions within the same class. 🔹 2. Number of Parameters If the number of parameters is different, the method is overloaded. int add(int a, int b) int add(int a, int b, int c) 🔹 3. Type of Parameters Even if the number of parameters is the same, changing the data type makes it overloaded. int add(int a, int b) double add(double a, double b) 🔹 4. Order of Parameters If parameter types are the same but in a different order, it is still valid overloading. void display(int a, String b) void display(String b, int a) 🔹 5. Type Conversion (Implicit Casting) Java follows method matching rules: Exact match Widening (int → long → float → double) Autoboxing Varargs Example: void show(int a) void show(double a) If we call show(5), Java chooses the most specific match (int). 🔹 6. Ambiguity in Method Overloading Ambiguity occurs when Java cannot determine which method to call. Example: void test(int a, float b) void test(float a, int b) Calling test(10, 10) creates confusion because both methods are possible after type conversion. ⚠️ The compiler throws an error in such cases. 📌 Important Terms Related to Method Overloading ✔️ Compile-Time Polymorphism ✔️ Static Binding ✔️ Early Binding ✔️ Method Signature (method name + parameter list) ✔️ Implicit Type Promotion ✔️ Varargs ✔️ Autoboxing 💡 Key Rule to Remember Changing only the return type does NOT achieve method overloading. int sum(int a, int b) double sum(int a, int b) ❌ (Invalid) ✨ Method overloading improves code readability, flexibility, and reusability. It allows developers to perform similar operations in different ways without changing method names. Mastering this concept is essential for cracking Java interviews and writing clean object-oriented code. #Java #OOPS #Programming #SoftwareDevelopment #Coding #LearningJourney
To view or add a comment, sign in
-
-
🚀 Mastering Method Overloading in Java – Compile Time Polymorphism 🚀 During my learning journey at Tap Academy, I explored one of the most important OOP concepts in Java — Method Overloading. 🔹 What is Method Overloading? Method Overloading is the process of creating multiple methods with the same name in the same class, but with different parameters. It is also known as Compile-Time Polymorphism because the method call is resolved during compilation by the Java compiler. 🔹 How Does Java Identify Overloaded Methods? The Java compiler differentiates overloaded methods based on: 1️⃣ Method Name 2️⃣ Number of Parameters 3️⃣ Type of Parameters ⚠️ Note: The return type alone cannot differentiate overloaded methods. 🔹 Real-Time Example in Java A common example of method overloading is: System.out.println(); The println() method is overloaded to accept different data types like int, float, char, String, boolean, etc. 🔹 Example: Calculator Class Using Method Overloading class Calculator{ public void add(int a, int b) { int c = a + b; System.out.println(c); } public void add(int a,int b, int c) { int d = a + b + c; System.out.println(d); } public void add(int a,float b) { float c = a + b; System.out.println(c); } public void add(float a,int b) { float c = a + b; System.out.println(c); } public void add(float a,float b) { float c = a + b; System.out.println(c); } } public class MethodOverloading { public static void main(String[] args) { Calculator calc = new Calculator(); calc.add(123,223); calc.add(22.87f, 32.0f); // calc.add(22.07,21); // Ambiguity occurs } } 🔹 Key Takeaways: ✔ Improves code readability ✔ Enhances reusability ✔ Allows flexibility in method usage ✔ Handled internally by the Java compiler Understanding method overloading helps build a strong foundation in Object-Oriented Programming concepts in Java. Grateful to Tap Academy for guiding me through these core Java fundamentals 🙌 #Java #CoreJava #OOPS #MethodOverloading #CompileTimePolymorphism #LearningJourney #TapAcademy TAP Academy
To view or add a comment, sign in
-
-
🚀 AI Powered Java Full Stack Journey with Frontlines EduTech (FLM) – Day 6 📌 Strings & Operators in Java — Understanding Data and Actions Day 6 helped me understand how Java handles text using Strings and how operators perform calculations and updates. This session made coding feel more practical and structured. 🔷 String (Non-Primitive Data Type) String is not a primitive type — it is a class. It stores a sequence of characters including letters, numbers, spaces, and symbols. String name = "Charan"; String course = "Java Full Stack"; Key Points: • Default value of a class reference = null • Size ≈ characters × 2 bytes (excluding object overhead) • Strings belong to java.lang (no import needed) • Spaces are counted as characters ⭐ Why String Matters Used in forms, login systems, messages, and user input. It plays a major role in real-time applications. 🔹 Immutability Once created, a String cannot be changed. If modified, a new object is created. String s = "Java"; s = "FullStack"; // new object 🔹 Common Methods name.length(); name.toUpperCase(); name.charAt(0); name.contains("Java"); 🔹 Empty vs Null String a = ""; // length = 0 String b = null; // no reference Calling methods on null causes NullPointerException. 🔥 Operators in Java Operators perform operations on values and variables. 1️⃣ Arithmetic Operators int a = 10, b = 5; a + b; // Addition a - b; // Subtraction a * b; // Multiplication a / b; // Division a % b; // Remainder Note: 10 / 0 → Error 10.0 / 0 → Infinity 2️⃣ Assignment Operators int a = 10; a += 5; a -= 2; a *= 3; a /= 4; a %= 5; They make value updates shorter and more efficient. 🎯 Day 6 Takeaways ✨ String is a class and immutable ✨ Understanding null vs empty ✨ Practical use of String methods ✨ Strong clarity on arithmetic operators ✨ Efficient use of assignment operators Each day is strengthening my Java fundamentals and coding confidence. Grateful for the continuous learning journey 🚀 Thanks to Krishna Mantravadi, Upendra Gulipilli, and Fayaz S for the clear and practical teaching. #Java #JavaBasics #JavaOperators #StringsInJava #FullStackDeveloper #LearningInPublic #Day6 #FrontlinesEduTech
To view or add a comment, sign in
-
🚀 Day 21 | Core Java Learning Journey 📌 Topic: Exception Handling Keywords in Java Today I learned the most important Java exception handling keywords: try, catch, finally, throw, throws — and the commonly confused finalize(). Understanding them is essential for writing clean, production-ready Java code 💡 🔹 try ✔ Wraps risky code ✔ Must be followed by catch or finally ✔ Cannot exist alone ✔ Multiple catch blocks allowed Syntax : try { // risky code } catch(Exception e) { // handling } 🔹 catch ✔ Handles exceptions from try ✔ Takes exception object as parameter ✔ Order matters (Child → Parent) ✔ Multiple catch blocks allowed 🔹 finally ✔ Always executes (whether exception occurs or not) ✔ Executes even if return statement is present ✔ Used for cleanup (files, DB, etc.) ✔ Won’t execute only if JVM crashes or System.exit() is called 🔹 throw ✔ Explicitly throws an exception ✔ Used inside method body ✔ Can throw checked & unchecked exceptions ✔ Followed by exception object throw new IllegalArgumentException("Invalid Age"); 🔹 throws ✔ Declares exception responsibility ✔ Used in method signature ✔ Mainly for checked exceptions ✔ Can declare multiple exceptions public void readFile() throws IOException { // code } 🔥 throw vs throws ✔ throw → Inside method body ✔ throws → In method declaration ✔ throw → Single exception ✔ throws → Multiple exceptions 🔹 finalize() (Important) ✔ NOT part of exception handling ✔ Belongs to Garbage Collection ✔ Defined in Object class ✔ Called before object destruction ✔ Deprecated (Java 9+) 🔥 finally vs finalize() ✔ finally → Exception handling block ✔ finalize() → GC method ✔ finally → (Almost) always runs ✔ finalize() → May or may not run 📌 Key Takeaways ✔ finally ensures cleanup ✔ throw creates exceptions ✔ throws delegates responsibility ✔ finalize() relates to memory management Small keywords — powerful concepts 💻🚀 Special thanks to Vaibhav Barde Sir . #CoreJava #JavaLearning #ExceptionHandling #JavaDeveloper #OOP #LearningJourney
To view or add a comment, sign in
-
-
🚀 Day 12 @ TAP Academy | Understanding Variables in Java! 💡 What is a Variable in Java? A variable defines a storage location in memory with a specific data type that determines what kind of value it can hold. 🧠 Syntax: dataType variableName = value; ✅ Example: int age = 20; String name = "Eswar"; 🔸 Types of Variables in Java There are three main types of variables in Java: 1️⃣ Local Variables 2️⃣ Instance Variables 3️⃣ Static Variables Let’s explore the first two in detail 👇 🔹 1️⃣ Local Variables A Local Variable is declared inside a method, constructor, or block and is accessible only within that scope. 💡 Key Points: Created when the method starts, destroyed when it ends Must be initialized before use Not accessible outside its method or block ✅ Example: public void display() { int count = 5; // Local variable System.out.println("Count: " + count); } 🔸 2️⃣ Instance Variables An Instance Variable is declared inside a class but outside any method. It belongs to an object and each object has its own copy of instance variables. 💡 Key Points: Created when an object is created, destroyed when it’s deleted Accessed using object reference Default values are automatically assigned ✅ Example: public class Student { String name; // Instance variable int marks; // Instance variable void display() { System.out.println(name + " scored " + marks + " marks."); } } ⚖️ Difference Between Local and Instance Variables FeatureLocal VariableInstance VariableDeclared InsideMethod, constructor, or blockInside class but outside any methodScopeOnly within the method or blockAvailable to all methods in the classDefault ValueNone (must be initialized)Has a default value (e.g., 0, null)Memory LocationStack memoryHeap memoryAccess ModifierCannot use (private/public)Can use access modifiersLifetimeCreated when method is called and destroyed when it endsExists as long as the object exists. 🌟 Example Program public class Example { int number = 10; // Instance variable void show() { int count = 5; // Local variable System.out.println("Local Variable: " + count); System.out.println("Instance Variable: " + number); } public static void main(String[] args) { Example obj = new Example(); obj.show(); } } ✅ Output: Local Variable: 5 Instance Variable: 10 💬 Key Takeaways ✔️ Variables help manage data efficiently ✔️ Local variables exist temporarily during execution ✔️ Instance variables are tied to the object’s lifetime ✔️ Understanding both helps control scope, memory, and data flow effectively. #TAPAcademy #JavaProgramming #VariablesInJava #LocalVariable #InstanceVariable #LearningJourney #CodingJourney #JavaDeveloper #ProgrammingBasics #TechLearning #InternshipExperience #CodeWithJava #SoftwareDevelopment #BuildInPublic #CodingCommunity
To view or add a comment, sign in
-
-
🚀 Day 17 @ TAP Academy | Introduction to Strings in Java Today at TAP Academy, we explored a core concept of Java programming — the String! ☕💻 💡 What is a String in Java? A String is a sequence of characters enclosed within double quotes ("). In Java, a string is actually an object of the String class, not just a data type. 🧠 Simple Definition: A string is a collection of characters used to represent text in Java. ✅ Example: String name = "TAP Academy"; System.out.println(name); 📘 Output: TAP Academy 🧩 Different Ways to Create a String There are two main ways to create strings in Java 👇 1️⃣ Using String Literal String s1 = "Hello"; String s2 = "Hello"; 🟢 Java reuses the same memory in the String Constant Pool, making it efficient. 2️⃣ Using new Keyword String s3 = new String("Hello"); 🔵 Creates a new object in heap memory, even if the same value exists. ⚙️ Common String Methods Strings in Java come with many useful built-in methods that make text handling simple: MethodDescriptionExamplelength()Returns string length"TAP".length() → 3charAt()Returns character at index"Java".charAt(2) → vtoUpperCase()Converts to uppercase"tap".toUpperCase() → TAPtoLowerCase()Converts to lowercase"TAP".toLowerCase() → tapconcat()Joins two strings"TAP".concat(" Academy") → TAP Academyequals()Compares strings"Java".equals("JAVA") → false 🧠 String Characteristics ✔️ Strings are immutable – once created, they cannot be changed. ✔️ They are stored in the String Constant Pool for memory efficiency. ✔️ The String class is part of the java.lang package (imported automatically). ✔️ For mutable strings, we use StringBuilder or StringBuffer. 🔍 Example Program public class StringExample { public static void main(String[] args) { String course = "TAP Academy"; System.out.println("Length: " + course.length()); System.out.println("Uppercase: " + course.toUpperCase()); System.out.println("Character at index 4: " + course.charAt(4)); } } ✅ Output: Length: 11 Uppercase: TAP ACADEMY Character at index 4: c 💬 Why Strings Are Important ✔️ Used in almost all applications (names, messages, input/output). ✔️ Essential for working with user input, file handling, and APIs. ✔️ Foundation for text processing and data communication in Java. #TAPAcademy #JavaProgramming #StringsInJava #CoreJava #LearningJourney #InternshipExperience #CodingJourney #ProgrammingBasics #LearnToCode #BuildInPublic #JavaDeveloper #TechLearning #SoftwareDevelopment #CodingCommunity #ObjectOrientedProgramming
To view or add a comment, sign in
-
-
📘 Java Learning – Multithreading (Part 1: Multitasking & Thread Creation) 🚀🎯 Starting my learning journey into Java Multithreading, one of the most powerful features of Java used for executing multiple tasks simultaneously. 🔰 Multitasking Executing several tasks simultaneously is called Multitasking. There are two types of multitasking: 👉 Process Based Multitasking 👉 Thread Based Multitasking 1️⃣ Process Based Multitasking Executing several tasks simultaneously where each task is a separate independent process. Example: Running multiple applications at the same time: • Browser • Music Player • Code Editor ✔ Best suited at Operating System level 2️⃣ Thread Based Multitasking (Multithreading) Executing several tasks simultaneously where each task is an independent part of the same program. Each independent path of execution is called a Thread. ✔ Best suited for Programmatic level 🎯 Objective of Multitasking • Improve system performance • Reduce response time 📌 Applications of Multithreading Multithreading is widely used in: • Video games • Multimedia graphics • Animations • High performance applications 🔰 Multithreading Support in Java Java provides rich API support for multithreading through: • Thread • Runnable • ThreadGroup • ThreadLocal ✔ Java provides built-in APIs for multithreading, and programmers use these APIs to create and manage threads. This makes multithreading easier in Java compared to C++. 🔰 Ways to Create a Thread A thread can be defined in two ways: 1️⃣ Extending Thread class 2️⃣ Implementing Runnable interface 📌 Example – Extending Thread Class class MyThread extends Thread { public void run() { for(int i=0;i<5;i++){ System.out.println("Child Thread"); } } } public class ThreadDemo { public static void main(String[] args) { MyThread t = new MyThread(); // instantiation of thread t.start(); // starting of a thread for(int i=0;i<5;i++){ System.out.println("Main Thread"); } } } 📌 start() does NOT directly execute run(). It does: start() ↓ JVM asks Thread Scheduler ↓ New Thread Created ↓ run() executes in new thread ⭐ Key Points • start() method creates a new thread • run() contains the task executed by thread • Multiple threads execute simultaneously More concepts like Thread Scheduler, start() vs run(), Thread Lifecycle in the next post. #Java #CoreJava #Multithreading #JavaDeveloper #Concurrency #LearningJourney
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