Understanding static in Java | JVM Execution Flow 📍 Learned at TAP Academy As part of my Java learning journey at TAP Academy, I explored the concept of static and how it works inside the JVM. 🔎 What happens when a Java program runs? When we execute a Java program: 1️⃣ The JVM (Java Virtual Machine) loads the class into memory. 2️⃣ While loading the first class, JVM checks for: ✅ Static variables ✅ Static blocks ✅ Static methods 3️⃣ After loading static members, JVM looks for the entry point: public static void main(String[] args) ⚡ Why is main() static? Because the JVM must call it without creating an object of the class. 💡 What is static in Java? static members belong to the class, not to objects. Memory is allocated only once in the class area. Shared among all objects of the class. 🔹 Static Variable Common property shared by all objects. Saves memory because only one copy is created. 🔹 Static Block Executes only once when the class is loaded. Used for initialization of static variables. 🎯 Understanding static helped me clearly visualize how JVM loads classes and manages memory. Grateful to TAP Academy for strengthening my Java fundamentals 🙌 #Java #OOPS #JVM #TAPAcademy #Programming #LearningJourney
Java Static Explained: JVM Execution Flow
More Relevant Posts
-
🚀 Understanding the Internal Execution Flow in Java. Ever wondered what really happens under the hood when you run a Java program? It is much more than just the main method!. In my latest learning session at TAP Academy with Sharath R sir, I learned about the seven essential elements of a Java class: static variables, static blocks, static methods, instance variables, instance blocks, instance methods, and constructors. Here are the key takeaways: 🔹 Static vs. Instance: A fundamental rule is that static members belong to the class, while instance members belong to the object. 🔹 The Class Loader: When the JVM needs a class, it calls its "closest friend," the Class Loader, to locate and load the class into the code segment. 🔹 Order of Execution: Java execution follows a strict sequence. It starts with static variables and static blocks during class loading, long before the main method or any object creation occurs. 🔹 The "Illegal" Access Rule: You cannot access instance variables from a static block or method. Why? Because static members are initialized during class loading, at which point the object (and its instance variables) does not even exist yet. Understanding the internal memory flow—from the static segment to the heap and stack—is the first step toward mastering Java's object-oriented pillars. #Java #Programming #SoftwareDevelopment #oops #ObjectOrientedProgramming #TechLearning #Tap Academy
To view or add a comment, sign in
-
-
💻 Understanding the Object Class and toString() Method in Java Day 31 at #TAPACADEMY As part of my journey in learning Java and Object-Oriented Programming, I explored the Object class, which is the root of the entire Java class hierarchy. 🔹 Object Class in Java The Object class is the parent class of all classes in Java. Every class automatically inherits methods from it, either directly or indirectly. Some commonly used methods provided by the Object class include: ✔ equals() – Used to compare two objects ✔ hashCode() – Generates a unique hash value for objects ✔ clone() – Creates a copy of an object ✔ toString() – Returns the string representation of an object 🔹 toString() Method The toString() method is used to convert an object into a readable string representation. By default, it returns the class name and hash code, but it can be overridden to display meaningful information about an object. Overriding this method helps improve readability, debugging, and logging in Java applications. 📚 Understanding the Object class gives deeper insight into how Java manages objects and inheritance, making it a fundamental concept in mastering Java programming. Trainer : Sharath R #Java #ObjectOrientedProgramming #OOP #JavaDeveloper #Programming #LearningJourney #SoftwareDevelopment
To view or add a comment, sign in
-
-
🚀 Day 40 – Java Object Class | TAP Academy Learning Series Today at TAP Academy, I learned about the Object Class, which is the root of the Java class hierarchy. Every class in Java automatically inherits methods from the Object class. 🔹 Common Object Class Methods: toString(), equals(), hashCode(), clone(), getClass(), wait(), notify(), notifyAll(). 🔹 toString() Method Used to return the string representation of an object. We often override it to print meaningful object details instead of the default ClassName@HashCode. 🔹 clone() Method Creates a separate copy of an object or array, so changes in one reference don’t affect the other. 🔹 Is Java Pure OOP? No, because Java has primitive data types. But using Wrapper Classes like Integer, Double, etc., primitives can be treated as objects. Understanding the Object class methods helps in writing better and more efficient Java programs. #Java #CoreJava #ObjectClass #TAPAcademy #JavaLearning TAP Academy Sharath R
To view or add a comment, sign in
-
-
🚀 Understanding Default, Static, and Private Methods in Java Interfaces As part of my learning journey at Tap Academy, I recently explored some powerful features introduced in Java interfaces starting from JDK 8 and JDK 9. These features allow interfaces to contain concrete methods, making them more flexible and powerful. Here’s a quick summary of what I learned: 🔹 Default Methods (JDK 8) The default keyword allows us to define concrete methods inside an interface. Example: public default void methodName() { // implementation } Key points: Default methods participate in inheritance. They can be overridden in the implementing (child) class. In the child class, we should NOT use the default keyword while overriding. Introduced mainly for backward compatibility, allowing new methods to be added to interfaces without breaking existing implementations. 🔹 Static Methods (JDK 8) Interfaces can also have static methods. Example: public static void methodName() { // implementation } Key points: Accessed using InterfaceName.methodName() Can be used without creating objects or implementing the interface Useful for utility/helper methods related to the interface Static methods cannot be overridden 🔹 Private Methods (JDK 9) Private methods were introduced to avoid code duplication inside interfaces. Example: private void methodName() { // implementation } Key points: Accessible only within the interface. Used to support default methods. Static methods cannot access non-static private methods. To solve this, we can create a private static method: private static void methodName() { // implementation } 🔹 Summary Interfaces can contain concrete methods using default, static, and private. default and static methods were introduced in JDK 8. private and private static methods were introduced in JDK 9. Grateful to Tap Academy for helping me understand these important Java concepts and strengthening my core Java knowledge. Looking forward to applying these concepts in real-world projects! #Java #CoreJava #JavaLearning #Programming #SoftwareDevelopment #JavaDeveloper #TapAcademy #LearningJourney TAP Academy
To view or add a comment, sign in
-
-
📚 Day 37 – Core Java Learning Journey at Tap Academy 🚀 Today I learned about the Rules of Method Overriding in Java, an important concept in Inheritance and Runtime Polymorphism. 🔹 Key Rules of Method Overriding: • The method must have the same name as the method in the parent class. • The parameters (method signature) must be the same. • The return type must be the same or covariant. • The method in the child class cannot have a more restrictive access modifier than the parent method. • Final methods cannot be overridden. • Static methods cannot be overridden (they are method hidden). • The overriding method can throw same or fewer exceptions than the parent method. 💡 Understanding these rules helps in writing flexible, reusable, and maintainable Java programs. Every day I’m getting closer to mastering Core Java and problem-solving. 💪 #Day37 #Java #CoreJava #MethodOverriding #Inheritance #Polymorphism #LearningJourney #TapAcademy #JavaDeveloper #WomenInTech
To view or add a comment, sign in
-
-
💫 Understanding Inheritance in Java | TAP Academy As part of my Java learning journey at TAP Academy, I explored the concept of Inheritance, one of the core principles of Object-Oriented Programming (OOP). 🔎 What is Inheritance? Inheritance is the process by which one class acquires the properties (variables) and behaviors (methods) of another class. In Java, inheritance is achieved using the extends keyword. 📌 Advantages of Inheritance ✅ Code Reusability ✅ Reduces development time and effort ✅ Improves productivity and maintainability 📚 Types of Inheritance 1️⃣ Single Inheritance One class inherits from another class. Example: ClassB extends ClassA ClassA │ ClassB 2️⃣ Multilevel Inheritance A class inherits from another class, and another class inherits from it. ClassA │ ClassB │ ClassC 3️⃣ Hierarchical Inheritance Multiple classes inherit from a single parent class. ClassA / \ ClassB ClassC 4️⃣ Hybrid Inheritance Combination of single inheritance and hierarchical inheritance. ClassA │ ClassB / \ ClassC ClassD 5️⃣ Multiple Inheritance A class inherits from more than one parent class. ⚠️ Note: Multiple inheritance is not supported in Java using classes because it creates the Diamond Problem. Diamond Problem Diagram ClassA / \ ClassB ClassC \ / ClassD Here, ClassD receives properties from both ClassB and ClassC, which both inherit from ClassA, causing ambiguity. 6️⃣ Cyclic Inheritance ClassA ←→ ClassB This occurs when classes depend on each other in a cycle. ⚠️ Note: Cyclic inheritance is not allowed in Java because it creates logical conflicts. 💡 Conclusion Inheritance helps developers reuse existing code, build relationships between classes, and create scalable applications. Learning these OOP concepts is helping me strengthen my Java programming fundamentals. #Java #OOP #Inheritance #JavaProgramming #CodingJourney #TAPAcademy #LearningJava #SoftwareDevelopment 💻
To view or add a comment, sign in
-
-
🚀 Java Learning Journey — Day 6 Today I continued strengthening my Java fundamentals and explored an important concept: Static vs Instance behavior in Java. 🔹 Learned the difference between instance methods and static methods 🔹 Understood why static methods belong to the class, not the object 🔹 Explored static variables and how a single copy is shared across all objects 🔹 Studied how Java manages memory using Stack, Heap, and Method Area One key realization today: Static members are created when the class is loaded into the JVM, not when objects are created. This explains why all objects share the same static variable. Small concepts like these build the foundation for understanding how Java actually works internally. Looking forward to continuing tomorrow with Static Blocks and class loading behavior. #Java #LearningJourney #BackendDevelopment #Programming #SoftwareDevelopment #100DaysOfCode
To view or add a comment, sign in
-
💻 Exploring Method Overriding & the final Keyword in Java Day 30 at #TapAcademy Continuing my journey in Object-Oriented Programming (OOP) with Java, I explored two important concepts: Method Overriding and the final keyword. 🔹 Method Overriding Method overriding occurs when a child class provides its own implementation of a method that is already defined in the parent class. It enables runtime polymorphism, allowing methods to behave differently based on the object that calls them. 📌 Key Rules of Method Overriding: ✔ The method name must be the same as in the parent class ✔ The parameter list must remain the same ✔ The return type must be the same or covariant ✔ The access modifier cannot be more restrictive than the parent method ✔ Static, private, and final methods cannot be overridden 🔹 final Keyword in Java The final keyword is used to restrict modification in Java programs. 📌 It can be used in three ways: • Final Variable – The value cannot be changed once assigned • Final Method – The method cannot be overridden in a child class • Final Class – The class cannot be inherited Understanding these concepts helps in controlling inheritance, protecting code from unwanted changes, and implementing runtime polymorphism effectively. 📚 Always excited to deepen my knowledge in Java and OOP concepts as I continue learning and building! Trainer: Sharath R #Java #OOP #MethodOverriding #FinalKeyword #Programming #SoftwareDevelopment #LearningJourney
To view or add a comment, sign in
-
-
Day 9 – Java Learning Journey Today I continued strengthening my Java fundamentals, focusing on method overriding and important rules in inheritance. Key concepts I explored: • Method Overriding Rules in Java The child class method must have the same method signature as the parent class method. The return type must be the same or covariant (a subclass of the parent return type). The method cannot be static, because static methods belong to the class rather than the object. • Covariant Return Types Java allows a child class method to return a more specific type than the parent class method, making inheritance more flexible. • Static vs Instance Methods I also learned why static methods cannot be overridden and are instead method hidden, which behaves differently from runtime polymorphism. Step by step, continuing to build a stronger foundation in Core Java and OOP concepts. 🚀 #Java #CoreJava #OOP #MethodOverriding #Programming #SoftwareDevelopment #LearningJourney
To view or add a comment, sign in
-
📘 Day 18 of My Java Learning Journey ☕💻 Today I learned about the concept of the main method and method types in Java, which help in writing structured, reusable, and organized programs. 👉 What is a Method? A method is a block of code that performs a specific task. It allows us to reuse code and avoid repetition in a program. 👉 What is Method Signature? A method signature consists of the method name and parameter list. It defines how the method is called. 👉 What is Method Declaration? The declaration specifies the return type, method name, and parameters. 👉 What is Method Definition? The definition contains the actual implementation of the method, where the program logic is written. 👉 Types of Method in Java I practiced today: 1️⃣ With return type and with arguments. 2️⃣ With return type and without arguments. 3️⃣ Without return type and without arguments. 4️⃣ Without return type and with arguments. Understanding the concept of method helps in breaking a program into smaller reusable parts, making the code easier to read and maintain. Step by step, I am strengthening my Java fundamentals. #JavaDeveloper #LearnJava #JavaProgramming #CodingJourney #DailyCoding #DeveloperJourney #CodePractice #ProgrammingLife #TechLearning
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