• JackbyDev@programming.dev
    link
    fedilink
    English
    arrow-up
    5
    ·
    8 hours ago

    This is getting a little better nowadays.

    > cat Hello.java
    void main() {
        System.out.println("Hello, World!");
    }
    > java --enable-preview Hello.java
    Hello, World!
    

    Things to notice:

    1. No compilation step.
    2. No class declaration.
    3. Main method is not public static
    4. No String[] args.

    This still uses preview features though. However, like you demonstrated already, compilation is no longer a required step for simplistic programs like this.

    • مهما طال الليل@lemm.ee
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      20 minutes ago

      Main method is not public static

      It must be somewhere under the hood. Otherwise, it wont be callable and it would require an instance of an object to call. Unless the object here is the Java environment?

      No String[] args

      They are just optional I’m sure, like C and C++. You still need them to read command line arguments.

      All in all, these syntax improvements are welcome. I already moved on to Kotlin for Android development though.

    • cashew@lemmy.world
      link
      fedilink
      arrow-up
      4
      ·
      edit-2
      5 hours ago

      Microsoft Java is a one-liner these days.

      > cat program.cs
      Console.WriteLine("Hello, World!");
      > dotnet run
      Hello, World!