3

I thought I've always understood why Java was portable, until I took Computer Organization.

This is my interpretation of a C program from start to finish:

C program --> compiler --> assembly --> machine code --> ISA --> micro architecture (how the computer interprets ISA) --> logic gate --> circuit --> device

Where the compiler must have knowledge of the ISA. Also, the assembly and machine code will vary based on ISA.

Java is as such: (inside JVM): Java program --> compiler --> bytecode

bytecode is the ISA for a JVM.

So, I am guessing the JVM also has it's own micro architecture to interpret it's ISA (bytecode).

Is this accurate?

So the overall cycle would be: (inside JVM) Java program --> bytecode(ISA) --> JVM micro architecture --> host hardware

Also, if the micro architecture is implemented in the processor, does the JVM need to use one of the hosts' processors?

jinan
  • 173
  • 1
  • 10

2 Answers2

2

It's more like (following your layering for C):

Java program --> Java compiler --> bytecode --> JVM compiler --> assembly 
--> machine code --> ISA --> micro architecture (how the computer interprets ISA)
--> logic gate --> circuit --> device

Note that there are essentially two compilers. That's how Java achieves portability.

M A
  • 71,713
  • 13
  • 134
  • 174
  • But doesn't assembly and machine language vary per machine based on ISA? – jinan Feb 18 '16 at 21:41
  • 2
    @jinan Yes, and so does the JVM. There are different implementations of the JVM for different hardware/OS, and each translates to the appropriate native language of the platform. – M A Feb 18 '16 at 22:43
0

First, java compiler compiles the source code into byte code. At the run time,Java Virtual Machine (JVM) interprets this byte code and generates machine code which will be directly executed by the machine in which java program runs.

Visit good tutorial of JVM,JRE and JDK https://javatutorialdetails.blogspot.com/2017/10/java-tutorial-in-details-step-by-step.html

M J
  • 11
  • 1