5
System.err.println( "I/O error: " + e.getMessage() );
}
}
}
SUMMARY
Java is a modern object-oriented programming language. This chapter discussed how to compile and run
Java programs. We discussed the ???primitive??? data types in Java, as well as the frequently used ???reference??? types
including String and Array types. We explained the use of control structures for selective code execution
and iteration. These statements included the if-else, for, while, do-while, and switch statements.
Java takes advantage of the OO concept of classes, and the attendant principles of inheritance, encapsulation,
and polymorphism. An instance of a class is called an object, and objects have state and behavior. Classes define
both instance and static variables, which manifest the state of an object. Classes also define both instance and
static methods, which endow objects with their characteristic behaviors. Java also provides the concept of an
interface, which makes it possible to enforce similar behavior across different classes.
Error handling in Java is accomplished using Exception objects. When an error occurs, a program can
throw an Exception, which can describe the problem. Exceptions can be caught within the application
when the code generating the Exception is enclosed in a try block.
Pages:
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248