Java in a Nutshell: A Desktop Quick Reference

Overview

This bestselling quick reference contains an accelerated introduction to the Java language and its key APIs, so seasoned programmers can start writing Java code right away. The third edition of Java in a Nutshell covers Java 1.2 and Java 1.3 beta and includes:

  • A description of the syntax of the Java language, written in a tight, concise style, that can serve as both a fast-paced tutorial and a language ...
See more details below
Available through our Marketplace sellers.
Other sellers (Paperback)
  • All (77) from $1.99   
  • New (4) from $5.00   
  • Used (73) from $1.99   
Close
Sort by
Page 1 of 1
Showing All
Note: Marketplace items are not eligible for any BN.com coupons and promotions
$5.00
Seller since 2014

Feedback rating:

(4)

Condition:

New — never opened or used in original packaging.

Like New — packaging may have been opened. A "Like New" item is suitable to give as a gift.

Very Good — may have minor signs of wear on packaging but item works perfectly and has no damage.

Good — item is in good condition but packaging may have signs of shelf wear/aging or torn packaging. All specific defects should be noted in the Comments section associated with each item.

Acceptable — item is in working order but may show signs of wear such as scratches or torn packaging. All specific defects should be noted in the Comments section associated with each item.

Used — An item that has been opened and may show signs of wear. All specific defects should be noted in the Comments section associated with each item.

Refurbished — A used item that has been renewed or updated and verified to be in proper working condition. Not necessarily completed by the original manufacturer.

New
have a blessed day

Ships from: santa cruz, CA

Usually ships in 1-2 business days

  • Canadian
  • International
  • Standard, 48 States
  • Standard (AK, HI)
  • Express, 48 States
  • Express (AK, HI)
$7.92
Seller since 2008

Feedback rating:

(169)

Condition: New
1565924878 BRAND NEW NEVER USED IN STOCK 125,000+ HAPPY CUSTOMERS SHIP EVERY DAY WITH FREE TRACKING NUMBER

Ships from: fallbrook, CA

Usually ships in 1-2 business days

  • Standard, 48 States
  • Standard (AK, HI)
$21.39
Seller since 2009

Feedback rating:

(847)

Condition: New
1565924878 *BRAND NEW* Ships Same Day or Next!

Ships from: Springfield, VA

Usually ships in 1-2 business days

  • Canadian
  • International
  • Standard, 48 States
  • Standard (AK, HI)
  • Express, 48 States
  • Express (AK, HI)
$45.00
Seller since 2014

Feedback rating:

(136)

Condition: New
Brand new.

Ships from: acton, MA

Usually ships in 1-2 business days

  • Standard, 48 States
  • Standard (AK, HI)
Page 1 of 1
Showing All
Close
Sort by
Sending request ...

Overview

This bestselling quick reference contains an accelerated introduction to the Java language and its key APIs, so seasoned programmers can start writing Java code right away. The third edition of Java in a Nutshell covers Java 1.2 and Java 1.3 beta and includes:

  • A description of the syntax of the Java language, written in a tight, concise style, that can serve as both a fast-paced tutorial and a language reference.
  • An explanation of the object-oriented features of Java that does not assume any prior object-oriented programming experience.
  • An overview of the essential Java APIs that shows how to perform common tasks, such as string manipulation, input/output, and thread handling, with the classes and interfaces that comprise the Java 2 platform.
  • Documentation for the Java development tools shipped with Sun's Java SDK.

This book also includes O'Reilly's classic-style, quick-reference material for all of the classes in the essential Java packages, including java.lang, java.io, java.beans
java.math, java.net, java.security,
java.text, java.util, and javax.crypto. This reference material covers all of the new classes in Java 1.2 and 1.3. Once you've learned Java, you'll keep this book next to your keyboard for handy reference while you program.

This book is part of the two-volume set of quick references that every Java programmer needs. It is an essential companion to Java Foundation Classes in a Nutshell, which covers the graphics and graphical user interface APIs in the Java 2 platform, including Swing, AWT, and Java 2D. A third volume, Java Enterprise in a Nutshell, focuses on the Java Enterprise APIs and is of interest to programmers working on server-side or enterprise Java applications.

Read More Show Less

Product Details

  • ISBN-13: 9781565924871
  • Publisher: O'Reilly Media, Incorporated
  • Publication date: 11/30/1999
  • Series: In a Nutshell (O'Reilly) Series
  • Edition description: Third Edition
  • Edition number: 3
  • Pages: 666
  • Product dimensions: 6.04 (w) x 9.00 (h) x 1.21 (d)

Meet 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 http://www.davidflanagan.com.

Read More Show Less

Read an Excerpt

Chapter 4: The Java Platform

4.7 Types, Reflection, and Dynamic Loading

The java.lang.Class class represents data types in Java and, along with the classes in the java.lang.reflect package, gives Java programs the capability of introspection (or self-reflection); a Java class can look at itself, or any other class, and determine its superclass, what methods it defines, and so on. There are several ways you can obtain a Class object in Java:

// Obtain the Class of an arbitrary object o Class c = o.getClass(); 
// Obtain a Class object for primitive types with various predefined 
constants c = Void.TYPE;          
// The special "no-return-value" type c = Byte.TYPE;          
// Class object that represents a byte c = Integer.TYPE;      
 // Class object that represents an int c = Double.TYPE;      
   // etc.  See also Short, Character, Long, Float. 
   // Express a class literal as a type name followed by ".class" c = int.class;          
// Same as Integer.TYPE c = String.class;      
 // Same as "dummystring".getClass() c = byte[].class;     
   // Type of byte arrays c = Class[][].class;   
    // Type of array of arrays of Class objects

Once you have a Class object, you can perform some interesting reflective operations with it:

import java.lang.reflect.*; Object o;                  
 // Some unknown object to investigate Class c = o.getClass();    
  // Get its type 
  // If it is an array, figure out its base type while (c.isArray()) c =
   c.getComponentType(); 
// If c is not a primitive type, print its class hierarchy if (!c.isPrimitive())
 {  for(Class s = c; s != null; s = s.getSuperclass()) 
// Try to create a new instance of c; 
this requires a no-arg constructor Object newobj = null;try { newobj =
 c.newInstance(); }catch (Exception e) { 
   // Handle InstantiationException, IllegalAccessException}
    // See if the class has a method named setText that takes a single String 
        // If so, call it with a string argumenttry {   Method m =
         c.getMethod("setText", new Class[] { String.class });  
          m.invoke(newobj, new Object[] { "My Label" }); } catch(Exception
           e) { /* Handle exceptions here */ }

Class also provides a simple mechanism for dynamic class loading in Java. For more complete control over dynamic class loading, however, you should use a java.lang.ClassLoader object, typically a java.net.URLClassLoader. This technique is useful, for example, when you want to load a class that is named in a configuration file, instead of being hardcoded into your program:

// Dynamically load a class specified by name in a config file String classname = 
                    // Look up the name of the class   config.getProperties("filterclass",  
// The property name try {  Class c = Class.forName(classname); 
 // Dynamically load the class   Object o = c.newInstance();       
    // Dynamically instantiate it } catch (Exception e) { /* Handle exceptions */        } 
// If the class to be loaded is not in the classpath, create a custom 
         // class loader to load it.
          // Use the config file again to specify the custom path import java.net.URLClassLoader; 
String classdir = config.getProperties("classpath");
try {   ClassLoader loader = new URLClassLoader(new URL[] { new URL(classdir) });
   Class c = loader.loadClass(classname);} catch (Exception e) { /* Handle exceptions */ }

4.8 Threads

java makes it easy to define and work with multiple threads of execution within a program. java.lang.Thread is the fundamental thread class in the Java API. There are two ways to define a thread. One is to subclass Thread, override the run() method, and then instantiate your Thread subclass. The other is to define a class that implements the Runnable method (i.e., define a run() method) and then pass an instance of this Runnable object to the Thread() constructor. In either case, the result is a Thread object, where the run() method is the body of the thread. When you call the start() method of the Thread object, the interpreter creates a new thread to execute the run() method. This new thread continues to run until the run() method exits, at which point it ceases to exist. Meanwhile, the original thread continues running itself, starting with the statement following the start() method. The following code demonstrates:

final List list;  
// Some long unsorted list of objects; initialized elsewhere
 /** A Thread class for sorting a List in the background 
 */ class BackgroundSorter extends Thread {  List l;   public
  BackgroundSorter(List l) { this.l = l; }    
  // Constructor   public void run() { Collections.sort(l); }         
  // Thread body} 
  // Create a BackgroundSorter thread Thread sorter = new
   BackgroundSorter(list); 
   // Start it running; the new thread runs the run() method above, while
    // the original thread continues with whatever statement comes next.
         sorter.start();  
         // Here's another way to define a similar thread Thread t = new Thread(new Runnable() {         
 // Create a new thread   public void run() { Collections.sort(list); }
  // to sort the list of objects. });t.start();  
                                      // Start it running

Threads can run at different priority levels. A thread at a given priority level does not run unless there are no higher-priority threads waiting to run. Here is some code you can use when working with thread priorities:

// Set a thread t to lower-than-normal priority
 t.setPriority(Thread.NORM_PRIORITY-1); 
// Set a thread to lower priority than the current thread
 t.setPriority(Thread.currentThread().getPriority() - 1);
  // Threads that don't pause for I/O should explicitly yield the CPU 
  // to give other threads with the same priority a chance to run. 
  Thread t = new Thread(new Runnable() {  public void run() {

Often, threads are used to perform some kind of repetitive task at a fixed interval. This is particularly true when doing graphical programming that involves animation or similar effects:

public class Clock extends Thread {   java.text.DateFormat f =      
// How to format the time for this locale   boolean keepRunning = true; 
 public Clock() {        
  // The constructor   public void run() {      
  // The body of the thread  
   public void pleaseStop() { keepRunning = false; }}

Notice the pleaseStop() method in the previous example. You can forcefully terminate a thread by calling its stop() method, but this method has been deprecated because a thread that is forcefully stopped can leave objects it is manipulating in an inconsistent state. If you need a thread that can be stopped, you should define a method such as pleaseStop() that stops the thread in a controlled way.

In Java 1.3, the java.util.Timer and java.util.TimerTask classes make it even easier to run repetitive tasks. Here is some code that behaves much like the previous Clock class:

import java.util.*; 
// How to format the time for this locale final java.text.DateFormat timeFmt = 
  java.text.DateFormat.getTimeInstance(java.text.DateFormat.MEDIUM); 
  // Define the time display taskTimerTask displayTime = new TimerTask() {  
   public void run() { System.out.println(timeFmt.format(new Date())); }};
    // Create a timer object to run the task (and possibly others) Timer timer =
         new Timer(); 
         // Now schedule that task to be run every 1000 milliseconds, starting now
          Timer.schedule(displayTime, 0, 1000);
          // To stop the time display task displayTime.cancel();

Sometimes one thread needs to stop and wait for another thread to complete. You can accomplish this with the join() method:

List list; 
 // A long list of objects to be sorted; initialized elsewhere 
 // Define a thread to sort the list: lower its priority, so it only runs 
 // when the current thread is waiting for I/O and then start it running. 
 Thread sorter = new BackgroundSorter(list);               
 // Defined earlier sorter.setPriority(Thread.currentThread.getPriority()-1); 
 // Lower priority sorter.start();                                         
   // Start sorting 
   // Meanwhile, in this original thread, read data from a file byte[] data =
    readData();  
// Method defined elsewhere
 // Before we can proceed, we need the list to be fully sorted, so 
 // we've got to wait for the sorter thread to exit, if it hasn't
  already. sorter.join();

When using multiple threads, you must be very careful if you allow more than one thread to access the same data structure. Consider what would happen if one thread was trying to loop through the elements of a List while another thread was sorting those elements. Preventing this problem is called thread synchronization and is one of the central problems of multithreaded computing. The basic technique for preventing two threads from accessing the same object at the same time is to require a thread to obtain a lock on the object before the thread can modify it. While any one thread holds the lock, another thread that requests the lock has to wait until the first thread is done and releases the lock. Every Java object has the fundamental ability to provide such a locking capability.

The easiest way to keep objects thread-safe is to declare any sensitive methods synchronized. A thread must obtain a lock on an object before it can execute any of its synchronized methods, which means that no other thread can execute any other synchronized method at the same time. (If a static method is declared synchronized, the thread must obtain a lock on the class, and this works in the same manner.) To do finer-grained locking, you can specify synchronized blocks of code that hold a lock on a specified object for a short time.....

Read More Show Less

Table of Contents

Preface;
Who Should Read This Book;
How to Use This Book;
Conventions Used in This Book;
Using Code Examples;
Safari® Books Online;
How to Contact Us;
Acknowledgments;
Chapter 1: Introduction: Why ClojureScript?;
1.1 The Rise of Browser Applications;
1.2 The Rise of JavaScript;
1.3 The Need for a Better Language;
1.4 Introducing ClojureScript;
Chapter 2: Hello World;
2.1 Leiningen;
2.2 Using lein-cljsbuild;
Chapter 3: The Compilation Process;
3.1 Architecture;
3.2 How to Compile;
3.3 Compilation in Depth;
3.4 Summary;
Chapter 4: ClojureScript Basics;
4.1 ClojureScript versus Clojure;
4.2 Expressions and Side Effects;
4.3 Syntax and Data Structures;
4.4 Special Forms and Definitions;
4.5 Functions;
4.6 Local Bindings;
4.7 Closures;
4.8 Flow Control;
4.9 JavaScript Interop;
4.10 Summary;
Chapter 5: Data and State;
5.1 Primitives;
5.2 Data Structures;
5.3 Identity and State;
Chapter 6: Sequences;
6.1 The Sequence Abstraction;
6.2 Lazy Sequences;
6.3 The Sequence API;
Chapter 7: Namespaces, Libraries, and Google Closure;
7.1 Namespaces;
7.2 Advanced Compilation Mode;
7.3 Consuming Libraries;
7.4 Creating Libraries;
Chapter 8: Macros;
8.1 Code as Data;
8.2 Writing Macros;
8.3 Using Macros;
8.4 When to Write Macros;
8.5 Summary;
Chapter 9: Development Process and Workflow;
9.1 Installing ClojureScript;
9.2 The Built-In Tools;
9.3 The Browser REPL;
9.4 Additional lein-cljsbuild Features;
Chapter 10: Integration with Clojure;
10.1 AJAX;
10.2 The Reader and Printer;
10.3 Example Client-Server Application;
10.4 Extending the Reader;
10.5 Sharing Code;
10.6 Summary;
Libraries;
ClojureScript’s Standard Library;
Google Closure Library;
Domina;
Enfocus;
Jayq;
C2;
core.logic;

Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star

(0)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing all of 6 Customer Reviews
  • Anonymous

    Posted December 8, 2001

    Good, concise reference

    This is an excellent reference if you are an experienced programmer and want a single reference that you can rely on. The author succeds in covering all the really important features with just enough detail so that you can get a working understanding of them.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted October 16, 2001

    Not too happy...

    I like the way its layed out. But the only thing that troubles me that the explantions were too technical. I'm experianced in C++ and BASIC and a little bit of COBOL. But I when I learned those languages I had references that explained things as if you were new to the language like I am new to JAVA.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted October 31, 2000

    A reference, not a learning tool

    This is not a tutorial, but a language reference. I like the breakdown of the information, and the way the side 'tabs' of the book make the sections easy distinguish. Once you catch on to the layout of the book, you can find things very very fast. I also like the fact that the authors have taken the time to point out deprecated classes/methods and point the reader to those when applicable. This saved me a LOT of aggravation when working with existing code.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted September 26, 2000

    Good, but lacking content from earlier editions

    <i>Java in a Nutshell, 3rd Edition</i>, is the sequel to the highly successful series of books by author David Flanagan. His books have been both a handy reference when programming, and a quick-start guide to learning the Java language. Unlike other authors, when David releases a new edition, it is very much a complete rewrite, rather than just adding a chapter here and there. </p> <p>This is, however, a double-edged sword. It means that you can pick up the latest edition, and still find it useful if you've read previous ones. However, to conserve space, the book becomes more and more compact, so some of the great sections like a comparison between C++ and Java from the first edition is reduced to a two page summary of bullet points.</p> <p><i>Java in a Nutshell, 3rd Edition</i> is, nonetheless, the best Java reference available on the market. It covers all the core Java technologies, save the Abstract Windowing Toolkit and Swing graphical libraries, which have been relegated to the new book <i>Java Foundation Classes in a Nutshell.</i> This will be a disappointment to some, but if you're looking for a language reference, and not a guide to GUI programming, this title is an excellent buy. Particularly if you're new to the Nutshell series, David Flanagan's fast paced guide to Java is a perfect desktop reference <i>-- David Reilly</i>

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted June 10, 2000

    Useless

    Outdated, shallow and useless.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted March 3, 2000

    Great Reference Book

    As in the previous edition, the tutorial part of the book remains a terse introduction to the language. The older editions assumed you knew C or C++. This edition just assumes that you have some programming experience. If a person who does not have programming experience picks up this book, the explanation is too terse to learn programming as well as Java. Even I who learned Java back in the 1.0beta days, use the tutorial section of this book. I can never seem to remember all the different types of inner classes and their syntax. When I needed to know, I've pulled out the previous edition of this book. I was happy to see that the inner class description used in the previous edition was carried forward to this one. The second half of the remains as before. It is a compact reference of the Java API. This part of the book is not really useful for learning the APIs, but it is useful for remembering the syntax of the various method calls and being able to look them up quickly. If you have to limit yourself to one Java book, 'Java in a Nutshell' would be an excellent choice. This is doubly true if you are a consultant, travel around quite a bit, and need something light, but extremely useful.

    Was this review helpful? Yes  No   Report this review
Sort by: Showing all of 6 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)