The Nuts and Bolts of the Java Language |
In the Java language, all methods and variables must exist within a class. So, the first line of the character-counting application defines a class,class Count { public static void main(String args[]) throws java.io.IOException { int count = 0; while (System.in.read() != -1) count++; System.out.println("Input has " + count + " chars."); } }Count
, that defines the methods, variables, and any other classes needed to implement the character-counting application. Since this program is such a simple one, the Count class just defines one method namedmain()
.Defining a Class in The Anatomy of a Java Application contains a more thorough discussion about defining a class.
The Nuts and Bolts of the Java Language |