Java Reference
In-Depth Information
In skeleton form, a Java application program looks like the following:
import
statements if any
public class
ClassName
{
2
named constants and/or stream objects declarations
public static void
main(String[] args)
{
variable declaration
statements
}
}
Notice that the heading of the method
main
contains the reserved word
static
.The
statements to declare the named constants and the input stream objects are placed outside
the definition of the method
main
. Therefore, to use these named constants and stream
objects in the method
main
, Java requires that you declare the named constants and the
input stream objects with the reserved word
static
. Example 2-26 illustrates this concept.
EXAMPLE 2-26
The following is a simple Java application program showing where in a Java program the
import statements, the method
main
, and statements such as named constants, declara-
tions, assignment statements, and input and output statements typically appear.
//*****************************************************************
// Author: D.S. Malik
//
// This program shows where the import statements, named constants,
// variable declarations, assignment statements, and input and
// output statements typically appear.
//*****************************************************************
import
java.util.*;
//Line 1
public class
FirstJavaProgram
//Line 2
{
//Line 3
static final int
NUMBER = 12;
//Line 4
static
Scanner console =
new
Scanner(System.in);
//Line 5
public static void
main(String[] args)
//Line 6
{
//Line 7
int
firstNum;
//Line 8
int
secondNum;
//Line 9
firstNum = 18;
//Line 10
System.out.println("Line 11: firstNum = "
+ firstNum);
//Line 11
Search WWH ::
Custom Search