Hacker News new | ask | show | jobs
by bastloing 575 days ago
I thought java was tokenized, not compiled. That's why you need their runtime environment isn't it?
4 comments

It is compiled to Java byte code. The JVM runs the byte code.

Tokenization [1] is the process of splitting text into components called tokens. It's usually the first stage of parsing.

[1]: https://en.wikipedia.org/wiki/Lexical_analysis#Tokenization

Compiled means it's a direct executable in machine code. Java ain't that. Heck, if it needs a runtime with a garbage collector built into the runtime it's especially junk.
No, that is not what compiled means. A compiler is simply a program that translates from one language to another. Hence a compiled language is one that is translated into a different language prior to execution. Java is compiled twice; once to byte code and again to machine code by the JIT compiler. That is unless you compile it directly to machine code using, say, Graal Native Image.

You are welcome to your opinion on the utility of garbage collection but the widespread usage of GC suggests the industry as a whole does not share your view nor is such an unnaunced view supported by research (e.g. https://dl.acm.org/doi/abs/10.1145/1094811.1094836)

As having a masters in computer science I respectfully disagree with you. Would you consider a program that translates C code to FORTRAN a compiler? Nope, it's a translator. A compiler compiles a language into a direct executable. Just like Microsoft Windows has executables, .exe file, there's no runtime required to run those files.
Nobody calls them “translators”, that’s so silly. It’s a compiler, or transpiler (still a compiler).

Avoid using appeals to authority when discussing, it doesn’t make you look good. Even more-so when your authority is relatively mundane and you’re totally incorrect.

Transpilers are a subset of compilers, even if somewhat often "compiler" is used to refer to the ones producing executables.

And .exe-s still need the OS, dynamic libraries, and, perhaps most importantly, the CPU (which is pretty much a VM interpreter, modern CPUs having what's essentially a custom IR, peephole optimizations, aliasing analysis, JITting, loop unrolling, PGO, caching, ...), to run.

You should use your CS master skills to read the first line of the "Compiler" article in Wikipedia [1]

> In computing, a compiler is a computer program that translates computer code written in one programming language (the source language) into another language (the target language).

And maybe also the second line. JVM bytecode is an object code as referenced there.

[1] https://en.wikipedia.org/wiki/Compiler

I would call this a transpiler, and it's definitely a kind of compiler. I typically use the word compiler to imply that I'm moving to a lower level representation, and a transpiler as one that does a horizonal translation.

There are expections to this general rule of thumb, Cross-compiling is a term used for a horizonal translation.

I also watched this video of a PhD project that compiles JavaScript from an input of Visual data and JavaScript. Which is probably one of the more interesting uses of compiler I've seen.

https://youtu.be/MQnVmEw6ISQ?si=NYCSuzi3IxG0md_k

Why would holding a MS make you an authoritative source on… anything?

Anyway, there’s no real agreement on the terms and everyone has an opinion. This is as useful as arguing “is a taco a sandwich”

I very much consider RATFOR a compiler.
javac does produce machine code. You just don't like the machine.
We used to have Java CPUs

https://en.m.wikipedia.org/wiki/Java_processor

The JVM is just to run the code on other systems, and is the most common way of running compiled Java code.

I think it means "compile it into bytecode", which can then be run by the Runtime.
So like most JIT languages nowadays?
That's pretty much the definition of tokenized. I know Oracle would like us to think different, but facts are facts
Since you seem passionate about precise definitions for technical terms, maybe you could point us to third-party definitions which match your understanding? Start with sources for what "compilation" and "tokenization" mean as you understand them?
You are thinking of the typical design of a BASIC system in the 80's. Keywords were stored as "tokens" (numbers) but expressions were usually stored as space-stripped strings. There would be an edit-time syntax check (combined with the tokenization) to check if the expressions were syntactical and only in places where they were allowed). Some designs did use tokens for the expressions too.

There was almost no syntax involved and essentially zero compilation work.

Java compilers do a lot more than that. They actually compile to a real (abstract) machine and they do real compiler things (proper parsing, maintenance of namespaces, type checks). They usually don't do any optimization because that will happen at run-time anyway -- but that doesn't make them "not compilers".

> That's pretty much the definition of tokenized

Oh boy. It’s rare to see such confidence mixed with such nonsense.

Java is compiled down to bytecode and there is a bunch that happens in the compiler to make things fast ahead of the JIT.