|
|
|
|||
|
The Nuts and Bolts of the Java LanguageTheCount class shown below contains a
method named countChars that reads and
counts characters from a Reader
(an object that implements an input stream of characters)
and then displays the number of characters read.
Even a small method such as this
uses many of the traditional language features
of Java and classes from the Java API.
Through a line-by-line investigation of this simple method, this lesson describes Java's traditional language features such as variables and data types, operators, expressions, control flow statements, and so on.
The previous listing of the Variables and Data TypesLike other programming languages, Java allows you to declare variables in your programs. You use variables to contain data that can change during the execution of the program. All variables in Java have a type, a name, and scope. The example program shown previously declares these two variables among others: OperatorsThe Java language provides a set of operators which you use to perform a function on one or two variables. The ExpressionsOperators, variables, and method calls can be combined into sequences known as expressions. The real work of a Java program is achieved through expressions. Control Flow StatementsThe Arrays and StringsTwo important data types in any programming language are arrays and strings. In Java, both arrays and strings are full-blown objects. Other languages force programmers to manage data in arrays and strings at the memory level using direct pointer manipulation. | |||
|