Online Book Reader

Home Category

Think In JAVA (the third edition) [8]

By Root 15968 0
condition that occurs as part of the normal execution of the program—can be detected and dealt with only at run time. Java has exception handling to deal with any problems that arise while the program is running. This chapter examines how the keywords try, catch, throw, throws, and finally work in Java, when you should throw exceptions, and what to do when you catch them. In addition, you’ll see Java’s standard exceptions, how to create your own, what happens with exceptions in constructors, and how exception handlers are discovered during an exception.

Chapter 10: Detecting Types

Java run-time type identification (RTTI) lets you find the exact type of an object when you have a reference to only the base type. Normally, you’ll want to intentionally ignore the exact type and let Java’s dynamic binding mechanism (polymorphism) implement the correct behavior for that type. But occasionally, it is very helpful to know the exact type of an object for which you have only a base reference. Often this information allows you to perform a special-case operation more efficiently. This chapter also introduces the Java reflection mechanism. You’ll learn what RTTI and reflection are for and how to use them, and also how to get rid of RTTI when it doesn’t belong there.

Chapter 11: Collections of Objects

It’s a fairly simple program that has only a fixed quantity of objects with known lifetimes. In general, your programs will always be creating new objects at a variety of times that will be known only while the program is running. In addition, you won’t know until run time the quantity or even the exact type of the objects you need. To solve the general programming problem, you need to create any number of objects anywhere, at any time. This chapter explores in depth the collections library that Java supplies to hold objects while you’re working with them: the simple arrays and more sophisticated containers (data structures) such as ArrayList and HashMap.

Chapter 12: The Java I/O System

Theoretically, you can divide any program into three parts: input, process, and output. This implies that I/O (input/output) is an important part of the equation. In this chapter you’ll learn about the different classes that Java provides for reading and writing files, blocks of memory, and the console. The evolution of the Java I/O framework and the JDK 1.4 “new” I/O (nio) will be examined. In addition, this chapter shows how you can take an object, “stream” it (so that it can be placed on disk or sent across a network), and then reconstruct it, which is handled for you with Java’s object serialization. Java’s compression libraries, which are used in the Java ARchive (JAR) file format, are examined. Finally, the new preferences application program interface (API) and regular expressions are explained.

Chapter 13: Concurrency

Java provides a built-in facility to support multiple concurrent subtasks, called threads, running within a single program. (Unless you have multiple processors on your machine, this is only the appearance of multiple subtasks.) Although these can be used anywhere, threads are most apparent when trying to create a responsive user interface so, for example, a user isn’t prevented from pressing a button or entering data while some processing is going on. This chapter gives you a solid grounding in the fundamentals of concurrent programming.

Chapter 14: Creating Windows and Applets

Java comes with the Swing GUI library, which is a set of classes that handle windowing in a portable fashion. These windowed programs can either be World Wide Web applets or standalone applications. This chapter is an introduction to the creation of programs using Swing. Applet signing and Java Web Start are demonstrated. Also, the important JavaBeans technology is introduced, which is fundamental for the creation of Rapid Application Development (RAD) program-building tools.

Chapter 15: Discovering Problems

Language-checking mechanisms can take us only so far in our quest to develop a correctly-working program. This chapter

Return Main Page Previous Page Next Page

®Online Book Reader