📘 Day 15 ,16,17– Understanding Methods in Java & JVM Execution On Day 15,16,17 I explored one of the most fundamental building blocks of Java — Methods. 🔹 What is a Method? A method is a block of code defined inside a class that performs a specific task. It improves code reusability, readability, and modularity. 🔹 Method Signature Includes: Access specifier Return type Method name Parameters (inside parentheses) 🔹 Types of Methods in Java: No Input, No Output No Input, With Output With Input, No Output With Input, With Output 🔹 JVM & Memory Flow (Behind the Scenes): When program execution starts, the object is created in the Heap segment The reference variable is stored in the Stack segment Each method call creates a new stack frame After method execution, its stack frame is removed Finally, the main() method stack frame is removed Objects without references become garbage, collected by the Garbage Collector 🔹 Execution Order Java follows LIFO (Last In, First Out) principle in stack memory: Last method called → First method removed 🔹 Important Concept Parameters → Variables that receive values Arguments → Values passed to the method Understanding how methods work internally with the JVM helps write efficient, optimized, and interview-ready code. Learning step by step and enjoying the journey 🚀 #Java #CoreJava #MethodsInJava #JVM #StackAndHeap #LearningJourney #Day15 #ProgrammingConcepts
Java Methods & JVM Execution Fundamentals
More Relevant Posts
-
Day 4 | Full Stack Development with Java Today I explored one of the most important concepts in Java — the Main Method and how execution actually begins inside a program. What I learned today: Control of Execution In Java, execution always starts from the main() method. Even if multiple functions exist, none will run unless the main method gives control. The JVM looks for a specific signature to start execution. Why public static void main(String[] args)? public → Makes the method visible to JVM. static → Allows execution without creating an object. void → No return value. String[] args → Stores command-line inputs as an array. Command Line Arguments (args) args collects data passed during program execution. It acts like a dynamic array that stores runtime inputs. Helps make programs flexible and dynamic. Object Creation Reminder Objects are created using the new keyword. Steps include declaration, instantiation, and initialization. Key Takeaway Understanding how the main method controls execution helped me realize how Java programs actually start running behind the scenes. Strong fundamentals are making advanced backend concepts easier to understand. #Day4 #Java #MainMethod #FullStackDevelopment #LearningInPublic #SoftwareDevelopment
To view or add a comment, sign in
-
-
🚀 Day 13 – Java Full Stack Journey | Understanding Variables & Memory in Java Today’s session was about something every developer must truly understand — How Java manages memory internally. Not just writing code, but understanding what happens inside RAM when a program runs. 🧠 🔹 Variables in Java A variable is a container used to store data. Java mainly has two important types of variables: ✔ Instance Variables ✔ Local Variables 🔹 Instance Variables Declared directly inside a class Memory allocated inside the Heap segment Stored inside objects Automatically assigned default values by Java Example: class Demo { int a; float b; boolean c; } Default values: int → 0 float → 0.0 boolean → false char → empty character 🔹 Local Variables Declared inside a method Memory allocated inside the Stack segment ❌ No default values Must be initialized before usage Example: int a; System.out.println(a); // Compilation error Java will not assign default values to local variables. 🔹 Memory Structure During Execution When a Java program runs, memory is divided into: • Code Segment • Heap Segment • Stack Segment • Static Segment Objects → Heap Instance variables → Inside objects Local variables → Stack References → Stack 💡 Key Learning of the Day Understanding memory flow helps in: Debugging effectively Avoiding logical errors Writing optimized code Performing better in technical interviews Today was less about syntax and more about JVM thinking. Day 13 Complete ✔ #Day13 #Java #CoreJava #JVM #MemoryManagement #HeapAndStack #JavaDeveloper #FullStackJourney #LearningInPublic TAP Academy
To view or add a comment, sign in
-
-
Java☕ — Reflection made frameworks less magical🪞 I used to wonder how Spring creates objects automatically. Then I discovered Reflection API. 📝Reflection allows Java to: ✅Inspect classes at runtime ✅Access fields & methods dynamically ✅Create objects without new #Java_Code Class<?> clazz = Class.forName("com.example.User"); Object obj = clazz.getDeclaredConstructor().newInstance(); That blew my mind. Realization for me: Frameworks use reflection to reduce boilerplate. 📝But also: ✅Slower than normal calls ✅Breaks encapsulation ✅Should be used carefully Reflection isn’t for daily coding. It’s for building libraries and frameworks. #Java #Reflection #AdvancedJava #BackendDevelopment
To view or add a comment, sign in
-
🚀 Java Core Interview Series – Part 2 Encapsulation in Java Encapsulation is one of the most important OOP principles in Java. It ensures: ✔ Data Hiding ✔ Controlled Access ✔ Secure Object State ✔ Better Maintainability In real backend development: Entities, DTOs, and Services rely on encapsulation. Spring Boot uses getters/setters for data binding and validation internally. Without encapsulation: account.balance = -500 ❌ (Invalid state possible) With encapsulation: Invalid updates are prevented through business logic ✅ Strong Encapsulation = Secure & Maintainable Backend Code 🔥 I’ve explained the concept with a practical BankAccount example in this post. You can find my Java practice code here: 🔗 https://lnkd.in/gkmM6MRM More core Java concepts coming next 🚀 #Java #Encapsulation #OOPS #BackendDevelopment #CoreJava
To view or add a comment, sign in
-
📌 start() vs run() in Java Threads Understanding the difference between start() and run() is essential when working with threads in Java. 1️⃣ run() Method • Contains the task logic • Calling run() directly does NOT create a new thread • Executes like a normal method on the current thread Example: Thread t = new Thread(task); t.run(); // no new thread created 2️⃣ start() Method • Creates a new thread • Invokes run() internally • Execution happens asynchronously Example: Thread t = new Thread(task); t.start(); // new thread created 3️⃣ Execution Difference Calling run(): • Same call stack • Sequential execution • No concurrency Calling start(): • New call stack • Concurrent execution • JVM manages scheduling 4️⃣ Common Mistake Calling run() instead of start() results in single-threaded execution, even though Thread is used. 🧠 Key Takeaway • run() defines the task • start() starts a new thread Always use start() to achieve true multithreading. #Java #Multithreading #Concurrency #CoreJava #BackendDevelopment
To view or add a comment, sign in
-
🚨 Day 15 of #100days — Java Exception Handling Today I entered the world of errors… but in a controlled way 😌 I learned how Java handles unexpected situations using Exception Handling. Here’s how I now see it: 🧠 Exception → Something abnormal that disrupts normal program flow 🛠 try → “Risky code goes here” 🪝 catch → “If something breaks, handle it here” 🧹 finally → “Runs no matter what” (cleanup crew) Then things got more interesting 👀 🔥 throw → Manually throw an exception 🔥 throws → Declare that a method might throw an exception And the coolest part? Creating a Custom Exception — Designing your own rule and error message instead of relying only on built-in ones. Also explored the Throwable hierarchy: ✔ Checked → Must be handled (like IOException) ✔ Unchecked → Runtime issues (like NullPointerException) What I realized today: Exceptions aren’t just “errors”. They’re a way to make programs safer, cleaner, and more predictable. Java feels more powerful when you know how to control failure instead of fearing it . #Java #ExceptionHandling #JavaLearning #ProgrammingJourney #100DaysOfCode #SoftwareDevelopment #BackendDevelopment #CodingLife
To view or add a comment, sign in
-
-
⚡Static Methods in Interfaces Before Java 8, helper/utility logic lived in separate utility classes: Collections, Arrays, Math They didn’t belong to objects — they belonged to the concept itself. Java later allowed static methods inside interfaces so the behavior can live exactly where it logically belongs. 👉 Now the interface can hold both the contract and its related helper operations. 🧠 What Static Methods in Interfaces Mean A static method inside an interface: Belongs to the interface itself Not inherited by implementing classes Called using interface name only No object needed. No utility class needed. 🎯 Why They Exist ✔ Removes unnecessary utility classes The operation belongs to the type, not to instances. 🔑 Static vs Default Default → inherited behavior, object can use/override it Static → helper behavior, called using interface name only, not inherited 💡 Interfaces now contain: Contract + Optional Behavior(default) + Helper Logic(static) Use static when the behavior must stay fixed for the interface/class itself cant be overridden. Use default when you want a common behavior but still allow children to override it or just use the parent default implementation. Default methods exist only for interfaces (to evolve them without breaking implementations). In abstract classes you simply write a normal concrete method — no default keyword needed. GitHub link: https://lnkd.in/esEDrfPy 🔖Frontlines EduTech (FLM) #Java #CoreJava #Interfaces #DefaultMethods #StaticMethods #OOP #BackendDevelopment #Programming #CleanCode #ResourceManagement #AustraliaJobs #SwitzerlandJobs #NewZealandJobs #USJobs
To view or add a comment, sign in
-
-
🚀 Java 8 Series – Day 6 𝗦𝘁𝗿𝗲𝗮𝗺 𝗔𝗣𝗜 – 𝗜𝗻𝘁𝗲𝗿mediate vs Terminal Operations Yesterday we introduced Streams. Today let’s understand how Streams actually execute. A Stream pipeline has 3 parts: 𝗦𝗼𝘂𝗿𝗰𝗲 → 𝗜𝗻𝘁𝗲𝗿𝗺𝗲𝗱𝗶𝗮𝘁𝗲 𝗢𝗽𝗲𝗿𝗮𝘁𝗶𝗼𝗻𝘀 → 𝗧𝗲𝗿𝗺𝗶𝗻𝗮𝗹 𝗢𝗽𝗲𝗿𝗮𝘁𝗶𝗼𝗻 But what’s the difference between Intermediate and Terminal? 🔹 𝗜𝗻𝘁𝗲𝗿𝗺𝗲𝗱𝗶𝗮𝘁𝗲 𝗢𝗽𝗲𝗿𝗮𝘁𝗶𝗼𝗻𝘀 👉Return another Stream 👉 Lazy in nature 👉 Do NOT execute immediately 𝗘𝘅𝗮𝗺𝗽𝗹𝗲𝘀: ⭐ filter() ⭐ map() ⭐ sorted() ⭐ distinct() ⭐ limit() ⭐ skip() ⭐ flatMap() 𝗘𝘅𝗮𝗺𝗽𝗹𝗲: names.stream() .filter(name -> name.length() > 3) .map(String::toUpperCase); This will NOT execute yet. Why? Because there is no terminal operation. 🔹 𝗧𝗲𝗿𝗺𝗶𝗻𝗮𝗹 𝗢𝗽𝗲𝗿𝗮𝘁𝗶𝗼𝗻𝘀 👉 Trigger the execution 👉 Produce a final result 👉 Close the stream 𝗘𝘅𝗮𝗺𝗽𝗹𝗲𝘀: ⭐ collect() ⭐ forEach() ⭐ reduce() ⭐ count() ⭐ min() ⭐ max() 𝗘𝘅𝗮𝗺𝗽𝗹𝗲: List result = names.stream() .filter(name -> name.length() > 3) .map(String::toUpperCase) .collect(Collectors.toList()); Now it executes. 🔥 𝗜𝗺𝗽𝗼𝗿𝘁𝗮𝗻𝘁 𝗖𝗼𝗻𝗰𝗲𝗽𝘁: 𝗟𝗮𝘇𝘆 𝗘𝘃𝗮𝗹𝘂𝗮𝘁𝗶𝗼𝗻 Streams execute only when a terminal operation is present. This improves performance because operations are chained and optimized internally. Visual Flow Source → filter → map → sorted → collect Single pass processing. Not multiple loops. Tomorrow: Deep dive into map() vs flatMap() 🔥 (Most confusing interview topic) Follow the series if you're building strong Java fundamentals 🚀 #Java #Java8 #StreamAPI #BackendDeveloper #Coding #InterviewPreparation #SpringBoot
To view or add a comment, sign in
-
Ever wondered why you can’t create your own class named java.lang.String? 🤔 We often hear that Java is "secure" and "platform-independent," but how does that actually work under the hood? In my latest Medium article, I break down the internals of the JVM, moving from the basics to the complex mechanisms that keep Java applications stable. In this guide, I cover: ✅ The Ecosystem: The real difference between JVM, JDK, and JRE. ✅ Platform Independence: How "Write Once, Run Anywhere" is achieved via bytecode. ✅ Class Loading: A deep dive into the Parent Delegation Model. I specifically explore how the Bootstrap, Platform, and Application ClassLoaders interact. Understanding this delegation hierarchy is key to understanding why core Java classes cannot be overridden—a massive security feature. If you are brushing up on Java internals or preparing for technical interviews, this guide simplifies the complex architecture. #Java #JVM #SoftwareEngineering #Coding #TechEducation #JavaDeveloper #Programming You can read the full blog here : https://lnkd.in/gVJzk2Pp
To view or add a comment, sign in
-
🧠 Java Basics: The Building Blocks of Code Whether you're just starting your programming journey or revisiting the fundamentals, understanding Java's core components is essential. Here's a quick breakdown of the pillars that power every Java program: 🔹 Variables Think of variables as labeled containers that store data. Java requires you to declare the type of data each variable holds — making your code predictable and efficient. 🔹 Data Types Java offers both primitive types (like int, float, char, boolean) and non-primitive types (like String, arrays, and classes). Choosing the right type is key to memory management and performance. 🔹 Operators Operators are the tools that let you manipulate data. From arithmetic (+, -, *, /) to relational (==, !=, >, <) and logical (&&, ||, !), they help you build logic into your code. #Java, #JavaProgramming, #ProgrammingBasics, #SoftwareDevelopment, #LearnToCode, #TechEducation, #CodeNewbie, #BackendDevelopment, #ObjectOrientedProgramming, #CodingJourney, #TechCommunity
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