Table of Contents |
This lesson introduces you to the basic concepts of the Java language through a line by line explanation of a simple Java application. You'll learn specifics about the syntax and semantics of the Java language including variables and data types, control flow, and operators and expressions. You will also learn about basic class definitions, themain()
method, strings, static methods and variables, and making system calls.The Character-Counting Application
The following application reads and counts characters in its input and then displays the number of characters read. The character-counting program uses several components of the Java language and of the class libraries shipped with the Java development environment. The links in the following listing visit pages that explain a particular feature of the application or a general Java language concept. Where appropriate, those pages refer you to other lessons in The Java Programmer's Guide or to other documentation.Instead of using the links embedded in the source listing above, you can use the and links (in the header and footer of each page) to step through the links in order.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."); } }Running the Application
Type in the program exactly as it appears above and save it to a file. Then use the Java compiler to compile the program, and the Java interpreter to run it.
Table of Contents |