🔹 Instance main() Methods in Java — A Preview Feature in Progress Java has been experimenting with reducing startup ceremony while keeping backward compatibility intact. One such example is instance main() methods, introduced as a preview feature in Java 21 (JEP 445) and refined across subsequent releases. What is this about? Traditionally, Java programs start with: public static void main(String[] args) With this preview feature: • Java allows a non-static main() method • The JVM creates an instance of the class automatically • The instance main() is then invoked Important context • First introduced in Java 21 • Still a preview feature (not final) • Requires preview features to be enabled • The static main() method remains the recommended production standard Why it matters • Reduces boilerplate for small programs • Makes learning and experimentation easier • Shows Java’s gradual evolution without breaking existing code class Main { public void main(String[] args) { System.out.println("It runs!"); } } This feature is best viewed as a learning and experimentation improvement, not a replacement for established Java practices. #Java #Java21 #JEP445 #JVM #JavaEvolution #SoftwareEngineering #LearningInPublic
Utkarsh Joshilkar’s Post
More Relevant Posts
-
Post3 of Sharing a learning from Effective Java Item 3: Enforce the Singleton Property A Singleton should guarantee only one instance — even in the presence of serialization, reflection, and multithreading. Common (but fragile) approach: public class Singleton { private static final Singleton INSTANCE = new Singleton(); private Singleton() {} public static Singleton getInstance() { return INSTANCE; } } Best approach (recommended by Effective Java): public enum Singleton { INSTANCE; } Why enum-based singleton? • Thread-safe by default • Prevents reflection attacks • Safe against serialization issues • Simple and clean Key takeaway: If you need a true Singleton in Java, use an enum unless you have a strong reason not to. 📖 Effective Java — Joshua Bloch #Java #EffectiveJava #BackendEngineering #CleanCode #SoftwareEngineering #DesignPatterns #JavaTips #ProductEngineering
To view or add a comment, sign in
-
💡 Understanding the Java main() Method The main() method is the entry point of a Java application. When a Java program is executed, the Java Virtual Machine (JVM) looks for the main() method and begins program execution from there. Without this method, a Java program cannot run. 🔹 Standard Syntax: public static void main(String[] args) 🔹 Explanation of Each Keyword: public – Allows the JVM to access the method from anywhere static – Enables the method to be called without creating an object of the class void – Indicates that the method does not return any value main – The method name recognized by the JVM as the starting point String[] args – Used to accept command-line arguments 🔹 Why the main() Method Is Important: Acts as the starting execution point of a Java program Helps the JVM understand where the program begins Allows developers to pass inputs at runtime using command-line arguments Forms the foundation for understanding Java application structure 📘 Learning Outcome: Through this assignment, I gained a strong understanding of how Java programs start execution, the role of the JVM, and the importance of correct method declaration. Grateful to kshitij kenganavar at TAP Academy for his professional guidance and clear explanation of core Java concepts. #CoreJava #JavaMainMethod #JavaBasics #JVM #ProgrammingFundamentals #SoftwareDevelopment #FullStackDeveloper #TapAcademy #LearningJourney #SkillBuilding #StudentDeveloper #CodingLife #TechTraining
To view or add a comment, sign in
-
-
Today, I came across a Core Java concept that made me think: Fail-Fast vs Fail-Safe Iterators :- Iteration feels simple—until a collection changes mid-loop. That’s where Java makes some smart design choices to protect consistency. Fail-Fast iterators: • work on the original collection • track changes using an internal counter (modCount) • throw ConcurrentModificationException on modification • used in ArrayList, HashMap Example (Fail-Fast): for (Integer i : list) { if (i == 2) list.remove(i); // exception } Fail-Safe iterators: • iterate over a snapshot of the collection • allow modification without exceptions • safer for concurrency, but use extra memory • used in CopyOnWriteArrayList Example (Fail-Safe): for (Integer i : copyOnWriteList) { if (i == 2) copyOnWriteList.remove(i); // no exception } The takeaway? Fail-Fast chooses correctness. Fail-Safe chooses stability. Still learning, but this really shows how Java thinks beyond syntax. #Java #CoreJava #JavaCollections #BackendDevelopment #LearningInPublic #Programming #JavaDeveloper #ObjectOrientedProgramming #CodingCommunity
To view or add a comment, sign in
-
💡 A small Java error that taught me a BIG lesson about JVM Java be like: “It runs.” JVM be like: “Yes… but WHERE is your .class file?” 😅 Today I met this classic Java error: Error: Could not find or load main class Everything looked fine. Folder ✔ Class ✔ Confidence ❌ Then Java 11 entered the chat. Its not search .class file. When you run: java HelloWorld.java Java says: “No worries, I’ll compile and run it for you.” And the funny part? 👉 No HelloWorld.class is created 🤯 It’s compiled in memory and gone like magic. Helpful? Yes. Confusing while learning JVM fundamentals? Absolutely 😄 But when you run: java com.package.HelloWorld JVM says: “I don’t do magic. Show me the .class file, correct package declaration, and proper folder structure.” 🔍Folder is NOT a package utill not mention in java class as package JVM never guesses For compilation you should be on project root. C:\Users\abcd\OneDrive\Attachments>javac duke\choice\ShopApp.java Java 11 source-file mode is helpful… and sneaky No .class file ≠ no rules 😄 Once everything aligned for JVM— C:\Users\abcd\OneDrive\Attachments>java com.don.htt.HelloWorld Hello, Java! finally appeared ☕️ #Java #JVM #CoreJava #DeveloperLife #LearningInPublic #BackendDevelopment
To view or add a comment, sign in
-
Post 4 - Sharing a learning from Effective Java Item 4: Enforce Noninstantiability with a Private Constructor Some classes are not meant to be instantiated (e.g. utility classes). But Java adds a public constructor by default if you don’t define one. ❌ Problematic utility class: public class MathUtils { public static int add(int a, int b) { return a + b; } } This allows: new MathUtils(); // unwanted ✅ Correct approach: public class MathUtils { private MathUtils() { throw new AssertionError("No instances allowed"); } public static int add(int a, int b) { return a + b; } } Why this matters: • Prevents accidental instantiation • Makes intent explicit • Improves API design clarity Key takeaway: If a class is not meant to be instantiated, make it impossible to do so. 📖 Effective Java — Joshua Bloch #Java #EffectiveJava #CleanCode #BackendEngineering #SoftwareEngineering #DesignPrinciples #JavaTips #ProductEngineering
To view or add a comment, sign in
-
While trying out Java 25, one thing really stood out to me—not a flashy feature, but a subtle shift in how Java lets us begin a program. For years, starting Java meant memorizing this line before understanding anything else: public static void main(String[] args) Now, it can be as simple as: void main() { } This isn’t just syntax sugar. It’s a signal. ➡️ Java is reducing cognitive load ➡️ Java is becoming more beginner-friendly ➡️ Java is modernizing without breaking its foundation The language that once felt verbose is quietly becoming more expressive—without losing the reliability it’s known for. Small changes. Big impact. Java is still evolving, and it’s doing it the right way. #Java #Java25 #SoftwareDevelopment #ProgrammingLanguages #DeveloperExperience #CleanCode #TechThoughts
To view or add a comment, sign in
-
🔐 Java Access Modifiers Access modifiers in Java define where a class, method, or variable can be accessed, and they play a crucial role in encapsulation, security, and clean code design. In this visual, I’ve summarized all four access modifiers with clear rules and examples: 🔹 public – Accessible from anywhere (same class, same package, subclasses, and other packages). 🔹 protected – Accessible within the same package and by subclasses (supports inheritance). 🔹 default (package-private) – Accessible only within the same package. 🔹 private – Accessible only inside the same class (maximum data hiding). Each section includes: ✔ Access scope ✔ When to use it ✔ Simple Java code examples ✔ A comparison table for quick revision Understanding access modifiers is essential for writing secure, maintainable, and interview-ready Java applications. Strong fundamentals always lead to better design decisions. 🚀 #Java #CoreJava #OOPs #AccessModifiers #JavaLearning #ProgrammingConcepts #DeveloperJourney #LearningInPublic
To view or add a comment, sign in
-
-
🚫 Tired of writing "if (obj != null)" everywhere in your Java code? I just published a new article on Medium: “Beyond if (obj != null): Smarter Ways to Handle Nulls in Java” NullPointerExceptions are still the #1 cause of midnight debugging sessions — even in Java 25 and 26. In this post, I break down three modern techniques that help you write cleaner, safer, and more maintainable code: ✅ Use Optional to eliminate ambiguity ✅ Fail fast with Objects.requireNonNull() ✅ Flip your comparisons with the “Yoda Condition” Whether you're mentoring juniors or refactoring legacy code, these habits can save hours of frustration and make your logic bulletproof. 🔗 https://lnkd.in/ghxPp2Nk Would love to hear how you handle nulls in your own projects — let’s share best practices! #Java #CleanCode #NullPointerException #Optional #BackendDevelopment #ProgrammingTips #TechWriting #SoftwareEngineering #CodeQuality #MediumBlog
To view or add a comment, sign in
-
📘 Java Basics Series | Topic: Methods in Java Today, I learned one of the most important concepts in Java — Methods 🚀 🔹 What is a Method? A method is a block of code that performs a specific task. It helps us reuse code, reduce repetition, and write clean programs. 🔹 Why Methods are Important? ✔ Code reusability ✔ Better readability ✔ Easy maintenance ✔ Structured programming 🔹 Types of Methods in Java 1️⃣ Method without parameters & without return value void greet() { System.out.println("Hello Java"); } 2️⃣ Method with parameters & without return value void add(int a, int b) { System.out.println(a + b); } 3️⃣ Method without parameters & with return value int getNumber() { return 10; } 4️⃣ Method with parameters & with return value int multiply(int a, int b) { return a * b; } 🔹 Static vs Non-Static Methods Static Method → Called using class name Non-Static Method → Called using object 💡 Key Takeaway: Methods make Java programs modular, reusable, and easy to understand. 📈 Learning Java step by step and enjoying the journey! #Java #JavaProgramming #MethodsInJava #CoreJava #LearningJava #ProgrammingBasics #DeveloperJourney
To view or add a comment, sign in
-
📘 Core Java Day 13 | Synthetic Classes in Java Today learned about synthetic classes a concept that exists in Java even though we never write it in our code. - Synthetic classes are not written by developers - They are generated automatically by the compiler / JVM - Their bytecode is added behind the scenes - They are not visible in Java source code - We cannot directly create or modify them Where are synthetic classes used? Arrays in Java - When we create an array, Java does not expose any constructor Still, an object is created on the heap - This is possible because arrays are instances of JVM-generated synthetic classes Inner class access - Synthetic classes and methods are used to allow inner classes to access private members of outer classes Why are synthetic classes needed? - To simplify Java syntax for developers - To hide low-level implementation details - To maintain performance and safety - To support language features without exposing complexity
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