By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
World of SoftwareWorld of SoftwareWorld of Software
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Search
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
Reading: Instance Main Methods Move from Preview to Final in JDK 25
Share
Sign In
Notification Show More
Font ResizerAa
World of SoftwareWorld of Software
Font ResizerAa
  • Software
  • Mobile
  • Computing
  • Gadget
  • Gaming
  • Videos
Search
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Have an existing account? Sign In
Follow US
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
World of Software > News > Instance Main Methods Move from Preview to Final in JDK 25
News

Instance Main Methods Move from Preview to Final in JDK 25

News Room
Last updated: 2025/05/05 at 2:18 PM
News Room Published 5 May 2025
Share
SHARE

JEP 512, Compact Source Files and Instance Main Methods, has been integrated for JDK 25 following a comprehensive four-round preview cycle beginning with JDK 21. Previously known as Implicitly Declared Classes and Instance Main Methods, these features are now finalized for JDK 25. This evolution introduces refined concepts such as Compact Source Files, flexible instance main methods, a new console I/O helper class, java.lang.IO, and automatic imports for core libraries. The primary goal is to provide beginners with an accessible entry into the Java language, while also enabling experienced developers to craft scripts and prototypes with significantly reduced ceremony.

The initiative aligns with the vision articulated by Brian Goetz, Oracle’s Java Language Architect, in his September 2022 blog post, “Paving the On-Ramp.” Additionally, Gavin Bierman, Oracle’s Consulting Member of Technical Staff, recently published the initial specification draft for community review.

Traditionally, even the simplest Java program required explicit class declarations:

// Traditional "Hello, World!"
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

JEP 512 addresses this complexity by introducing implicitly declared classes. If a source file (.java) contains methods or fields outside explicit class declarations, the Java compiler treats these contents as belonging to an unnamed, implicitly declared top-level class. This significantly simplifies beginner programs:

// "Hello, World!" using JEP 512 features
void main() {
    IO.println("Hello, World!");
}

Complementing implicitly declared classes, JEP 512 introduces support for instance methods as program entry points. For simpler scenarios, the historical requirement for a static entry point (public static void main(String[] args)) has been relaxed.

The Java launcher protocol now recognizes instance main methods. If the class selected for launching lacks a suitable static main method, the launcher searches for an instance main method. The preferred instance entry-point signature is straightforward:

void main() {
    // Program logic
}

An alternative signature, void main(String[] args), is also supported for scenarios involving command-line arguments. This approach eliminates beginners’ immediate need to grapple with the static keyword or the String[] args parameter. When utilizing an instance main method, the Java launcher automatically instantiates the class before invoking the main method.

Addressing another common point of complexity, particularly reading from System.in and printing via System.out.println, JEP 512 introduces a utility class, java.lang.IO. Residing in the java.lang package, it is implicitly available without explicit import statements. It provides essential static methods for basic console interactions:

public static void print(Object obj);
public static void println(Object obj);
public static void println();
public static String readln(String prompt);
public static String readln();

This facilitates simple, interactive programming:

// Simple interactive program using java.lang.IO
void main() {
    String name = IO.readln("Please enter your name: ");
    IO.print("Pleased to meet you, ");
    IO.println(name);
}

Notably, while the IO class itself requires no import, its static methods are no longer implicitly imported into compact source files as in earlier previews. Developers must explicitly qualify method calls (e.g., IO.println(...)) unless using explicit static imports. This adjustment ensures a smoother transition when evolving compact source files into regular classes, avoiding sudden additional requirements like static imports.

Further minimizing boilerplate, particularly beneficial for beginners unfamiliar with package structures, compact source files now automatically access all public top-level classes and interfaces from packages exported by the java.base module. This implicit import resembles a declaration (import module java.base;) proposed in a companion JEP, providing seamless access to common classes such as those in java.util, java.io, and java.math (e.g., List, ArrayList, File, BigDecimal). Thus, classes can be directly utilized without explicit imports:

// Compact source file using List without explicit import
void main() {
    var authors = List.of("Bazlur", "Shaaf", "Mike"); // List is auto-imported
    for (var name : authors) {
        IO.println(name);
    }
}

The finalization of Compact Source Files, instance main methods, the java.lang.IO class, and automatic imports from the java.base module in JDK 25 marks a substantial refinement to improve Java’s learning curve and simplify small program development. By reducing initial complexity, these enhancements facilitate a gradual introduction to Java without compromising the smooth transition to advanced programming constructs. Crucially, these features maintain compatibility and integrate seamlessly into the standard Java toolchain, reinforcing their place as core components rather than isolated dialects. If widely adopted, these improvements could profoundly influence Java education and developers’ approach when crafting simple utilities and prototypes.

 

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Twitter Email Print
Share
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Previous Article Cyprus, Israel seek to establish electricity linkup via undersea cable
Next Article Commvault CVE-2025-34028 Added to CISA KEV After Active Exploitation Confirmed
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Stay Connected

248.1k Like
69.1k Follow
134k Pin
54.3k Follow

Latest News

Today's NYT Mini Crossword Answers for May 18 – CNET
News
10 ChatGPT prompts I love that’ll turn you into a power user
News
This Search Engine Uses Its Earnings to Help the Environment. New Dashboard Lets You Track Your Impact
News
Get the best price ever on this Anker charging station and never go looking for an outlet
News

You Might also Like

News

Today's NYT Mini Crossword Answers for May 18 – CNET

2 Min Read
News

10 ChatGPT prompts I love that’ll turn you into a power user

7 Min Read
News

This Search Engine Uses Its Earnings to Help the Environment. New Dashboard Lets You Track Your Impact

6 Min Read
News

Get the best price ever on this Anker charging station and never go looking for an outlet

2 Min Read
//

World of Software is your one-stop website for the latest tech news and updates, follow us now to get the news that matters to you.

Quick Link

  • Privacy Policy
  • Terms of use
  • Advertise
  • Contact

Topics

  • Computing
  • Software
  • Press Release
  • Trending

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

World of SoftwareWorld of Software
Follow US
Copyright © All Rights Reserved. World of Software.
Welcome Back!

Sign in to your account

Lost your password?