As we saw in the applet
and application examples
in the first chapter, all Java programs are built within a class
Note: You can begin to program
in Java without understanding the details of object oriented code.
Later chapters discuss classes and objects in detail. For now
you can note the overall framework and then just concentrate on
the code within a method and write programs just as if Java were
a procedural language.
We provide program Starters
in which you can simply insert example and exercise codes without
dealing with the details of class design.
Below we show a simple example of a Java application program. In
Java all coding occurs within a class definition like this.
It begins with a class title line such as
followed by the members of the class enclosed within curly
braces. The members include fields
for data and methods,
which are similar to functions or subroutines in other languages.
* A Simple application.
public class SimpleApp1
public static void main(String args)
// A method to output to the console.
Begin with the class specification.
method for application programs.
using 2 slashes.
Print to console.
Curly braces span the code for a class. They also bracket
the code of a method.
Many details will vary and classes can be much longer and more
complicated but this same basic framework holds for all Java programs.
Programmers in C/C++ will note the resemblance to the main
method in those languages, though its argument is not a string array.
We will discuss in later chapters the meanings of the keywords
Latest update: Dec.11.2003