← Back to context

Comment by tofflos

20 hours ago

You can also choose to run directly from source with a small penalty at startup and verbosity has decreased for simple use cases. It's still not great for scripting but the situation has been steadily improving over the last couple of years.

  void main() {
    IO.println("Hello world");
  }

  $ time java Hello.java
  Hello world

  real    0m0.662s
  user    0m2.421s
  sys     0m0.198s

  void main(String[] args) throws Exception {
    IO.println(InetAddress.getByName(args[0]));
  }

  $ time java Dig.java news.ycombinator.com
  news.ycombinator.com/209.216.230.207

  real    0m1.154s
  user    0m2.379s
  sys     0m0.222s

You can also use a shebang and mark the file as executable on Linux:

  #!/usr/bin/java --source 25
  
  void main(String[] args) throws Exception {
    var addr = java.net.InetAddress.getByName(args[0]);
    System.out.println(addr);
  }