Buy this Book
Print Book $34.99 PDF $23.99 Read it Now!
Print Book £24.99
Add to UK Cart
Reprint Licensing
Java Generics and Collections

By Maurice Naftalin, Philip Wadler
First Edition  October 2006 
Pages: 294
ISBN 10: 0-596-52775-6 | ISBN 13: 9780596527754
starstarstarstarstar (Average of 3 Customer Reviews)

Buy 2 Get 1 Free Free ShippingGuarantee

Book description

Java Generics and Collections covers everything from the most basic uses of generics to the strangest corner cases. It teaches you everything you need to know about the collections libraries, so you'll always know which collection is appropriate for any given task, and how to use it.
Full Description

This comprehensive guide shows you how to master the most important changes to Java since it was first released. Generics and the greatly expanded collection libraries have tremendously increased the power of Java 5 and Java 6. But they have also confused many developers who haven't known how to take advantage of these new features.

Java Generics and Collections covers everything from the most basic uses of generics to the strangest corner cases. It teaches you everything you need to know about the collections libraries, so you'll always know which collection is appropriate for any given task, and how to use it.

Topics covered include:

  • Fundamentals of generics: type parameters and generic methods
  • Other new features: boxing and unboxing, foreach loops, varargs
  • Subtyping and wildcards
  • Evolution not revolution: generic libraries with legacy clients and generic clients with legacy libraries
  • Generics and reflection
  • Design patterns for generics
  • Sets, Queues, Lists, Maps, and their implementations
  • Concurrent programming and thread safety with collections
  • Performance implications of different collections

Generics and the new collection libraries they inspired take Java to a new level. If you want to take your software development practice to a new level, this book is essential reading.

Philip Wadler is Professor of Theoretical Computer Science at the University of Edinburgh, where his research focuses on the design of programming languages. He is a co-designer of GJ, work that became the basis for generics in Sun's Java 5.0.

Maurice Naftalin is Technical Director at Morningside Light Ltd., a software consultancy in the United Kingdom. He has most recently served as an architect and mentor at NSB Retail Systems plc, and as the leader of the client development team of a major UK government social service system.

"A brilliant exposition of generics. By far the best book on the topic, it provides a crystal clear tutorial that starts with the basics and ends leaving the reader with a deep understanding of both the use and design of generics."
Gilad Bracha, Java Generics Lead, Sun Microsystems

Browse within this book

Cover | Table of Contents | Colophon



Featured customer reviews

Write a Review


Finally, A Book Devoted To Generics And Collections,  August 12 2007
Rating: StarStarStarStarStar
Submitted by Dave Walz-Burkett   [Respond | View]

Ever since the release of Java 5, I've been keeping my eyes open for a book that describes what I believe to be the most powerful new feature of Java - generics. The new book published by O'Reilly, Java Generics and Collections covers the topic in spades. As a bonus, the second half of this book examines the Java Collections Framework. Since the Collections Framework was rewritten to incorporate the use of generics, it makes perfect sense for the authors to spend a reasonable amount of time describing the new interfaces.

A brief introduction highlights the use of generics, autoboxing, foreach loops, generic methods and varargs. The examples are written using the Collections Framework. Subtyping and the use of wildcards follow the introduction and begin to show the real power of generics.

Getting past the basics, a chapter devoted to the Comparable and Comparator interfaces describes some very useful concepts, such as how to use the Comparable interface to find the minimum or maximum element in a collection. The use of enumerated types is briefly covered here, as well as the concepts of multiple bounds, bridges and covariant overriding.

A chapter describing how to declare a generic class helps you build your own classes. Following that is a useful chapter that describes how the design of generics is evolutionary, not revolutionary. It details how generics in Java 5 allow you to gradually migrate your legacy code, rather than replace it all at once.

If you use generic types in casts, instance testing, exceptions or arrays, a chapter on reification warns you of rough edges and limitations you may find and describes some workarounds. How generics changes reflection is also covered.

The last two chapters of the first half of the book describe how to use generics effectively in your code and provide samples of how implementations of select design patterns can take advantage of generics.

The second half of the book, which dives into the Collections Framework, starts with a quick chapter called 'Preliminaries' that spends time discussing underlying concepts, such as the Iterable interface. Thread safety issues are covered in this chapter as well. Thread-safe concurrent collections were introduced in Java 5 and their use, as compared with synchronized collections is also discussed.

The Collection interface is given its own chapter, which is important considering that it defines functionality common to any type of collection other than maps. Following are chapters describing sets, queues and lists. The Map interface also warrants its own chapter, in which the available methods and the various map implementations are discussed. The comparative performance of different set, queue, list and map implementations is shown in tables at the end of each chapter.

Following the Collection and Map interface chapters is the final chapter which describes the Collections class in detail. The Collections class contains static methods that operate on collections or return them.

I found the code and diagrams in this book very easy to understand and a great resource when trying to decide which collection or map implementation to use for a specific problem.

Once you learn how to take advantage of generics, you'll begin to write more useful, reusable code. This book now occupies a space on my shelf next to my Algorithms and Data Structures books.


Egyptian JUG Review,  February 16 2007
Rating: StarStarStarStarStar
Submitted by Ahmed Hashim   [Respond | View]

Reviewd By Islam Mahgoub (http://www.egjug.org/user/771)

In the past, I wondered a lot about Java Generics, and how
could I use it, how it’s implemented in Java, what goes behind the scenes, How
could I evolve my code to use Java Generics, what about the differences between
Java Generics and C++ templates, what does the phrase “Java generics are
defined by erasure” mean… and a lot of other questions concerning Java recently
added features to support generics.

This book was recommended to me by a friend, really it’s a
great recommendation, I have found answers to the most of my questions concerning
Java Generics and Collection framework.



At the end, I think this book is suitable for both, a Java
developer who know nothing about Java Generics and Collection and wants to
start his journey with Java Generics and Collection framework, and also a Java
expert who already has a good knowledge about Java Generics and Collection
framework, but wants a more deep understanding of this topic, and wants to know
how to use this feature in a professional way, and what goes behind the scenes.




Read the complete review. (At the end, I think this book is suitable for both, a Java
developer who know nothing about Java Generics and Collection and wants to
start his journey with Java Generics and Collection framework, and also a Java
expert who already has a good knowledge about Java Generics and Collection
framework, but wants a more deep understanding of this topic, and wants to know
how to use this feature in a professional way, and what goes behind the scenes.
)


Greenvile Java Users Group - Moderator,  February 01 2007
Rating: StarStarStarStarStar
Submitted by John Yeary   [Respond | View]

The Java Generics book provides an in-depth analysis of the new Generics and Collections APIs in Java 5 and 6. The book provides a level of detail on this new technology that can not be found elsewhere. This book is generally not for a novice programmer due to the level of architectural details and theory. It provides a seasoned programmer with a comprehensive examination of why and how the Generics and Collections APIs were modified, as well as, the design decisions and impact. The book provides the programmer with the information they need to make informed decisions on which type of Collection to use, and the associated pitfalls based on design decisions.



The only issue I found with the book was that it did not provide enough concrete examples. The code was provided generally in code snippets which do not provide enough detail.



The book is a definite choice for the advanced Java programmer and architect. If you are serious about learning these new technologies: this is the book to get.



Read all reviews


Media reviews

"This book is a real gem. Wonderfully written and well illustrated with meaningful (although quite terse) examples, it's a delightful read. Java programmers wishing to utilize the full power of Generics and the additions/modifications to the Collection framework should read this book. Though the new language features introduced by Java 5 are quite complex and vast and almost impossible to cover within a single book, this 254 page book takes a crack at attempting the impossible. Go out and grab a copy!!"
-- Aditya Gore, JavaLobby

"Given the history of Generic Java, Naftalin and Wadler's Java Generics and Collections has a distinguished pedigree. In this review I'll argue that this is a new classic...If you're new to generics, and you don't mind thinking, I recommend this book. If you're a Java programmer who's a bit confused by then this is the book for you. The only people who shouldn't read this are people new to Java. You need to go elsewhere first. This is not a book for complete beginners. This is a great book in the classic—practical, concise and intelligent—O'Reilly mould. "
-- Andrew Cooke, Slashdot.org

"A brilliant exposition of generics. By far the best book on the topic, it provides a crystal-clear tutorial that starts with the basics and ends leaving the reader with a deep understanding of both the use and design of generics."
-- Gilad Bracha, Java Generics Lead, Sun Microsystems

Read all reviews


See larger cover


"...a crystal-clear tutorial that starts with the basics and ends leaving the reader with a deep understanding of both the use and design of generics."
--Gilad Bracha, Java Generics Lead, Sun Microsystems