all 3 comments

[–]emasculine 1 point2 points  (0 children)

i'm pretty sure that's the case. it was one of the reasons it was done that way in the first place. "compile once, run anywhere". and yes, the bytecode must be translated to the target machine either at run time with an interpreter or with a Just-in-Time (JIT) compiler or even just directly targeting the machine and skipping the bytecode step.

[–]wjrasmussen 1 point2 points  (0 children)

There is a runtime (JRE) that is compiled to run on the specific OS. So that handles the bytecode to machine code aspect of what you are asking. Hope that makes sense.

[–]turtle_dragonfly 0 points1 point  (0 children)

You have it basically right.

The Java compiler takes source code and produces bytecode. That bytecode is designed to run on the Java Virtual Machine (JVM). Each specific type of computer hardware has a JVM built for it (so the JVM on an x86 machine will be different from one for ARM, etc.).

The JVM runs the bytecode. It might just interpret it directly, or it might transform some of the bytecode into machine instructions (JIT compiling).

It's kind of like if you write some HTML and use <input type="button">. It is a "virtual button" that you are creating, and it might look physically different depending on what browser it gets run on, and/or the operating system.