Java Reference
In-Depth Information
using some predefined methods, you will mainly deal with Java application programs that
have only one class.
Statements to declare memory spaces (named constants and variables), statements to create
input stream objects, statements to manipulate data (such as assignments), and statements
to input and output data will be placed within the class.
Statements to declare named constants and input stream objects are usually placed outside
the method main , and statements to declare variables are usually placed within the
method main . Statements to manipulate data and input and output statements are placed
within the method main .
The syntax of a class to create a Java application program is:
2
public class ClassName
{
classMembers
}
where ClassName is a user-defined Java identifier; classMembers consists of the data
members and methods (such as the method main ). In Java, public and class are
reserved words. (Typically, the name of a class begins with an uppercase letter.)
A typical syntax of the method main is:
public static void main(String[] args)
{
statement1
.
.
.
statementn
}
Recall that in a syntax example, the shading indicates the part of the definition that is
optional.
A Java application program might be using the resources provided by the IDE, such as the
necessary code to input data, which require your program to import certain packages.
You can, therefore, divide a Java application program into two parts: import statements
and the program itself. The import statements tell the compiler which packages are
needed by the program. The program contains statements (placed in a class) that
accomplish some meaningful results. Together, the import statements and the program
statements constitute the Java source code. To be useful, this source code must be saved
in a file, called a source file, that has the file extension .java . Moreover, the name of
the class and the name of the file containing the Java program must be the same. For
example, if the name of the class to create the Java program is Welcome , then the name of
the source file must be Welcome.java .
Search WWH ::




Custom Search