Java Reference
In-Depth Information
SE 8 Development Kit (JDK). See the
Before You Begin
section
for information on down-
loading and installing the JDK on Windows, Linux and OS X.
Phase 1: Creating a Program
Phase 1 consists of editing a file with an
editor program
,
normally known simply as an
editor
(Fig. 1.6). Using the editor, you type a Java program (typically referred to as
source code
),
make any necessary corrections and save it on a secondary storage device, such as your hard
drive. Java source code files are given a name ending with the
.java
extension
, indicating
that the file contains Java source code.
Program is created in an
editor and stored on disk in
a file whose name ends
with
.java
Phase 1: Edit
Editor
Disk
Fig. 1.6
|
Typical Java development environment—editing phase.
Two editors widely used on Linux systems are
vi
and
emacs
. Windows provides
Notepad
. OS X provides
TextEdit
. Many freeware and shareware editors are also available
Integrated development environments (IDEs)
provide tools that support the soft-
ware development process, such as editors, debuggers for locating
logic errors
(errors that
cause programs to execute incorrectly) and more. There are many popular Java IDEs,
including:
On the topic's website at
we provide Dive-Into
®
videos that show you how to executes this topic's Java applications
and how to develop new Java applications with Eclipse, NetBeans and IntelliJ IDEA.
Phase 2: Compiling a Java Program into Bytecodes
In Phase 2, you use the command
javac
(the
Java compiler
) to
compile
a program
(Fig. 1.7). For example, to compile a program called
Welcome.java
, you'd type
javac Welcome.java
in your system's command window (i.e., the
Command Prompt
in Windows, the
Terminal
application in OS X) or a Linux shell (also called
Terminal
in some versions of Linux). If
the program compiles, the compiler produces a
.class
file called
Welcome.class
that
contains the compiled version. IDEs typically provide a menu item, such as
Build
or
Make
,
that invokes the
javac
command for you. If the compiler detects errors, you'll need to go
back to Phase 1 and correct them. In Chapter 2, we'll say more about the kinds of errors
the compiler can detect.