A Java program consists of a set of text files, each with a name ending in
the extension .java and the compiled versions of these files, whose
names end in .class.
Each .class file represents the definition a particular Java
class.
You will learn lots more later about what a class is.
There are two kinds of Java programs, applications and applets. An applet is a special program that runs within a Web browser. We'll learn about these later in the course. An application is a conventional self-standing program that runs on its own.
Each class definition normally includes definitions for one or more methods (procedures). Each method "does" something. When the program runs, it "calls" (executes) methods in a partcular sequence and under particular conditions that are specified by the program. Most of what you are doing when you write a program is writing method definitions. Among other things, each method has an identifier, a name that is assigned to it in its definition and that is used when it is called.
Every application must have a single class with a main method, that is, a method whose identifier is the word "main".
When you write a Java program, you edit one or more .java files containing the source code for the program.
You can use any text editor for this, but editors that are specifically designed for editing programming language source code usually have features that make this easier.
In particular, these editors know how to indent the code so that it is readable and how to use color to distinguish different kinds of text within the code.
In the class we'll use the editor that is built into Apple's XCode application. Another very useful editor (for many types of text, not just programming languages) is Emacs.
XCode is an example of a software development environment, an application that offers many features to those writing programs, including facilities for compiling and debugging programs. We will be looking at some of these features later in the course.
To run, a Java program must first be compiled.
A compiler is a program that converts source code to executable code, unless there are
errors in the source code.
A Java compiler creates .class files.
A software development environment can run the compiler for you, but we will normally do this "manually" in a shell using Unix command javac.
To run a Java application, a computer must have the proper version of the
Java Virtual Machine.
This knows how to convert the compiled code in the .class files into executable behaviors within the Java runtime environment.
There are different ways to run a program.
In the simplest cases, you can just double-click on the icon representing the class with the main method like you would with any other application on your computer.
A java program may also be compressed into a single file ending in .jar, and the icon for this file may be double-clicked like any application.
The more flexible method, because it allows for different options, is to run the program using the Unix command java within a shell, and this is what we usually do in the class.
Even if a program compiled without errors, it may encounter run-time errors when you try to run it.
These errors are reported by the java tool.
A Java program normally also includes documentation that explains how it works and how it could be used by a programmer.
You create this documentation using the javadoc tool.
The result is a set of HTML files which can be read in a browser.
The format of these files is the same as that used in the API (application program interface) for built-in Java classes.