Java Examples in a Nutshell (In a Nutshell (O'Reilly)) and over one million other books are available for Amazon Kindle. Learn more

Vous voulez voir cette page en français ? Cliquez ici.

Sign in to turn on 1-Click ordering.
More Buying Choices
Have one to sell? Sell yours here
Start reading Java Examples in a Nutshell (In a Nutshell (O'Reilly)) on your Kindle in under a minute.

Don't have a Kindle? Get your Kindle here, or download a FREE Kindle Reading App.

Java Examples in a Nutshell [Paperback]

David Flanagan
4.5 out of 5 stars  See all reviews (19 customer reviews)
List Price: CDN$ 57.95
Price: CDN$ 26.30 & FREE Shipping. Details
You Save: CDN$ 31.65 (55%)
o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o
Usually ships within 3 to 5 weeks.
Ships from and sold by Gift-wrap available.
‹  Return to Product Overview

Product Description

From Amazon

David Flanagan looks to be trying to corner the market in Java titles. Java Examples in a Nutshell is his fourth and is designed to be read in conjunction with the earlier books in which he says, it proved impossible to include all the example code he would have liked.

Like all good coding books it starts with "Hello world", used in this case to illustrate how to correctly set up your Java environment. After a few more basic examples there is a set of exercises which test your grasp of the material. From then on Flanagan tends to refer you to other books in the series to provide background and reference material relevant to the examples under discussion--a great marketing tool. In practice, any basic Java reference will provide this information. What they won't do is provide so many or such well thought out code examples for you to play with.

After the first few chapters you will be glad all the code is available for download as the examples become longer and more complex with ever less text between them. The simple Web browser example alone goes on for many pages.

Despite starting at the absolute beginning Java Examples In A Nutshell goes to the limits with sections on using RMI, JDBC, XML, servlets, JSP and lots more. It covers GUI programming, sound, encryption, internationalisation and other technologies essential for creating practical programs--all with exercises to ensure you really do understand.

While Java code is available from many Net sites the combination of organisation, examples and exercises make this a massively useful book for any budding or working Java programmer. --Steve Patient --This text refers to an out of print or unavailable edition of this title.


"This essential, learn-as-you-go tutorial invites new and seasoned Java developers to let go of worries about the complexity and sophistication of Java and simply jump in and try effective new programming techniques and code. It's a very good place to start if you're thinking of trying something new." Industrial Networking & Open Contol, April 2004 "This is not, perhaps, for the gnarled old 'sandals and beard' developer at the back of the office, but if you're a junior developer, or perhaps a highly experienced developer moving into Java for the first time, you won't find much better reading, and doing, than this." - Davey Winder, PC Plus, Nov (Rating 9/10)

From the Publisher

Java Examples in a Nutshell is full of real-world example programs that not only serve as great learning tools, but can also be modified for individual use. The second edition covers Java 1.3, and contains 164 complete, practical programs: over 17,900 lines of densely commented, professionally written Java code covering 20 distinct Java API's, including Servlets, JavaServer Pages, XML, Swing, and Java 2D. --This text refers to an out of print or unavailable edition of this title.

About the Author

David Flanagan is a computer programmer who spends most of his time writing about JavaScript and Java. His books with O'Reilly include Java in a Nutshell, Java Examples in a Nutshell, Java Foundation Classes in a Nutshell, JavaScript: The Definitive Guide, and JavaScript Pocket Reference. David has a degree in computer science and engineering from the Massachusetts Institute of Technology. He lives with his wife and son in the U.S. Pacific Northwest bewteen the cities of Seattle, Washington and Vancouver, British Columbia. David has a simple website at

Excerpt. © Reprinted by permission. All rights reserved.

Chapter 19 - XML
Parsing with JAXP and SAX 1
Parsing with SAX 2
Parsing and Manipulating with JAXP and DOM
Traversing a DOM Tree
Traversing a Document with DOM Level 2
XML, or Extensible Markup Language, is a meta-language for marking up text documents with structural tags, similar to those found in HTML and SGML documents. XML has become popular because its structural markup allows documents to describe their own format and contents. XML enables "portable data," and it can be quite powerful when combined with the "portable code" enabled by Java.
Because of the popularity of XML, there are a number of tools for parsing and manipulating XML documents. And because XML documents are becoming more and more common, it is worth your time to learn how to use some of those tools to work with XML. The examples in this chapter introduce you to simple XML parsing and manipulation. If you are familiar with the basic structure of an XML file, you should have no problem understanding them. Note that there are many subtleties to working with XML; this chapter doesn't attempt to explain them all. To learn more about XML, try Java and XML, by Brett McLaughlin, or XML Pocket Reference, by Robert Eckstein, both from O'Reilly & Associates.
The world of XML and its affiliated technologies is moving so fast that it can be hard just keeping up with the acronyms, standards, APIs, and version numbers. I'll try to provide an overview of the state of various technologies in this chapter, but be warned that things may have changed, sometimes radically, by the time you read this material.
Parsing with JAXP and SAX 1
The first thing you want to do with an XML document is parse it. There are two commonly used approaches to XML parsing: they go by the acronyms SAX and DOM. We'll begin with SAX parsing; DOM parsing is covered later in the chapter. At the very end of the chapter, we'll also see a new, but very promising, Java-centric XML API known as JDOM.
SAX is the Simple API for XML. SAX is not a parser, but rather a Java API that describes how a parser operates. When parsing an XML document using the SAX API, you define a class that implements various "event" handling methods. As the parser encounters the various element types of the XML document, it invokes the corresponding event handler methods you've defined. Your methods take whatever actions are required to accomplish the desired task. In the SAX model, the parser converts an XML document into a sequence of Java method calls. The parser doesn't build a parse tree of any kind (although your methods can do this, if you want). SAX parsing is typically quite efficient and is therefore your best choice for most simple XML processing tasks.The Java implementation of the API is in the package org.xml.sax and its subpackages. SAX is a defacto standard but has not been standardized by any official body. SAX Version 1 has been in use for some time; SAX 2 was finalized in May 2000. There are numerous changes between the SAX 1 and SAX 2 APIs. Many Java-based XML parsers exist that conform to the SAX 1 or SAX 2 APIs.
With the SAX API, you can't completely abstract away the details of the XML parser implementation you are using: at a minimum, your code must supply the classname of the parser to be used. This is where JAXP comes in. JAXP is the Java API for XML Parsing. It is an "optional package" defined by Sun that consists of the javax.xml.parsers package. JAXP provides a thin layer on top of SAX (and on top of DOM, as we'll see) and standardizes an API for obtaining and using SAX (and DOM) parser objects. The JAXP package ships with default parser implementations but allows other parsers to be easily plugged in and configured using system properties. At this writing, the current version of JAXP is 1.0.1; it supports SAX 1, but not SAX 2. By the time you read this, however, JAXP 1.1, which will include support for SAX 2, may have become available.
Example 19.1 is a listing of, a program that uses JAXP and SAX to parse a web application deployment descriptor and list the names of the servlets configured by that file. If you haven't yet read Chapter 18, Servlets and JSP, you should know that servlet-based web applications are configured using an XML file named web.xml. This file contains tags that define mappings between servlet names and the Java classes that implement them. To help you understand the task to be solved by the program, here is an excerpt from the web.xml file developed in Chapter 18:










com.davidflanagan.examples.servlet.Logout --This text refers to an out of print or unavailable edition of this title.

‹  Return to Product Overview