Comp 210 Lab 13: Java Interpreter

Whereas g++ created a file which was directly executable on your machine, javac compiles to Java byte code, which requires the Java interpreter, java, to run the byte code.

While running through the interpreter is slower than running directly on the machine, the advantage is that any computer which has the Java interpreter can run your compiled program. This turns out to be ideal for the world-wide web. If you want to run my C program over the web, I don't know what type of computer you have (PC, Sparc, Mac, etc.), so I couldn't compile it to run on your machine. However, if you have a Java interpreter on your machine, I don't care what type it is, I can just ship you my exciting compiled List.class, Null.class, Cons.class, and know that they'll run on your machine.

Okay, so we have platform-independent interpreter. It turns out that the interpreter runs slower than an executable program anyway, so why bother compiling? If you want to run a program on a computer 4000 miles away, code size matters. In fact, since the computer 4000 miles away is fast once it gets the program, code size is a pretty big deal. Thus one reason for having javac compile your program to Java Byte Code is so that a smaller amount of of data needs to be transmitted over the network. (And also, even if interpreting Java byte code is slower than running (say) compiled C code, it is still faster to run the byte code than the original Java source.)


Back to Lab 13
Back to Comp 210 Home