logoalt Hacker News

amelius • yesterday at 11:08 PM • 7 replies • view on HN

I'm not a Java person, but I'm curious how fast it is nowadays, and also the startup time. Can it be used to write shell commands with, for example?


Replies

twic • today at 1:44 AM

    $ echo 'class Hello { public static void main(String[] args) { System.out.println("Hello, world"); } }' >Hello.java
    $ javac Hello.java 
    $ java --version
    openjdk 21.0.7 2025-04-15 LTS
    OpenJDK Runtime Environment Zulu21.42+21-CRaC-CA (build 21.0.7+6-LTS)
    OpenJDK 64-Bit Server VM Zulu21.42+21-CRaC-CA (build 21.0.7+6-LTS, mixed mode, sharing)
    $ time java -cp . Hello
    Hello, world
    
    real 0m0.026s
    user 0m0.010s
    sys  0m0.018s
For some reason this machine is still on 21. Anyway, the overhead of the JVM itself is pretty low.

For small tools it's fine:

    $ echo 'class Dig { public static void main(String[] args) throws Exception { var addr = java.net.InetAddress.getByName(args[0]); System.out.println(addr); } }' >Dig.java
    $ javac Dig.java
    $ time java -cp . Dig news.ycombinator.com
    news.ycombinator.com/209.216.230.207
    
    real 0m0.047s
    user 0m0.026s
    sys  0m0.021s

    $ time host news.ycombinator.com
    news.ycombinator.com has address 209.216.230.207
    news.ycombinator.com has IPv6 address 2606:7100:1:67::26
    
    real 0m0.052s
    user 0m0.005s
    sys  0m0.004s
Java startup gets slow when you use some massive framework like Spring. If you need a program to start fast, don't use one!
illusive4080 • today at 1:29 AM

Startup time depends on whether you are using Spring heavily or not. I wouldn’t use it as a shell script replacement. Use Python to that end.

ww520 • yesterday at 11:37 PM

I'm using JDK 21 (old) and the startup time is sub-second for small programs.

➕ show 1 reply
azatom • today at 12:02 AM

Sorry if it is trivial but bc you asked shell command and if meant the "java script.java" no compile way: even that is fast, but if you run in a shell script loop thousand times, then do not forget to compile.

binary132 • today at 12:00 AM

JIT + hotspot optimization makes JVM pretty fast, but warmup time is usually the problem. However it does look like they’re addressing startup time with improvements in this release:

- AOT compilation: https://openjdk.org/jeps/544 - ~100ms startup for ZGC: https://openjdk.org/jeps/545

jiggawatts • yesterday at 11:19 PM

Every time I try, I keep going back to .NET, which has been optimising for faster startup time.

Almost all Java benchmarks are for the "steady state" after half an hour of warm up time.

➕ show 2 replies
__natty__ • yesterday at 11:45 PM

Very fast. And yes, it can be used for small apps too. With java problem now is not the performance but how verbose still it is. However, it's much better since Java 17 and each release make it even more compact and direct. Like in this release we got much better built-in support for JSON.