JRE is machine dependent but compiler is machine independent

J

jrefactors

When we download JRE, there are different platforms to choose. That
means JRE is machine dependent, but Java Compiler is machine
independent.

Is that the story board?

Java Code -> Java Compiler -> Class File -> Platform Dependent JRE ->
Native Code

Is that correct?
Please advise. Thanks
 
G

Grant Wagner

When we download JRE, there are different platforms to choose. That
means JRE is machine dependent, but Java Compiler is machine
independent.

The compiler itself is machine dependant, that is, you need a different
Java compiler for each platform you run it on, but the bytecode it
produces is machine independant (at least in theory). If you include
things in your Java program that are machine dependant such as
references to "drive letters" or hardcoding directory path separators
then the bytecode may be technically machine independant, but it will
not run correctly on platforms other than the one it is targeted for.
Java Code -> Java Compiler -> Class File -> Platform Dependent JRE ->
Native Code

Pretty much. The behaviour of the JRE or JVM (Java Virtual Machine) is a
"black box", you don't necessarily know (or care) what is going on
inside. It can "interpret" the bytecode instruction by instruction and
execute the appropriate native CPU instructions, or it can JIT
(Just-In-Time) compile the bytecode to native code, then execute that
native code. Or it can do a bit of both.
 
M

Michael Borgwardt

Grant said:
The compiler itself is machine dependant, that is, you need a different
Java compiler for each platform you run it on,

No, because the compiler itself (at least Sun's javac) is written in Java,
so all you need is a (definitely machine dependant) JRE.
 
E

Eric Sosman

Michael said:
Grant Wagner wrote:




No, because the compiler itself (at least Sun's javac) is written in Java,
so all you need is a (definitely machine dependant) JRE.

You need just a little more, but not much. There's a small
platform-specific launcher program (about 28KB on Solaris, 45KB
on Windows) that gets things started. The real "meat" of the
compiler is, as you say, a bunch of Java bytecode.
 
M

Michael Borgwardt

Eric said:
You need just a little more, but not much. There's a small
platform-specific launcher program (about 28KB on Solaris, 45KB
on Windows) that gets things started. The real "meat" of the
compiler is, as you say, a bunch of Java bytecode.

True, but the launcher is actually not necessary and exists only for
convenience's sake. You could also start the compiler like this:

java -cp tools.jar com.sun.tools.javac.Main <compiler arguments>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top