CodeNotes for Java: Intermediate and Advanced Language Features will introduce the reader with a grasp of basic Java to advanced object oriented design techniques, collections, I/O, multi-threaded applications, internationalization and more. Experienced Java programmers will also benefit from the numerous examples, tips and tricks and design notes that explain why these Java features are fundamentally important to every development effort.
This edition of CodeNotes includes:
-A global overview of a technology and explanation of what problems it can be used to solve
-"How and Why", and "Bugs and Caveats" sections that provide hints, tricks, workarounds, and tips on what should be taken advantage of or avoided
-"Design Notes" illustrating many of the common use patterns for Java programs
-Instructions and classroom-style tutorials throughout from expert trainers and software developers
Visit www.codenotes.com for updates, source code templates, access to message boards, and discussion of specific problems with CodeNotes authors and other developers.
Every CodeNotes title is written and reviewed by a team of commercial software developers and technology experts. See "About the Authors" at the beginning of the book for more information.
About the Author
Read an Excerpt
Chapter 1: Introduction
JAVA: INTERMEDIATE AND ADVANCED TOPICS
If you work with Java for any length of time, you will almost certainly encounter many of the concepts presented in this book. However, there is a difference between being able to use the language and actually understanding the language. The main purpose of this book is to help any beginning or intermediate Java programmer develop a firm understanding of both how and why the Java language works. For more advanced Java developers, this book contains many examples and design notes about how to use some of Java’s most powerful features. As part of the CodeNotes philosophy, this book focuses on practical examples, including working with collections, creating and using threads, selecting the proper I/O classes, and designing an application that supports multiple languages. With the numerous code samples and extensive additional material on the CodeNotes website, this book will make almost anyone a better Java developer.
This book as a whole is fundamentally about why Java works the way it does. However, the individual chapters are devoted specifically to features found in the Java 2 Standard Edition (J2SE). The core of this book is divided into five main development chapters (Chapters 3 to 7), a short deployment chapter (Chapter 8), and The Dark Side (Chapter 9) for everything that was left out.
-Chapter 3, Objects and Classes. Java is fundamentally an object-oriented language, which means that objects, encapsulation, and polymorphism play a major role in every single aspect of the language. At first glance, this chapter may seem like a basic topic. However, understanding why the Java language works the way it does requires a firm grasp of inheritance, interfaces, inner classes, and reflection. Although this chapter does explain the basic mechanics, it goes much further into the possibilities that are only available through object-oriented programming.
-Chapter 4, Collections. Almost every developer is familiar with the concept of an array as a data-storage mechanism. However, arrays are not always useful. The Java Collections Framework offers a set of alternative classes for storing and managing collections of data. Building extensively on interfaces and inheritance, the Java Collections Framework provides an ideal example of how object-oriented programming works in practice.
-Chapter 5, Java I/O. Very few programs operate without accepting some form of input or generating some form of output. Java provides an extensive framework for creating I/O systems of almost any description. Once again, this framework relies heavily on object-oriented programming principles, which is why it is often confusing to new programmers. Java’s version of I/O has all of the same functionality as other I/O systems (such as C-style fopen(), fprintf(), and fclose(), or C++-style IOStream objects with >> pipes), although it is often hidden through abstraction and encapsulation.
-Chapter 6, Threads. Java provides a surprisingly simple mechanism for creating and controlling multithreaded applications. However, this simplicity is often misleading, as a few lines of code can belie tremendous complexity. This chapter illustrates the basic process for creating and controlling threads and provides several examples for the common tools needed to control multithreaded programs (such as semaphores).
-Chapter 7, Internationalization. As the international demand for computer software continues to expand, the need for multilanguage, multicountry interfaces becomes even more acute. Rather than developing a new application for each country and each language, you can take advantage of Java’s many built-in features for customizing an application for a particular region. This chapter may not provide all of the answers, but it should open your eyes to the many challenges of creating international applications and provide enough of a background so that you can start the process on your own systems.
-Chapter 8, Deployment. Deploying a Java program is as simple as making sure the client has a Java Virtual Machine (JVM) and then installing a Java Archive, or JAR file. This chapter also provides an introduction to the javadoc tool, for generating application program interface (API) documentation, and the Jakarta Ant project. Ant is an XML-based replacement for the venerable make command. You can use Ant to compile all of your Java code, create JAR files, perform shell scripts, and even generate your API documentation automatically.
-Chapter 9, The Dark Side. Every book has secrets. This chapter provides a very brief introduction to several important Java topics that aren’t covered in this book, as well as a brief list of the more important changes in the Java 2 Standard Edition 1.4 release. At the time of writing, this release is in public beta, so the information in this section is subject to change.
ABOUT THE VENDORS
Sun Microsystems (www.sun.com) originally developed Java as a language for TV-top boxes, which were an instrumental component of the anticipated interactive TV explosion. Instead, the Internet and World Wide Web exploded and Java was quickly drawn into the realm of platform-independent computing. Sun’s philosophy for Java consists of two key statements: “The Network is the Computer”™ and “Write Once, Run Anywhere”™. The philosophy behind these two statements is built into every aspect of Java and J2EE.
Java Development Environments
Although you do not need a development environment for Java, most environments offer significant advantages over text editors, including keyword identification, debugging, parentheses matching, and integration with other tools such as javadoc, jar, and Jakarta’s ant. The following are among the most popular environments:
-Borland JBuilder 4 Enterprise (www.borland.com/jbuilder/)
-Sun’s Forte for Java (www.sun.com/forte/)
-IBM’s VisualAge for Java (www-4.ibm.com/software/ad /vajava/)
-WebGain VisualCafe (www.webgain.com/products/visual_cafe/)