Head First Java, Second Edition

Head First Java

Head First Java delivers a highly interactive, multisensory learning experience that lets new programmers pick up the fundamentals of the Java language quickly. Through mind-stretching exercises, memorable analogies, humorous pictures, and casual language, Head First Java encourages readers to think like a Java programmer. This revised second edition focuses on Java 5.0, the latest version of the Java development platform.

Head First Java combines puzzles, strong visuals, mysteries, and soul-searching interviews with famous Java objects to engage you in many different ways. It's fast, it's fun, and it's effective. And, despite its playful appearance, Head First Java is serious stuff: a complete introduction to object-oriented programming and Java. You'll learn everything from the fundamentals to advanced topics, including threads, network sockets, and distributed programming with RMI. And the new. second edition focuses on Java 5.0, the latest version of the Java language and development platform. Because Java 5.0 is a major update to the platform, with deep, code-level changes, even more careful study and implementation is required. So learning the Head First way is more important than ever.

By exploiting how your brain works, Head First Java compresses the time it takes to learn and retain complex information. Its unique approach not only shows you what you need to know about Java syntax, it teaches you to think like a Java programmer. If you want to be bored, buy some other book. But if you want to understand Java, this book's for you.

A collection of images from inside the book.

What you need for this book

You do not need any other development tool, such as an Integrated Development Environment (IDE). We strongly recommend that you not use anything but a basic text editor until you complete this book (and especially not until after chapter 16). An IDE can protect you from some of the details that really matter, so you're much better off learning from the command-line and then, once you really understand what's happening, move to a tool that automates some of the process.

Setting up Java

  • If you don't already have a 1.5 or greater Java 2 Standard Edition SDK (Software Development Kit), you need it. If you're on Linux, Windows, or Solaris, you can get it for free from java.sun.com (Sun's website for Java developers). It usually takes no more than two clicks from the main page to get to the J2SE downloads page. Get the latest non-beta version posted. The SDK includes everything you need to compile and run Java.
    If you're running Mac OS X 10.4, the Java SDK is already installed. It's part of OS X, and you don't have to do anything else. If you're on an earlier version of OS X, you have an earlier version of Java that will work for 95% of the code in this book.

    Note: This book is based on Java 1.5, but for stunningly unclear marketing reasons, shortly before release, Sun renamed it Java 5, while still keeping "1.5" as the version number for the developer's kit. So, if you see Java 1.5 or Java 5 or Java 5.0, or "Tiger" (version 5's original code-name), they all mean the same thing. There was never a Java 3.0 or 4.0—it jumped from version 1.4 to 5.0, but you will still find places where it's called 1.5 instead of 5. Don't ask. (Oh, and just to make it more entertaining, Java 5 and the Mac OS X 10.4 were both given the same code-name of "Tiger", and since OS X 10.4 is the version of the Mac OS you need to run Java 5, you'll hear people talk about "Tiger on Tiger". It just means Java 5 on OS X 10.4).

  • The SDK does not include the API documentation, and you need that! Go back to java.sun. com and get the J2SE API documentation. You can also access the API docs online, without downloading them, but that's a pain. Trust us, it's worth the download.

  • You need a text editor. Virtually any text editor will do (vi, emacs, pico), including the GUI ones that come with most operating systems. Notepad, Wordpad, TextEdit, etc. all work, as long as you make sure they don't append a ".txt" on to the end of your source code.

  • Once you've downloaded and unpacked/zipped/whatever (depends on which version and for which OS), you need to add an entry to your PATH environment variable that points to the /bin directory inside the main Java directory. For example, if the J2SDK puts a directory on your drive called "j2sdk1.5.0", look inside that directory and you'll find the "bin" directory where the Java binaries (the tools) live. Tha bin directory is the one you need a PATH to, so that when you type: % javac at the command-line, your terminal will know how to find the javac compiler.

    Note: if you have trouble with you installation, we recommend you go to javaranch.com, and join the Java-Beginning forum! Actually, you should do that whether you have trouble or not.

Last-minute things you need to know:

We use simple UML-like diagrams.

If we'd used pure UML, you'd be seeing something that looks like Java, but with syntax that's just plain wrong. So we use a simplified version of UML that doesn't confl ict with Java syntax. If you don't already know UML, you won't have to worry about learning Java and UML at the same time.

We don't worry about organizing and packaging your own code until the end of the book.

In this book, you can get on with the business of learning Java, without stressing over some of the organizational or administrative details of developing Java programs. You will, in the real world, need to know—and use—these details, so we cover them in depth. But we save them for the end of the book (chapter 17). Relax while you ease into Java, gently.

Code and Downloads

Get a zip file of all the code in the book here, or get it by chapter:
(opens a new window)

Read it on Safari

(opens a new window)

Buy 2 books, get 1 free!

Buy 2 books and get the third free! Use the coupon code OPC10 when you check out.

Who is this book for?

If you can answer "yes" to all of these:

  • Have you done some programming?
  • Do you want to learn Java?

  • Do you prefer stimulating dinner party conversation to dry, dull, academic lectures?

You should probably back away from this book if you can answer "yes" to any of these:

  • Is your programming background limited to HTML only, with no scripting language experience? (If you've done anything with looping, or if/then logic, you'll do fine with this book, but HTML tagging alone might not be enough.)
  • Are you a kick-butt C++ programmer looking for a reference book?
  • Are you afraid to try something different? Would you rather have a root canal than mix stripes with plaid? Do you believe than a technical book can't be serious if there's a picture of a duck in the memory management section?

Also by Kathy Sierra & Bert Bates

Head First Design Patterns

Head First Design Patterns

Head First Servlets & JSP

Head First Servlets & JSP