15.04.2018 Views

programming-for-dummies

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Compiling to a Virtual Machine 93<br />

Compiling to a Virtual Machine<br />

The problem with compilers is that they’re difficult to make <strong>for</strong> multiple<br />

operating systems and processors. The problem with interpreters is that<br />

they need the source code of a program to run, making interpreters unsuitable<br />

<strong>for</strong> distributing software. To solve both these problems, computer scientists<br />

created a third alternative — a virtual machine.<br />

To protect the source code of a program, a virtual machine lets you compile<br />

your program into an intermediate file called bytecode or pseudocode (also<br />

known as p-code). To make a program run on multiple operating systems,<br />

you need a virtual machine that runs on each operating system, as shown in<br />

Figure 4-3.<br />

Book I<br />

Chapter 4<br />

Programming Tools<br />

Source code<br />

Compiler<br />

Machine code<br />

A compiler normally converts source code directly into machine<br />

code <strong>for</strong> a specific type of processor.<br />

Source code<br />

Figure 4-3:<br />

A virtual<br />

machine<br />

acts like a<br />

combination<br />

of an<br />

interpreter<br />

and a<br />

compiler.<br />

Virtual machine<br />

<strong>for</strong> Windows<br />

Compiler<br />

Bytecode<br />

Virtual machine<br />

<strong>for</strong> Mac OS X<br />

Virtual machine<br />

<strong>for</strong> Linux<br />

When compiled to bytecode, a program can run on any operating<br />

system that has the bytecode virtual machine installed.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!