Today I Learned: Static vs Non-Static in Java — Order of Execution While revising core Java, I finally got a clear understanding of how the JVM executes static and non-static members. This topic looks simple, but it’s one of the most asked interview concepts! 💡 Key Takeaways: 🔹 Static members belong to the class Static variables load first Static blocks run once when class loads main() starts after static initialization 🔹 Non-static members belong to the object Instance variables load during object creation Non-static blocks run before constructor Constructor initializes the object Instance methods run when called 🔥 Execution Flow Simplified Class Loading → Static Vars → Static Block → main() → Object Creation → Instance Vars → Init Block → Constructor → Methods #Java #JavaProgramming #JavaDeveloper #SoftwareDevelopment #Programming #Coding #BackendDevelopment #TechLearning #Developers #LearnToCode #ProgrammingCommunity #100DaysOfCode #CodeNewbie #TechCareer #SoftwareEngineer
Java Static vs Non-Static Execution Order
More Relevant Posts
-
☕ Java Core Concepts – Interview Question 📌 What is Runtime (Dynamic) Polymorphism? In Java, Runtime Polymorphism (also called Dynamic Method Dispatch) is a concept where the method to be executed is determined at runtime, not at compile time. 🔹 Key Points: ✔ Achieved through Method Overriding ✔ Method call is resolved during execution ✔ Depends on the object type, not reference type 🔹 How it Works: • A parent class reference points to a child class object • The overridden method in the child class is executed 🔹 Why it’s Important: ✔ Enables flexibility and extensibility ✔ Supports runtime decision making ✔ Improves code reusability 💡 In Short: Runtime polymorphism allows Java to decide which method to call at runtime, based on the actual object, enabling dynamic behavior in applications. 👉For Java Course Details Visit :https://lnkd.in/gwBnvJPR . #Java #CoreJava #Polymorphism #JavaInterview #Programming #Coding #TechSkills
To view or add a comment, sign in
-
-
Ever wondered what happens internally when a Java class gets loaded? 🤔 When a class is used for the first time, JVM follows a fixed sequence: 1️⃣ Static Variable Initialization 2️⃣ Static Block Execution 3️⃣ Class Becomes Ready And when an object is created: 4️⃣ Instance Variable Initialization 5️⃣ Instance Block Execution 6️⃣ Constructor Execution So the actual flow looks like this: Static Variable → Static Block → Instance Variable → Instance Block → Constructor Important points: Static blocks run only once when the class is loaded Constructors run every time an object is created Static methods can be called without creating an object Non-static methods require an object This is one of the most commonly asked concepts in Java interviews. #Java #JVM #JavaDeveloper #Programming #Coding #SoftwareEngineer #BackendDevelopment #JavaInterview #Developers
To view or add a comment, sign in
-
-
📒 Day 29 of Java | Binding says, “I know who to call,” while static methods in method hiding are like twins — same name, different behavior. Today I learned about binding in Java, which refers to the process of linking a method call with its method body. 👉 There are two types of binding: ➲ Static Binding: The method call is resolved at compile time. It is used for method overloading, private methods, final methods, and static methods. ➲ Dynamic Binding: The method call is resolved at runtime. It is mainly used for method overriding and supports runtime polymorphism. 👉 I also learned about method hiding in Java. When a subclass defines a static method with the same signature as a static method in the parent class, it is called method hiding. These concepts made Java’s method handling feel even more interesting. #Java #CoreJava #Programming #Coding #ObjectOrientedProgramming #LearnInPublic #100DaysOfCode #DeveloperJourney #SoftwareDeveloper #BuildInPublic #StudentDeveloper #TechStudents
To view or add a comment, sign in
-
Java is called an object-oriented language… but that’s not entirely true. Here’s the Truth 👇 🔹 Not everything in Java is an object Primitive types like int, char, double exist outside OOP 🔹 Static breaks pure OOP Static methods and variables belong to the class, not objects 🔹 You can write Java without creating a single object (main method is static for a reason) So no, Java is not 100% object-oriented. #Java #Programming #OOP #SoftwareDevelopment #Coding
To view or add a comment, sign in
-
-
Stop being confused by Java Collections. Here's the whole picture in 30 seconds 👇 Most developers use ArrayList for everything. But Java gives you a powerful toolkit — if you know when to use what. 📋 LIST — When ORDER matters & duplicates are OK ArrayList → Fast reads ⚡ LinkedList → Fast inserts/deletes 🔁 🔷 SET — When UNIQUENESS matters HashSet → Fastest, no order LinkedHashSet → Insertion order TreeSet → Sorted order 📊 🔁 QUEUE — When the SEQUENCE of processing matters PriorityQueue → Process by priority ArrayDeque → Fast stack/queue ops 🗺️ MAP — When KEY-VALUE pairs matter HashMap → Fastest lookups 🔑 LinkedHashMap → Preserves insertion order TreeMap → Sorted by keys 🧠 Quick Decision Rule: Need duplicates? → List Need uniqueness? → Set Need FIFO/Priority? → Queue Need key-value? → Map The right collection = cleaner code + better performance. 🚀 Save this. Share it with a dev who still uses ArrayList for everything. 😄 #Java #Collections #Programming #SoftwareDevelopment #100DaysOfCode #JavaDeveloper #Coding #TechEducation #SDET
To view or add a comment, sign in
-
-
🚀 Java Practice: Longest Substring Without Repeating Characters Today I practiced a classic string problem in Java – finding the Longest Substring Without Repeating Characters. 🔹 Problem Statement: Given a string, find the longest substring that does not contain any repeating characters. 🔹 Approach I Used: I implemented a simple nested loop approach: Start checking substring from each index. Keep adding characters until a duplicate character appears. If a duplicate is found, break the loop. Track the maximum length substring during iteration. 💡 Key Concepts Used: String manipulation Nested loops indexOf() method Conditional logic 🧠 Why this problem is useful? This problem helps strengthen understanding of strings, loops, and algorithmic thinking, which are very important for coding interviews and problem solving. 📌 Example Input: "tessdfgteststest" 📌 Output: Longest substring without repeating characters. #Java #DSA #CodingPractice #ProblemSolving #JavaDeveloper #Programming #LearningJourney
To view or add a comment, sign in
-
-
This one Java concept silently breaks your understanding of OOP. Static methods are not overridden. They are hidden. Most developers don’t realize this until an interview exposes it. Let’s take a simple example: look at code image Challenge: What do you think this prints? What will be the output if we remove static from both methods? Let’s see how you reason about it 👇 #Java #BackendDevelopment #SoftwareEngineering #OOP #JavaDeveloper
To view or add a comment, sign in
-
-
🚀 Master Java Streams API – The Complete Guide with Practical Examples If you're still writing long loops in Java… you're missing out on one of the most powerful features introduced in Java 8. I’ve published a complete, practical guide on Java Streams API covering: ✅ What Streams really are (beyond theory) ✅ Intermediate vs Terminal operations ✅ Real-world examples (filter, map, reduce, grouping) ✅ Performance tips & when NOT to use streams ✅ Clean, readable, production-ready code Streams bring functional programming to Java, making your code more concise, readable, and maintainable. 💡Whether you're preparing for interviews or building scalable backend systems, this guide will help you level up. 🔗 Read here: https://lnkd.in/gD6ETYDH 💬 What’s your favorite Stream operation? map, filter, or reduce? #Java #JavaStreams #BackendDevelopment #SpringBoot #Programming #Coding #SoftwareEngineering #TechBlog #Developers #100DaysOfCode
To view or add a comment, sign in
-
⛓️💥 𝐒𝐲𝐬𝐭𝐞𝐦.𝐨𝐮𝐭.𝐩𝐫𝐢𝐧𝐭𝐥𝐧("𝐇𝐞𝐥𝐥𝐨 𝐖𝐨𝐫𝐥𝐝"); let's break this line to understand step by step We use this in almost every Java program. But have you ever thought what’s happening behind the scenes? 🪩 𝐒𝐲𝐬𝐭𝐞𝐦 A predefined class in Java from java.lang package ♟️𝐨𝐮𝐭 "out" is actually an object of type PrintStream. PrintStream is a class inside "System" class. 𝐏𝐫𝐢𝐧𝐭𝐒𝐭𝐫𝐞𝐚𝐦 : A class used to print output ♟️ 𝐩𝐫𝐢𝐧𝐭𝐥𝐧() (Instance method) A method of PrintStream class Used to print output with a new line 🔍 Putting it all together 𝐒𝐲𝐬𝐭𝐞𝐦.𝐨𝐮𝐭.𝐩𝐫𝐢𝐧𝐭𝐥𝐧("𝐇𝐞𝐥𝐥𝐨"); "System" → class "out" → static reference variable "println()" → method ➡️ So internally we are calling println() method using PrintStream object ("out") 🎈 𝐈𝐦𝐩𝐨𝐫𝐭𝐚𝐧𝐭 𝐈𝐧𝐬𝐢𝐠𝐡𝐭 "out" is already created [static] That’s why we don’t use "new" here 🎈 𝐒𝐢𝐦𝐩𝐥𝐞 𝐰𝐚𝐲 𝐭𝐨 𝐮𝐧𝐝𝐞𝐫𝐬𝐭𝐚𝐧𝐝 System → class out → object println() → action 📞We are calling 𝐩𝐫𝐢𝐧𝐭𝐥𝐧() method of PrintStream object (out) to print output. #Java #JavaDeveloper #JavaBackend #Programming #TechJourney #LearnBySharing #JavaConcepts #Coding #InterviewPrep
To view or add a comment, sign in
-
Day 3 of Java Interview Prep 🚀 4 Pillars of OOP 👇 1. Encapsulation 2. Inheritance 3. Polymorphism 4. Abstraction 💡 If you understand this, you understand Java Follow for Day 4 🔥
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