🚨 𝗪𝗵𝘆 𝗱𝗼𝗲𝘀 𝗝𝗮𝘃𝗮 𝗰𝗼𝗱𝗲 𝗿𝘂𝗻 𝗲𝘃𝗲𝗻 𝘄𝗶𝘁𝗵 𝗮 “𝘄𝗿𝗼𝗻𝗴” 𝗺𝗮𝗶𝗻() 𝗺𝗲𝘁𝗵𝗼𝗱? Today I learned something interesting while practicing Java 👇 I wrote this code: 𝘤𝘭𝘢𝘴𝘴 𝘏𝘦𝘭𝘭𝘰𝘞𝘰𝘳𝘭𝘥 { 𝘱𝘶𝘣𝘭𝘪𝘤 𝘴𝘵𝘢𝘵𝘪𝘤 𝘷𝘰𝘪𝘥 𝘮𝘢𝘪𝘯() { 𝘚𝘺𝘴𝘵𝘦𝘮.𝘰𝘶𝘵.𝘱𝘳𝘪𝘯𝘵𝘭𝘯("𝘏𝘦𝘭𝘭𝘰 𝘸𝘰𝘳𝘭𝘥"); } } 👉 𝗔𝗰𝗰𝗼𝗿𝗱𝗶𝗻𝗴 𝘁𝗼 𝗝𝗮𝘃𝗮 𝘀𝘁𝗮𝗻𝗱𝗮𝗿𝗱𝘀, 𝘁𝗵𝗶𝘀 𝗶𝘀 𝗡𝗢𝗧 𝗮 𝘃𝗮𝗹𝗶𝗱 𝗲𝗻𝘁𝗿𝘆 𝗽𝗼𝗶𝗻𝘁. The JVM strictly requires: public static void main(String[] args) Yet surprisingly, the code ran successfully in VS Code / online compilers 🤯 ❓ 𝗪𝗵𝘆 𝗱𝗼𝗲𝘀 𝘁𝗵𝗶𝘀 𝗵𝗮𝗽𝗽𝗲𝗻? Some IDEs and online compilers (VS Code, OneCompiler, etc.) help developers by: Wrapping the code internally Using their own valid main(String[] args) Manually calling our main() method behind the scenes So the JVM never directly starts from our method. ⚠️ 𝗜𝗺𝗽𝗼𝗿𝘁𝗮𝗻𝘁 𝘁𝗮𝗸𝗲𝗮𝘄𝗮𝘆 This behavior: ❌ Will fail in exams ❌ Will fail in interviews ❌ Will fail in real JVM environments ✅ Always use this (safe everywhere): public static void main(String[] args) 💡 𝗟𝗲𝘀𝘀𝗼𝗻 𝗹𝗲𝗮𝗿𝗻𝗲𝗱: Don’t rely on IDE magic — always follow JVM specifications. #Java #CoreJava #Programming #Learning #InterviewPrep #CSStudent #JavaTips
Java Main Method Requirements for JVM Environments
More Relevant Posts
-
𝗦𝗧𝗔𝗖𝗞 𝘃𝘀 𝗛𝗘𝗔𝗣 𝗶𝘀𝗻’𝘁 𝗷𝘂𝘀𝘁 𝘁𝗵𝗲𝗼𝗿𝘆. It’s the difference between confusion and clarity when debugging Java. 𝗪𝗲𝗹𝗰𝗼𝗺𝗲 𝘁𝗼 𝗝𝗮𝘃𝗮 𝗕𝗲𝗴𝗶𝗻𝗻𝗲𝗿 𝗦𝗲𝗿𝗶𝗲𝘀 🚀 𝗣𝗮𝗿𝘁 𝟭 → 𝗣𝗿𝗶𝗺𝗶𝘁𝗶𝘃𝗲 𝗧𝘆𝗽𝗲𝘀 𝗣𝗮𝗿𝘁 𝟮 → 𝗥𝗲𝗳𝗲𝗿𝗲𝗻𝗰𝗲 𝗧𝘆𝗽𝗲𝘀 If you truly understand how Stack and Heap work, debugging becomes dramatically easier. ⚠️ 𝗪𝗵𝘆? Because most common Java errors happen here. 𝟭️⃣ 𝗡𝘂𝗹𝗹𝗣𝗼𝗶𝗻𝘁𝗲𝗿𝗘𝘅𝗰𝗲𝗽𝘁𝗶𝗼𝗻 This happens when: You try to use a 𝘳𝘦𝘧𝘦𝘳𝘦𝘯𝘤𝘦 stored in the 𝗦𝘁𝗮𝗰𝗸 that points to 𝗻𝗼𝘁𝗵𝗶𝗻𝗴 𝗶𝗻 𝘁𝗵𝗲 𝗛𝗲𝗮𝗽. In simple words: The variable exists. The object doesn’t. That’s when Java throws: 𝗡𝘂𝗹𝗹𝗣𝗼𝗶𝗻𝘁𝗲𝗿𝗘𝘅𝗰𝗲𝗽𝘁𝗶𝗼𝗻 𝟮️⃣ 𝗠𝗲𝗺𝗼𝗿𝘆 𝗟𝗲𝗮𝗸𝘀 This happens when: You forget to clear references. The object stays in the 𝗛𝗲𝗮𝗽 because the Garbage Collector thinks you’re still using it. Result? Memory slowly fills up. 🔥 𝗦𝗼 𝗪𝗵𝘆 𝗗𝗼𝗲𝘀 𝗧𝗵𝗶𝘀 𝗠𝗮𝗸𝗲 𝗗𝗲𝗯𝘂𝗴𝗴𝗶𝗻𝗴 “𝟭𝟬𝘅 𝗘𝗮𝘀𝗶𝗲𝗿”? Because when you understand: • 𝗪𝗵𝗲𝗿𝗲 𝘃𝗮𝗹𝘂𝗲𝘀 𝗮𝗿𝗲 𝘀𝘁𝗼𝗿𝗲𝗱 • 𝗪𝗵𝗲𝗿𝗲 𝗼𝗯𝗷𝗲𝗰𝘁𝘀 𝗮𝗿𝗲 𝗰𝗿𝗲𝗮𝘁𝗲𝗱 • 𝗛𝗼𝘄 𝗿𝗲𝗳𝗲𝗿𝗲𝗻𝗰𝗲𝘀 𝗯𝗲𝗵𝗮𝘃𝗲 You stop guessing. You start reasoning. And debugging becomes logical instead of frustrating. 𝗣𝗿𝗶𝗺𝗶𝘁𝗶𝘃𝗲 → 𝘷𝘢𝘭𝘶𝘦 𝘴𝘵𝘰𝘳𝘦𝘥 𝘥𝘪𝘳𝘦𝘤𝘵𝘭𝘺 𝘪𝘯 𝘚𝘵𝘢𝘤𝘬 𝗢𝗯𝗷𝗲𝗰𝘁 → 𝘳𝘦𝘧𝘦𝘳𝘦𝘯𝘤𝘦 𝘪𝘯 𝘚𝘵𝘢𝘤𝘬, 𝘰𝘣𝘫𝘦𝘤𝘵 𝘪𝘯 𝘏𝘦𝘢𝘱 Once this clicks, OOP makes much more sense. 𝗝𝗮𝘃𝗮 𝗕𝗲𝗴𝗶𝗻𝗻𝗲𝗿 𝗦𝗲𝗿𝗶𝗲𝘀 🚀 Part 1 → Primitive Types Part 2 → Reference Types Next: Variables & Memory Deep Dive 💬 What confused you more at first - Stack or Heap? 🔖 Save this for revision 🔁 Share with someone learning Java 🔥 Hashtags #Java #JavaBeginner #JavaDeveloper #Programming #SoftwareEngineering #BackendDevelopment #LearnJava #ComputerScience #Developers
To view or add a comment, sign in
-
-
Day 2/30 🚀 Consistent Progress > Occasional Motivation Documenting my learning journey in Core Java with a focused deep dive into: 🔹 Method Overloading 🔹 Compile-Time Polymorphism 🔹 Static Binding & Early Binding 🔹 Type Promotion 🔹 Ambiguity Scenarios 🔹 Real-time examples from println() & substring() This revision cheat sheet is part of my structured daily practice — not just understanding the definition, but learning: ✅ How the Java Compiler resolves overloaded methods ✅ The 3 selection rules (Method Name → Parameter Count → Parameter Type) ✅ When type promotion happens ✅ Why ambiguity leads to compile-time errors ✅ How to explain this concept clearly in interviews with code 💡 Goal: Move from knowing concepts → explaining them confidently → applying them in real scenarios Building strong fundamentals in OOP and Core Java step by step as part of my preparation for software development roles. Consistency, revision, and practical understanding — every single day. 📚💻 #Java #CoreJava #OOP #TAPACADEMY #MethodOverloading #Polymorphism #JavaDeveloper #ProgrammingFundamentals #InterviewPreparation #LearningInPublic #CodeNewbie #TechJourney #SoftwareEngineering #JavaLearning #ConsistencyMatters
To view or add a comment, sign in
-
-
I just wrapped up an intensive deep dive into Java fundamentals, and it’s a reminder that even the "simple" things have layers of complexity that separate a coder from a true software developer. Here are my top 3 takeaways from today’s session on Literals, Type Casting, and Operators: 1. Literals are more than just numbers. 🔢 Did you know Java interprets integers differently based on their prefixes? No prefix = Decimal 0 = Octal (e.g., 045 is actually 37 in decimal!) 0x = Hexadecimal 0b = Binary Pro-tip: Be careful! Trying to use an 8 in an octal literal will throw a compilation error because octal only uses symbols 0-7. 2. The Nuances of Type Casting. 🔄 We explored Widening (Implicit) and Narrowing (Explicit) casting. Widening happens automatically when moving from a smaller to a larger data type (e.g., byte to int). The Exception: Moving from a long (8 bytes) to a float (4 bytes) is actually implicit widening because the IEEE format allows float to store a wider range of values through compression. Narrowing requires manual intervention (e.g., (byte) myDouble) and often leads to a "loss of data" or truncation. 3. Pre- vs. Post-Increment. ➕➕ It’s not just plus a. It’s about "First increase, then use" (Pre) vs. "First use, then increase" (Post). Mastering this logic is crucial for solving complex expressions and technical aptitude tests. Final thought on the "Human Touch": With AI tools like Claude Co-workers evolving rapidly, the IT market is shifting. The consensus? A person who is excellent at foundational problem-solving and adds unique value to a company will always have a place. Consistency is the only shortcut. Feeling more "AI-proof" today! 💻✨ #Java #SoftwareDevelopment #CodingLife #TypeCasting #TechLearning #CareerGrowth #ProgrammingFoundations
To view or add a comment, sign in
-
-
🚀 𝗛𝗼𝘄 𝗔𝗿𝗿𝗮𝘆𝘀 𝗨𝘀𝗲 𝗠𝗲𝗺𝗼𝗿𝘆 𝗶𝗻 𝗝𝗮𝘃𝗮 (𝗦𝗶𝗺𝗽𝗹𝗲 𝗘𝘅𝗽𝗹𝗮𝗻𝗮𝘁𝗶𝗼𝗻) Arrays look very simple. But do you know what really happens in memory when you write: 𝗶𝗻𝘁[] 𝗮𝗿𝗿 = 𝗻𝗲𝘄 𝗶𝗻𝘁[𝟱]; Java does more than you think 👇 📦 1️⃣ 𝗔𝗿𝗿𝗮𝘆𝘀 𝗔𝗿𝗲 𝗢𝗯𝗷𝗲𝗰𝘁𝘀 In Java, arrays are stored in 𝗛𝗲𝗮𝗽 𝗺𝗲𝗺𝗼𝗿𝘆. 𝗮𝗿𝗿 → reference variable (stored in Stack if inside method) 𝗻𝗲𝘄 𝗶𝗻𝘁[𝟱] → actual array object (stored in Heap) So Java creates one object that can store 5 integers. 🧠 2️⃣ 𝗖𝗼𝗻𝘁𝗶𝗻𝘂𝗼𝘂𝘀 𝗠𝗲𝗺𝗼𝗿𝘆 𝗕𝗹𝗼𝗰𝗸 Arrays store elements in a continuous memory block. 𝗙𝗼𝗿 𝗶𝗻𝘁[𝟱]: • Each int = 4 bytes • Total memory = 5 × 4 = 20 bytes (+ object header overhead) That is why array access is very fast. Access by index is O(1). 🔢 3️⃣ 𝗗𝗲𝗳𝗮𝘂𝗹𝘁 𝗩𝗮𝗹𝘂𝗲𝘀 When Java allocates memory, it assigns default values automatically: • int → 0 • double → 0.0 • boolean → false • Object → null No garbage values like in C/C++. 🏗 4️⃣ 𝗔𝗿𝗿𝗮𝘆 𝗼𝗳 𝗢𝗯𝗷𝗲𝗰𝘁𝘀 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 Student[] students = new Student[3]; This creates: • One array object (holding 3 references) • NOT 3 Student objects Each element is null until you create objects manually. ⚠ 5️⃣ Fixed Size Array size cannot change after memory allocation. If you need dynamic size, use: • ArrayList • LinkedList 💡 If you are learning Java from basic to advanced in very simple language, platforms like w3schools.com are very helpful to understand core concepts clearly before going deep into JVM internals. Understanding memory basics makes you a stronger developer. Have you ever thought about what happens in memory when you create an array? 👇 #Java #JVM #MemoryManagement #Programming #BackendDevelopment #Java #JavaDeveloper #JVM #MemoryManagement #DataStructures #BackendDevelopment #Programming #Coding #SoftwareEngineering #LearnToCode #DeveloperLife #TechCommunity #ComputerScience #CleanCode
To view or add a comment, sign in
-
📘 Today I Learned — Java static Keyword 🔹 What I Learned •static makes a variable or method belong to the class, not the object. Useful for memory efficiency and operations that don’t depend on object state. 🔹 Key Concepts •Static Variables Only one copy exists for the entire class Shared by all objects •Static Methods Can be called without creating an object Can access only static data Ideal for utility functions •Static Block Runs once when the class loads Used to initialize static variables Executes before main() •Static Inner Class Only inner classes can be static 🔹 Why It’s Important •Helps optimize memory •Supports efficient utility operations •Useful for one-time initialization •Reduces unnecessary object creation #Java #OOPs #StaticKeyword #JavaProgramming #FullStackDeveloper #LearningJourney #TapAcademy #CodingBasics
To view or add a comment, sign in
-
-
Debugging in Action: Reverse String Prefix Challenge I recently tackled a deceptively simple Java problem: reverse the first k characters of a string s. Sounds easy, right? But my initial implementation returned a wrong answer — and that’s where the real learning began. What went wrong? - Misused loop conditions (k > 1 instead of i >= 0) - Incorrect indexing (i = k instead of i = k - 1) - Confused logic in appending the rest of the string Fixed it with clarity: `java for (int i = k - 1; i >= 0; i--) { sb.append(s.charAt(i)); } for (int i = k; i < s.length(); i++) { sb.append(s.charAt(i)); } ` Lesson: Error codes aren’t obstacles — they’re feedback. Every “Wrong Answer” is a chance to refine logic, rethink assumptions, and grow as a developer. If you’ve debugged something recently, share your fix! Let’s normalize learning through mistakes 💡 Java #Debugging #CodingJourney #SoftwareEngineering #LinkedInLearning #AkashLearns
To view or add a comment, sign in
-
-
Good Monday! Let’s start the week with a deep analysis by Java luminary Brian Goetz on carrier classes, records and the future of the language as is being developed in Project Amber. Sorry about the format, it is very clumsy, maybe a copy-paste on your favorite text editor will help. https://lnkd.in/eh3BQAYy #Java #DataOrientedProgramming #Java26AndBeyond #ProjectAmber
To view or add a comment, sign in
-
𝐉𝐚𝐯𝐚 𝐌𝐞𝐭𝐡𝐨𝐝𝐬 𝐂𝐡𝐞𝐚𝐭 𝐒𝐡𝐞𝐞𝐭 𝐟𝐨𝐫 𝐃𝐒𝐀 While learning, remembering important Java methods saves a lot of time. So I created a quick Java Cheat Sheet focused only on methods that are useful. 𝐂𝐨𝐯𝐞𝐫𝐬: 🔹 String Methods ✔️ length() ✔️ charAt() ✔️ substring() ✔️ indexOf() ✔️ toCharArray() 🔹 Arrays Class ✔️ sort() ✔️ fill() ✔️ equals() ✔️ binarySearch() 🔹 Collections & List ✔️ add() ✔️ remove() ✔️ get() ✔️ set() ✔️ contains() ✔️ size() 🔹 HashMap Methods ✔️ put() ✔️ get() ✔️ containsKey() ✔️ keySet() ✔️ entrySet() 🔹 Stack / Queue Methods ✔️ push() ✔️ pop() ✔️ peek() ✔️ offer() ✔️ poll() #Javadeveloper #softwaredeveloper #coding #javamethods #corejava
To view or add a comment, sign in
-
Why "Thinking in Objects" is the Ultimate Superpower in Java 🚀 If you are just starting your journey into Object-Oriented Programming (OOP), the terminology can feel like a foreign language. "Classes," "Objects," "Methods," "Instances"—it’s a lot to take in. But if you look at this illustration, you’ll see that coding isn’t just about syntax; it’s about architecture. 1. The Class: Your Architectural Blueprint 📜 The left side of the image shows the Class House. In Java, a class is not a thing; it is a template. It defines: Attributes (Fields): Like int windows and String color—these are the characteristics every house will have. Behaviors (Methods): Like void build()—this is what the house (or the system) can do. 2. The Process: Instantiation 🏗️ Notice the arrow in the middle? That’s the "Magic Moment" called Instantiation. When you use the new keyword in Java, you are telling the computer: "Take this blueprint and actually build it in memory!". 3. The Objects: The Real-World Result 🏡 On the right, we see three distinct Objects: Object 1: A Red House. Object 2: A Yellow House. Object 3: A Blue House. Here is the key takeaway: Even though they all came from the exact same blueprint, they are unique. They each have their own "state" (different colors), but they share the same "identity" (they are all Houses). Why does this matter? By using this model, Java allows us to write code that is: ✅ Reusable: Write the blueprint once, create a thousand houses. ✅ Organized: Keep data and behavior in one neat package. ✅ Scalable: It’s much easier to manage a neighborhood when you have a standard plan to follow. What was the "Aha!" moment that helped you finally understand OOP? Drop a comment below! 👇 #Java #SoftwareEngineering #CodingLife #OOP #TechEducation #WebDevelopment
To view or add a comment, sign in
-
-
If–else vs switch when should you use which ? At first glance, both solve the same problem. And honestly, I used to wonder: 👉 If `if–else` already works, why even use `switch`? Is it just for readability? Turns out, the difference becomes clearer as the logic grows. 🔹 `if–else` works best when: • conditions are complex • ranges or multiple boolean checks are involved • logic isn’t just equality comparisons 🔹 `switch` shines when: • one variable maps to many fixed values • cases are mutually exclusive • readability and maintainability matter ⚡ Performance & memory (practical view): • For small logic → difference is negligible • Long `if–else` chains → sequential checks • `switch` → JVM can optimize using jump tables or lookup strategies • Memory difference → minimal and usually not a concern What happens when conditions grow? Imagine: 20 50 or 100 possible values if–else behavior Conditions are checked top to bottom Worst case: every comparison is evaluated Time complexity: O(n) How switch works under the hood (Java) When Java compiles a switch, the JVM can choose different strategies: 1️⃣ Jump Table (tableswitch) Used when case values are dense (e.g., 1–10) Direct jump to the matching case Time complexity: O(1) 2️⃣ Lookup Table (lookupswitch) Used when values are sparse (e.g., 10, 50, 100) JVM performs a fast lookup Time complexity: O(log n) 3️⃣ String switch Hash-based lookup + switch Still faster than long if–else chains 4️⃣ Memory usage if–else: simple comparisons, minimal memory switch: may create a jump table 👉 Memory difference is usually negligible 👉 Speed + clarity is the real win What really changed my perspective was understanding how `switch` works under the hood. It’s not just syntax it can give the compiler and JVM more room to optimize. 📌 My takeaway: Choose based on clarity first. But knowing what happens under the hood helps you make better decisions when code starts to scale. Part of my “learning in public” journey — one concept at a time. Curious to hear your thoughts: Do you mainly use switch for readability or performance, or both? 👇 #LearningInPublic #Java #SoftwareEngineering #Programming #Performance #CleanCode #DeveloperJourney #TechLearning #corejava
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