Java 2 Exam Prep, Second Edition / Edition 2 available in Hardcover
- Pub. Date:
- Coriolis Value
About the Author
Read an Excerpt
Chapter One: Introduction to JavaAfter completing this chapter, you will be able to:
- Understand some of the design philosophy behind Java
- Understand the parts of the Java Software Development Kit (SDK)
- Run the demo programs included with the SDK
Java Design PrinciplesOne joke making the rounds when Java was first introduced described Java as "fully buzzword-compliant." This statement does have a certain amount of truth, because Java incorporates much of the modern thinking about computer languages. One of the first statements from the designers described Java as a simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, high-performance, multithreaded, and dynamic language.
The following list analyzes whether this description of Java has held up in the years since then:
- Simple—Java's syntax and program organization is certainly much simpler than
competing languages, such as C and C++. This simplicity is the benefit of
starting with a clean slate. The decision to use many aspects of C syntax has
made it easy for programmers to move from C to Java.
- Object oriented—All Java programs consist entirely of interacting Java objects.
The decision to make Java completely object oriented has certainly been
vindicated by the ease with which various extensions have been created.
- Distributed—Java was "network aware" from the beginning and seems to have
become the preferred language for networked applications in which the
complete application is composed of parts distributed across the network.
- Portable, interpreted, architecture-neutral—Java programs are compiled to bytecodes
that have no dependencies on a particular machine architecture. To run on a
particular system, all you need is a Java interpreter. Java now runs on a large
variety of systems, from mainframes to intelligent credit cards.
- Robust—The Java designers made numerous design decisions to avoid the
weaknesses inherent in other languages. Among these decisions was one to include strong typing, automatic memory management, and built-in array
- Secure—The Java architecture provides multiple layers of security checking.
These security checks range from low-level verification that bytecodes are
legal, to high-level control of access to files and other system resources.
- High-performance—Although some aspects of Java are very efficient, its raw
speed still hasn't reached the level of C++, except in some limited cases.
- Multithreaded—Java's design has made it easy to create multithreaded programs,
which is one reason for Java's popularity in networked applications.
- Dynamic—Running programs in Java can be dynamically modified, and developers have benefited greatly from this increased flexibility.
History of JavaSomeday, the saga of Java's introduction and its impact on the computer industry will make an interesting story. Most introductions of new computer languages seem to creep along as various books and articles are written and people start experimenting.
Why Java has had such a huge impact so quickly is worth analyzing. The following factors seem to be among the most important:
- Development subsidy by a large corporation—As a major hardware producer, Sun
Microsystems could afford to fund the development program, publicity, and
free distribution of Java.
- The Internet—The first major Java program was the HotJava Web browser. The
development of this browser demonstrates the extent to which Java's design is
suitable for Internet-related applications. Programmers were looking for an
easy route to explore programming for the Internet, and Java was right there
for free download.
- Worries about Wintel—The lock that Microsoft and Intel had obtained on the desktop computer had a lot of people worried. Java seemed to offer an escape from the Wintel world.
Table 1.1 A short history of Java....
Java ToolsSun provides the basic tools for Java in the Software Development Kit (SDK), which is platform dependent and in a separate documentation package that is platform independent. All of the platform-dependent code is used to create a Java Virtual Machine (JVM) for a particular hardware and operating system configuration.
The Java Virtual MachineYou might think of the JVM as creating a computer within a computer—a virtual computer. The instructions in Java programs are compiled to bytecodes, which are the instructions for this virtual computer. Naturally, bytecodes are called such because they occupy a single eight-bit byte. In addition to interpreting bytecodes, the JVM must supply interfaces to the various subsystems that the operating system manages for the display, mouse, keyboard, file system, and I/O ports.
Development ToolsAs the scope of the various Java libraries and toolkits continues to expand, Sun has rationalized the grouping of these products into three areas...
Table of Contents
|Chapter 1||Introduction to Java||1|
|Java Design Principles||2|
|History of Java||3|
|Sun's Java Certification Exam||6|
|Get a Java Job||7|
|Chapter 2||Java Language Fundamentals||13|
|The Structure of Java Programs||14|
|Java Reserved Words||17|
|Java Variables and Data Types||18|
|Sun's Software Development Kit||28|
|Conventions for Applications||30|
|Conventions for Applets||33|
|Javadoc Format Documentation||36|
|Chapter 3||Java Operators with Primitives and Objects||47|
|Logical and Bitwise Operators||55|
|Logical Operators with Objects||60|
|String Operators: A Special Case||64|
|Casting and Converting of References||67|
|Array Declaration, Initialization, and Conversion||68|
|Chapter 4||Creating Java Classes||85|
|Creating Java Classes||86|
|Declaring a Java Class||86|
|Static Members and Variables||101|
|The this Keyword||106|
|Chapter 5||Flow Control and Exceptions||135|
|Loops with for, while, and do||136|
|Branching with if--else and switch||140|
|Summary of Basic Flow Control||142|
|Exceptions, Errors, and Flow Control||143|
|Exceptions, try, catch, and finally||146|
|Designing Programs with Exceptions||147|
|Chapter 6||Program Architecture with Java Classes and Objects||167|
|Extending Classes and Implementing Interfaces||168|
|Abstract Classes in Program Design||174|
|More about Interfaces||175|
|The Class Class||177|
|The final Problem||178|
|Class Design and Encapsulation||178|
|Design Patterns and Java||179|
|Memory Management in Java||182|
|Chapter 7||Java Threads||201|
|Multitasking vs. Multithreading||202|
|The Thread Class||203|
|Synchronizing Objects and Threads||211|
|Using wait and notify||215|
|Hazards of Thread Programming||217|
|Exceptions Associated with Threads||218|
|Chapter 8||Standard Java Library||235|
|The Core Classes||236|
|The Extended Math Classes||247|
|The Utility Classes||248|
|The Original Collections||251|
|The Advanced Collections Classes||257|
|Chapter 9||Java AWT and JFC Components||279|
|What Is on the Exam?||280|
|An Overview of Java Graphical Interfaces||280|
|The Java AWT Packages||282|
|The Component Class||283|
|The Container Class||287|
|Graphics-Related Classes in the AWT||297|
|Event-Related Classes in the AWT||303|
|User Interfaces with Swing Classes||304|
|A Summary of User Controls with AWT and Swing||311|
|Chapter 10||Building GUI Applications with Layout Managers||329|
|The Layout Manager Concept||330|
|Chapter 11||Java Event Handling||361|
|A Brief History of Java Event Handling||362|
|The Event Hierarchy||364|
|Coordinating Events with Actions||375|
|Chapter 12||Java Graphics||399|
|Introduction to Graphics||400|
|The Graphics Class||400|
|The Graphics2D Class||410|
|Working with Images||414|
|Chapter 13||Java I/O||431|
|Dealing with IOException||432|
|How Java Treats Files||432|
|Filtering Input Streams||443|
|Readers and Writers||445|
|JAR and Zip Files||450|
|Networks, Sockets, TCP/IP, and Datagrams||451|
|Talking to Serial and Parallel Ports||454|
|Chapter 14||Advanced Java Topics||467|
|The Big Picture||468|
|Java 2 Micro Edition||469|
|Java 2 Standard Edition||472|
|Java 2 Enterprise Edition||474|
|Chapter 15||Sample Test||485|
|Chapter 16||Answer Key||523|
|Appendix A||Answers to Review Questions||535|
|Appendix B||Objectives for Exam 310-025||555|
|Appendix C||Study Resources||557|
|Appendix D||Java Programming and Debugging Hints||561|