Use your favorite editor to type this code, and then save your work as file Primitive.java.
The next step is to compile your code using this command:
javac Primitive.java
When that is successful, you can run your program by typing:
java Primitive
Make sure all this works before continuing.
Aside from the Java primitive types, all data types in Java are classes. In other words, every class in Java
represents a new data type. A programmer in effect creates a new Java data type every time the programmer
creates a new class. The class Primitive above is a class, but it doesn??™t have any facilities for use by other
programs, so it??™s not a good example of a reusable new data type. Soon we will show classes that do create new
data types that can be useful to other programs, however.
Sometimes you will find it necessary to operate on objects instead of primitive types. This is because
objects are reference types, and are handled differently internally than primitive types. For the purpose of
converting variables of primitive types to reference types, Java provides a set of ???wrapper classes??? so that the
programmer can always create an object having the same value as a corresponding variable of a primitive type.
Pages:
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193