Ask HN: Is Java the ideal language for LLM-assisted coding?

4 points by fragmede ↗ HN
Which programming language to use, now that LLMs are writing code, is at the forefront of everybody's minds when they start a new project.

Python, Rust, C++, Golang, and Swift come to mind for me, depending on the project, but I'm starting to think Java is actually the ideal LLM language, especially with LLM-driven sysadmin-ing making it easier to set up and run Java.

4 comments

[ 2.0 ms ] story [ 16.6 ms ] thread
Like humans, I’ve never seen an LLM write Java voluntarily.

They write python as readily as people breathe, though.

The argument that Java is LLM-friendly because its specifications enforce these four factors makes sense, but conversely, other languages that satisfy these four criteria—such as TypeScript, Kotlin, and Rust—fall into the same category.

In my own Python code, after tightening up Pydantic + strict mypy + pytest, I’ve noticed a significant increase in Claude’s first-pass accuracy. I believe which conventions you adopt within a language is more important than the language itself.

Additionally, a pitfall specific to Java is that the training data still contains a large amount of Spring XML/AbstractBeanFactoryAware-style patterns from the old Java 7–8 era. To elicit modern Java 21+ idioms, you need to specify them explicitly in the prompt. Conversely, Python tends to produce the latest idioms by default.

I understand the OP’s intuition (that Java is being reevaluated due to improvements in infrastructure tools), but the essence lies in “language design that enforces LLM-friendly coding styles.” In that sense, my personal conclusion is that Java is one of the good fits.

> I'm starting to think Java is actually the ideal LLM language

Why?

I'm quite a fan of lightgbm4j. It is a JNI Wrapper, but the API is decent. Training itself happens in native code, but the real advantage your support code gets compiled to native through the JVM's compiler.

I've also authored a Machine Learning Model compiler for the JVM: https://github.com/exabrial/petrify . This allows you to take Many Trees/Ensembles/Regressors/Classifiers/etc and compile them as regular Java classes! ...removing the long dependency chain that ML Models drag with them to run in production. It's also very memory efficient; exactly one array allocation invocation, with 0 other Garbage Collector pressure. Your weights and splits are also stored in the constant pool; making it an excellent C2 target and do not add to the additional heap memory pressure!

Overall, I think it's an ideal language for Data Science; but what it lacks compared to Python is community engagement. Oracle has Tribuo, which is actually quite good; but Oracle is still learning to interact with the open source community.