All computers, from Macs to mobile phones, run machine code. Each computer will have its own set of instrcutions (known as an instruction set). Each different type of computer will have a different set of instructions which is why a program compiled for windows will not work on your mobile phone! Also as the operating system deals with things differently programs compiled for windows would not work under linux even if run on the same computer!

Bytecode is Java's way of getting around that. It is essentially machine indepedant code rather than machine code. That is a bit of a mouthful so the java peeps decided on bytecode instead. A class file, which is a compiled Java program, contains bytecode.

However your PC does not have a clue about bytecode! It would be like someone speaking russian to you (unless you happen to speak russian then this is a bad example!). The virtual machine has the job of converting the bytecode into machine code.

More specifically the virtual machine translates calls to the operating system and hardware. So when bytecode tries to open a window the VM will make some system calls to your OS to open a window. Same goes for opening a file or anything really! For example files are stored in one big set of directories on linux while windows will use "drives" to seperate files (like C drive or D drive).

next Java program structure >>

 
Install
Menu
Search