🚀 Heads-up Java devs: the entry point just got a makeover If you thought every Java program had to start with public static void main(String[] args), the times are changing. With Java SE 21 and onward, the rules around the main() method have been relaxed. Medium+2 🔍 What’s new Java can now use instance main() methods (without static) or even main() with no parameters, in implicitly declared classes. You can skip writing the outer public class HelloWorld { … } in some contexts ("compact source files"). These features started as preview in Java 21 (JEP 445) and later became re-preview in Java 22 (JEP 463). 👍 Why this matters Less boilerplate: Faster to spin up a quick demo or script. Cleaner code: More readable, especially for newbies or quick utilities. Modernised Java: Aligns Java more with scripting or lightweight languages for rapid dev. 📣 Want to try it? // Java 21+ preview mode or above void main() { IO.println("Hello, world!"); } Yep — no public, no static, no args array. Though note: preview features may need enabling until finalised. 🗣 Let’s talk Have you experimented with this new main method style? Would you adopt it in production code, or is it just for demos & quick scripts? What’s a change in Java you wish would come next? Drop your thoughts below — and if you found this useful, hit Follow for more Java/Spring/tech-deep dives. #Java #Java21 #ProgrammingLanguages #SoftwareEngineering #DeveloperNews #SpringBoot #JobOpportunity
Java SE 21: New Main Method Rules for Java Developers
More Relevant Posts
-
Java 2025: Smart, Stable, and Still the Future 💡 ☕ Day 4 — Structure of a Java Program Let’s break down how every Java program is structured 👇 🧩 Basic Structure Every Java program starts with a class — the main container holding variables, constructors, methods, and the main() method (the entry point of execution). Inside the class, logic is organized into static, non-static, and constructor sections — each with a specific role. 🏗️ Class — The Blueprint A class defines the structure and behavior of objects. It holds data (variables) and actions (methods). Execution always begins from the class containing the main() method. ⚙️ Constructor — The Initializer A constructor runs automatically when an object is created. It shares the class name, has no return type, and sets the initial state of the object. 🧠 Static vs Non-Static Static → Belongs to the class, runs once, shared by all objects. Non-static → Belongs to each object, runs separately. 🔹 Initializers Static block → Runs once when the class loads (for setup/configurations). Non-static block → Runs before the constructor every time an object is created. 🧩 Methods Static methods → Called without creating objects; used for utilities. Non-static methods → Accessed through objects; define object behavior. 🔄 Execution Flow 1️⃣ Class loads 2️⃣ Static block executes 3️⃣ main() runs 4️⃣ Non-static block executes 5️⃣ Constructor runs 6️⃣ Methods execute 💬 Class → Blueprint Constructor → Object initializer Methods → Define actions Static/Non-static → Class vs Object level Initializers → Run automatically before constructors Together, they create a structured, readable, and maintainable Java program. #Day4 #Java #JavaStructure #100DaysOfJava #OOPsConcepts #ConstructorInJava #StaticVsNonStatic #JavaForDevelopers #ProgrammingBasics #LearnJava #BackendDevelopment #CodeNewbie #DevCommunity
To view or add a comment, sign in
-
-
🚀 Methods vs. Constructors: Unpacking Key Differences in Java 🚀 New to Java or looking for a quick refresher? Understanding the distinction between Methods and Constructors is fundamental! While both contain blocks of code, they serve very different purposes. Let's break it down with a simple comparison: Constructors: The Blueprint Initializers 🏗️ Purpose: Primarily used to initialize new objects. Think of them as setting up the initial state when an object is first created. Name: Must have the same name as the class itself. Return Type: No return type (not even void). Invocation: Called automatically when you use the new keyword to create an object. Example: new Employee(101, "Alice"); Methods: The Action Performers ⚙️ Purpose: Used to perform actions or operations on an object, or to retrieve information from it. Name: Can have any valid name (following Java naming conventions). Return Type: Must have a return type (e.g., void, int, String, Employee, etc.). Invocation: Called explicitly using the object reference, like object.methodName(). Example: employee.getDetails(); or employee.calculateBonus(); In essence: Constructors build and set up your object. Methods make your object do things. Understanding this distinction is crucial for writing clean, efficient, and object-oriented Java code! Thanks Anand Kumar Buddarapu #Java #Programming #SoftwareDevelopment #OOP #Constructors #Methods #CodingTips
To view or add a comment, sign in
-
-
💡 Immutability in Java — why it matters and how to use it effectively Immutability is one of those concepts that makes your Java code safer, cleaner, and easier to reason about. But what does “immutable” really mean? 👇 🧩 What is immutability? An immutable object is one whose state cannot change after it’s created. Once you build it, its data stays the same forever. This prevents unexpected side effects, race conditions, and bugs caused by shared mutable state — especially in multithreaded systems. 🧠 The classic example: String All String objects in Java are immutable. The classic example: String All String objects in Java are immutable String name = "Java"; name.concat(" Rocks!"); System.out.println(name); // "Java" ✅ Even though we called .concat(), it didn’t modify the original string. It returned a new String. ⚙️ final keyword Declaring a variable as final means you can’t reassign the reference — but it doesn’t make the object itself immutable. final List<String> list = new ArrayList<>(); list.add("A"); // ✅ allowed list = new ArrayList<>(); // ❌ not allowed 🧱 record — immutability made easy Since Java 16, record is the easiest way to create immutable data carriers: public record Person(String name, int age) {} Records automatically make fields private and final, and generate constructors, getters, equals(), hashCode(), and toString(). No setters. No mutability. Pure data. 🚀 Why use immutability Makes code thread-safe without synchronization Easier to debug and test Predictable state — no “who changed this object?” moments Simplifies functional programming with Streams and Lambdas 💬 Conclusion: String → always immutable final → prevents reassignment, not mutation record → immutable data structure made simple Immutability is not about restrictions — it’s about predictability and safety. #Java #Backend #CleanCode #Programming #SpringBoot #SoftwareEngineer #DeveloperTip
To view or add a comment, sign in
-
🚀 Java 8 → Java 17: The Most Practical Features Developers Use Every Day Java has evolved significantly over the years, but only a few features have a real impact on daily development. Here are the most important, real-world, high-productivity features from Java 8 to 17 that every backend developer should use. Java 8 Foundation of Modern Java Lambdas → Cleaner, expressive functional code Stream API → Filtering, mapping, sorting, grouping Optional → Avoid null pointer issues java.time API → Modern date/time handling CompletableFuture → Async programming made simpler Java 9 List.of(), Set.of(), Map.of() → Quick immutable collections JShell → Test code instantly Java 10 var keyword → Cleaner declarations, faster development Java 11 (LTS) HTTP Client API → HTTP/2, async support String enhancements → isBlank(), strip(), repeat(), lines() Java 13–15 Text Blocks → Easy multi-line JSON, SQL, HTML Pattern Matching (preview) → Cleaner instanceof checks Java 16–17 (Modern Java) Records → Perfect for DTOs and API models Sealed Classes → Controlled inheritance for domain modeling Pattern Matching (finalized) → Cleaner type patterns Improved GC (ZGC, Shenandoah) → Low-latency microservice performance 🔥 Top 7 Features Used DAILY (Most Practical) 1️⃣ Stream API 2️⃣ Lambdas 3️⃣ var keyword 4️⃣ List.of(), Map.of() 5️⃣ String new methods (Java 11) 6️⃣ Records 7️⃣ Text Blocks If you're writing Java Code, these are the features you should use every day. #Java #Java17 #JavaDeveloper #BackendDevelopment #Programming #SoftwareEngineering
To view or add a comment, sign in
-
🚀 #Day50 of My Java Journey Today, I explored Packages in Java — a powerful feature that helps organize and manage code efficiently 📦 𝗪𝗵𝗮𝘁 𝗮𝗿𝗲 𝗣𝗮𝗰𝗸𝗮𝗴𝗲𝘀? A package is a group of related Java classes and interfaces. Like a folder that keeps your code files organized and avoids naming conflicts. 𝗧𝘆𝗽𝗲𝘀 𝗼𝗳 𝗣𝗮𝗰𝗸𝗮𝗴𝗲𝘀: 1️⃣ 𝑩𝒖𝒊𝒍𝒕-𝒊𝒏 𝑷𝒂𝒄𝒌𝒂𝒈𝒆𝒔: Packages that come along with JDK and are already developed. 𝑬𝒙: java.lang → Fundamental classes (String, Math, System) (imported automatically) java.util → Utility classes (Scanner, Arrays, Collections) 2️⃣ 𝑼𝒔𝒆𝒓-𝑫𝒆𝒇𝒊𝒏𝒆𝒅 𝑷𝒂𝒄𝒌𝒂𝒈𝒆𝒔: Packages that we create based on project structure or modules. 𝑬𝒙: package com.application.student; 3️⃣ 𝑻𝒉𝒊𝒓𝒅-𝑷𝒂𝒓𝒕𝒚 𝑳𝒊𝒃𝒓𝒂𝒓𝒊𝒆𝒔 / 𝑷𝒂𝒄𝒌𝒂𝒈𝒆𝒔: Packages developed by external providers, used for specific features. 𝑬𝒙: com.mysql.cj.jdbc → For Database connectivity 𝐖𝐚𝐲𝐬 𝐭𝐨 𝐈𝐦𝐩𝐨𝐫𝐭 𝐏𝐚𝐜𝐤𝐚𝐠𝐞𝐬 1️⃣ 𝑺𝒊𝒏𝒈𝒍𝒆 𝑰𝒎𝒑𝒐𝒓𝒕: This imports only one specific class from a package. 𝑬𝒙: import java.util.Scanner; 2️⃣ 𝑶𝒏-𝑫𝒆𝒎𝒂𝒏𝒅 𝑰𝒎𝒑𝒐𝒓𝒕: Imports all classes inside the package. Useful when working with multiple classes from the same package. 𝑬𝒙: import java.util.*; 3️⃣ 𝑭𝒖𝒍𝒍𝒚 𝑸𝒖𝒂𝒍𝒊𝒇𝒊𝒆𝒅 𝑵𝒂𝒎𝒆: No import statement is required. You directly reference the class with its full package path. 𝑬𝒙: java.util.Scanner sc = new java.util.Scanner(System.in); 4️⃣ 𝑺𝒕𝒂𝒕𝒊𝒄 𝑰𝒎𝒑𝒐𝒓𝒕: Allows accessing static members(methods/variables) directly without class name. 𝑬𝒙: import static java.lang.System.out; out.println("Hello"); 🔥𝑲𝒆𝒚 𝑻𝒂𝒌𝒆𝒂𝒘𝒂𝒚: Packages help in organizing code, improving modularity, and making applications easy to maintain and scale. 10000 Coders #Java #LearningJourney #Programming #FullStack #Packages #import
To view or add a comment, sign in
-
-
☕ The Power of main() in Java — and What Happens When You Overload or Override It If you’ve ever written a Java program, you’ve seen this familiar line: public static void main(String[] args) But what makes it so important — and can we overload or override it? Let’s explore 👇 🚀 Why the main() Method Matters The main() method is the entry point of every standalone Java application. When you run a class, the Java Virtual Machine (JVM) looks for the exact signature: public static void main(String[] args) This is where execution begins. Without it, your program won’t start unless another class or framework calls it. Breaking it down: public → JVM must be able to access it from anywhere. static → No object creation needed to run it. void → Doesn’t return a value. String[] args → Accepts command-line arguments. 🔁 Overloading the main() Method Yes, you can overload the main() method — just like any other method in Java. 👉 What happens? Only the standard main(String[] args) method is called by the JVM. Any overloaded versions must be called manually from within that method. So, overloading works — but it doesn’t change the JVM’s entry point. 🔄 Overriding the main() Method Overriding, however, is not possible in the traditional sense. Since main() is static, it belongs to the class, not to an instance. Static methods can’t be overridden, but they can be hidden if you declare another main() in a subclass. 💬 Have you ever tried overloading the main() method just out of curiosity? What did you discover? #Java #Programming #OOP #SoftwareDevelopment #LearningJava #CodingConcepts #Developers #TechEducation #CodeNewbie
To view or add a comment, sign in
-
"Is a String stored as a Character Array in Java?" 🚀 Java Trivia for Developers: Have you ever wondered how a String is actually stored in memory? 🤔 Most developers would say — “as a char[].” ✅ That used to be true… but not anymore! Let’s break it down 👇 --- 🕹️ Java 8 and Earlier In older versions, a String was internally represented like this: public final class String { private final char[] value; private final int hash; } Each character occupied 2 bytes (UTF-16) — simple, but memory-heavy for ASCII text. --- ⚡ Java 9 and Later – Compact Strings (JEP 254) Starting with Java 9, the internal representation changed to: public final class String { private final byte[] value; private final byte coder; // 0 = LATIN1, 1 = UTF16 private int hash; } Now, Java stores String data as a byte array, using LATIN-1 or UTF-16 encoding based on the content. This saves up to 50% memory for text that fits in 1 byte per character! 💡 --- 🧠 Takeaway So, is a String stored as a char[] in Java? ➡️ Not since Java 9! It’s now backed by a byte[] for better performance and memory efficiency. --- 💬 What do you think about this change? Have you ever noticed memory improvements in your applications after Java 9? #Java #String #MemoryOptimization #JEP254 #JavaDeveloper #CodingTrivia #Performance
To view or add a comment, sign in
-
-
🔖 Annotations in Java: The Metadata That Powers Modern Frameworks Behind every clean, modern Java framework lies the silent power of annotations the metadata that tells the compiler and runtime what to do. Here’s what you’ll discover in this guide: ▪️What Annotations Really Are → Metadata that configures, documents, and automates behavior without altering logic. ▪️Built-in Annotations → @Override, @Deprecated, and @SuppressWarnings — your must-know compiler helpers. ▪️Custom Annotations → Create your own @interface annotations for validation, logging, or automation. ▪️Retention Policies → Learn where annotations live — at source, bytecode, or runtime. ▪️Target Types → Control where annotations can be applied — class, method, field, or parameter. ▪️Real-World Use Cases → See how Spring, Hibernate, and JUnit use annotations like @Autowired, @Entity, and @Test to simplify configuration. ▪️Interview Q&A → Understand retention, target, and runtime use — topics every Java interview covers. 📌 Like, Save & Follow CRIO.DO for more Java deep-dives made simple. 💻 Learn Java by Building Real Frameworks At CRIO.DO, you’ll master advanced Java concepts from annotations to dependency injection by actually building backend systems and Spring-based projects. 🚀 Book your FREE trial today- https://lnkd.in/geb_GYW2 and start coding like a pro! #Java #Annotations #CrioDo #LearnJava #SoftwareDevelopment #SpringFramework #Hibernate #JUnit #BackendEngineering #CodeSmart
To view or add a comment, sign in
-
🧠 Static vs Instance in Java: The Real Difference Explained Understanding the difference between static and instance members is crucial to mastering Java’s memory model and writing clean, efficient code. Here’s what you’ll uncover in this guide: ▪️Static Members → Belong to the class, not objects. Shared across all instances and accessed without creating objects. ▪️Instance Members → Belong to each object individually. Every instance gets its own copy of the variable. ▪️Variables & Methods → Learn how static methods differ from instance methods and what they can access. ▪️Real-World Example → See how a shared static variable (wheels) differs from instance data like color. ▪️When to Use Each → Static for constants and utility logic; instance for unique, object-level data. ▪️Common Pitfalls → Avoid referencing instance variables inside static methods and overusing static data. ▪️Interview Q&A → Covers static blocks, memory efficiency, and key differences tested in real Java interviews. Knowing when to use static vs instance members is what separates beginner code from production-grade design. 📌 Like, Share & Follow CRIO.DO for more practical Java concepts explained visually. 💻 Learn Java the Crio Way At CRIO.DO, you’ll build real-world Java applications mastering concepts like static memory, OOP design, and concurrency through hands-on projects. 🚀 Join our FREE trial today - https://lnkd.in/g9hMB7mM and level up your backend skills! #Java #OOP #CrioDo #SoftwareDevelopment #LearnCoding #StaticVsInstance #JavaBasics #ProgrammingTips #BackendEngineering
To view or add a comment, sign in
-
Go vs Java: The Interface Secret That Changes Everything After years of writing Java, switching to Go taught me something that fundamentally changed how I think about code architecture. Go doesn't care if you declare your interfaces. Let me explain what I mean: In Java (Nominal Typing): ```java class MyService implements ServiceInterface { // You MUST explicitly say "implements" // You MUST import the interface // The relationship is declared upfront } ``` In Go (Structural Typing): ```go type MyService struct{} func (s MyService) DoSomething() { // If this matches an interface somewhere, // it just... works. No declaration needed. } ``` Why this matters more than you think: → In Go, you can make third-party libraries implement YOUR interfaces without touching their code → In Java, you need adapters, wrappers, or you're stuck with what the library author gave you → Go's standard library has tiny interfaces (io.Reader is literally one method) → Java interfaces tend to be large because you must declare them upfront The real game-changer: In Go, consumers define interfaces, not producers. You write the interface you need, and anything that matches just works. In Java, producers define interfaces. The library author decides what you can depend on. For testing: - Go: Create a mock by implementing the methods. No frameworks needed. - Java: You're reaching for Mockito because you can't fake an interface without explicitly implementing it. The controversial take: Go's approach is more flexible but less explicit. You can't always tell what implements what just by reading the code. Java's approach is more rigid but crystal clear. Every dependency is declared. I used to think Java's explicit contracts were better. Now I realize Go's flexibility makes code more composable and testable by default. Question Have you worked with both? Which approach do you prefer and why? Drop your experience in the comments - I'm curious to hear different perspectives. #Fonsium #GoLang #Java #SoftwareEngineering #Programming #TechStack #SoftwareDevelopment #Pacti #CodeArchitecture
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