javac the Java Compiler
Some programming languages, such as C and Fortran, are compiled languages: the source code is compiled into machine code that is unique to the target hardware platform and operating system. Other languages, such as like APL and lisp, are interpreted languages: the source code is executed by running it through an interpreter. Both approaches have their strengths and weaknesses. Compiled programs tend to be faster and more efficient, but the compiled program can be run on only one hardware platform and operating system. Interpreted programs tend to be less efficient but potentially can be run, without change, on any platform for which an interpreter exists.
Java is both compiled and interpreted. The Java compiler, called javac, compiles (translates) the Java source code into an intermediate-level code called byte codes. These bytecodes are not directly executable on any hardware platform that is currently in existence; rather, the codes are interpreted by the Java interpreter, which can operate either by itself or as part of a Web browser such as Netscape.
The fact that Java is both compiled and interpreted can give you, the Java programmer, the best of both worlds. A program that you write in Java will be efficient (because it is compiled) and capable of running on a multitude of platforms (because it is interpreted).
In this chapter, you learn the following:
- How to get started with the Java compiler
- The Java compiler is easier to use than it seems. You'll find that out when you compile and run your first Java program.
- How the Java directories are organized
- The Java Development Kit is split across a number of directories. This chapter covers those directories that are significant to the compiler.
- How to use the various compiler options
- The Java compiler supports a number of options that vary its operation. You'll learn about those in this chapter.
- How to troubleshoot common compiler problems
- You'll learn to recognize and solve some of the problems that you may encounter with the Java compiler, especially when you use it for the first time.
Finding javac on your system
求职, 招聘找易才网The installation process that you completed in chapter 3 creates a hierarchy of directories, beginning with a directory called java. When we installed Java on our system, we put the java directory below a root-level directory called Languages, but you can put yours wherever you think is best, including directly below the root. After installation, then, we have the following directories on our machine: