Читать книгу Beginning Programming All-in-One For Dummies - Wallace Wang - Страница 63

Gaining true portability with Java

Оглавление

Although C and C++ programs are supposed to be portable — you can copy and run them on other computers — they’re not really. Sometimes you have to make minor changes to get a C/C++ program to run on another computer, but more often, you have to make major changes.

That’s why Sun Microsystems created the Java programming language. Like C++, Java is also based on the C language, but it includes several features to make Java programs safer than C or C++ programs. Specifically, Java isolates the programmer from directly accessing the computer’s memory. This reduces the power of Java somewhat but translates into safer programs that (hopefully) won’t crash as often as C/C++ programs do.

Perhaps the most important feature of Java is its portability. Rather than try to compile a Java program into machine language for different types of processors, Java compiles Java programs into an intermediate file format called bytecode or pseudocode (also called p-code).

To run a Java program that’s compiled into bytecode, you need a free Java virtual machine (VM). As long as a computer has a Java VM, it can run a Java compiled bytecode program.

Like most promises made by computer scientists, Java programs aren’t always portable. You can write a Java program correctly, compile it to bytecode format, and make the program run perfectly on a specific computer and operating system. But copy that same bytecode program to another computer, and suddenly, the Java program doesn’t run correctly. The problem can occur when the Java VM, on either computer, has errors in it. So, although Java programs are more portable than C/C++ programs, they still aren’t 100 percent portable.

Besides creating full-fledged programs, like word processors or spreadsheets, Java can also create applets (smaller programs), which can be used to create interactive web pages.

If you’re looking for a programming language that makes programming safer and more portable, consider Java. Java programmers are in demand almost as much as C/C++ programmers, and the similarities between Java and C/C++ make it relatively easy to understand after you know C. (Or you can study Java first and then study C/C++ later.)

Beginning Programming All-in-One For Dummies

Подняться наверх