|
Running JavaTo execute the Java application just created, enter the following instruction: JAVA BuyCar
The JAVA command invokes the JVM and
Vehicle: Ford Explorer
|
|
Java VariablesJava has eight primitive data types, shown in Table 26.1:
Notice that no String data type is available. The closet thing to a string is the byte data type that represents a single character. Java handles Strings with a class named String. Capitalization is important here. Notice that all the data types appear in lowercase. They must be written that way in the Java code as well. The String class is capitalized to denote that it is a class rather than a data type. All the primitive data types also have associated classes. These classes provide special functions
For example, the int data type has a corresponding Integer class. Figure 26.5 illustrates the use of the int data type, its associated Integer class, and its functions:
The boolean data type has a corresponding Boolean class. Boolean values are "true/false" values. Figure 26.6 illustrates the use of the boolean data type, its associated Boolean class, and its functions:
The char data type has a corresponding Char class. Char values are single character values. Figure 26.7 illustrates the use of the char data type, its associated Char class, and its functions:
Arrays are defined by adding brackets ([]) to the end of the data type or class
|
|
Passing Arguments to JavaJava Applications define an array of optional String arguments. The example shown in Figure 26.9 makes use of arguments. It receives a list of values and prints them: JAVA BuyCar Explorer, Jeep, Accura
This line of code invokes the Buycar Java class and
Strings are not the only kind of data Java has to work with. The various numeric data types, such as the integer type discussed earlier, are commonly used in Java and are often used in mathematical formulas. A list of valid arithmetic operators are listed in Table 26.2.
|