Skip to content

kappsegla/maven-java-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

221 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Create Your First Java Program

Java has evolved to become more beginner-friendly. This guide walks you through creating a simple program that prints β€œHello World,” using both the classic syntax and the new streamlined approach introduced in Java 21.


✨ Classic Java Approach

Traditionally, Java requires a class with a main method as the entry point:

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}

This works across all Java versions and forms the foundation of most Java programs.


πŸ†• Unnamed Class with Instance Main Method

Introduced as a preview in Java 21 (JEP 445), you can use Unnamed Classes and an Instance Main Method, which allows for a much cleaner syntax:

void main() {
    System.out.println("Hello World");
}

πŸ’‘ Why is this cool?

  • βœ… No need for a public class declaration
  • βœ… No static keyword required
  • βœ… Great for quick scripts and learning

To compile and run this, use:

java --source 25 HelloWorld.java

πŸ“š Learn More

https://docs.oracle.com/en/java/javase/21/language/implicitly-declared-classes-and-instance-main-methods.html

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages