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.

662<br />

Cross-Plat<strong>for</strong>m Programming<br />

entire program from scratch <strong>for</strong> a different operating system, but this<br />

process isn’t trivial.<br />

Create a program that can run on three different operating systems, and now you<br />

have to worry about maintaining and fixing problems with your program on three<br />

different operating systems. It’s possible <strong>for</strong> your program to work perfectly<br />

under Linux, but crash under Windows and the Macintosh. The more operating<br />

systems your program supports, the greater the complexity in getting your program<br />

to work right under all these different operating systems.<br />

Virtual machines<br />

The main advantage of cross-plat<strong>for</strong>m compilers is that they compile programs<br />

directly into machine language <strong>for</strong> each specific operating system,<br />

which makes your programs run as fast as possible. With today’s faster computers,<br />

speed is rarely as important as in the old days when slow programs<br />

could literally take hours to per<strong>for</strong>m a single task.<br />

Because speed isn’t as crucial as in the past, computer scientists have created<br />

another way to create cross-plat<strong>for</strong>m programs known as virtual machines.<br />

Rather than compile a program <strong>for</strong> a specific processor, virtual machine <strong>programming</strong><br />

languages compile programs to a generic <strong>for</strong>mat (called bytecode,<br />

pseudocode, or p-code) that can run on a virtual machine. This virtual machine,<br />

running on different operating systems, essentially tricks the program into<br />

thinking it’s running on a single computer, as shown in Figure 5-2.<br />

Source code<br />

Compiler<br />

Figure 5-2:<br />

A virtual<br />

machine<br />

lets a<br />

program run<br />

on multiple<br />

operating<br />

systems.<br />

Microsoft<br />

Windows<br />

Virtual Machine<br />

Mac OS X<br />

Linux

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

Saved successfully!

Ooh no, something went wrong!