Head First Java
PLEASE NOTE: book files for Head First Java are maintained on this site, but the authors Kathy Sierra and Bert Bates do not frequent this site. Given that, please direct all comments and questions to the Head First Java Discussion Forum.
Learning a complex new language is no easy task especially when it s an object-oriented computer programming language like Java. You might think the problem is your brain. It seems to have a mind of its own, a mind that doesn’t always want to take in the dry, technical stuff you’re forced to study.
The fact is your brain craves novelty. It’s constantly searching, scanning, waiting for something unusual to happen. After all, that’s the way it was built to help you stay alive. It takes all the routine, ordinary, dull stuff and filters it to the background so it won’t interfere with your brain’s real work–recording things that matter. How does your brain know what matters? It’s like the creators of the Head First approach say, suppose you’re out for a hike and a tiger jumps in front of you, what happens in your brain? Neurons fire. Emotions crank up. Chemicals surge.
That’s how your brain knows.
And that’s how your brain will learn Java. 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.
If you’ve read a Head First book, you know what to expect–a visually rich format designed for the way your brain works. If you haven’t, you’re in for a treat. You’ll see why people say it’s unlike any other Java book you’ve ever read.
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.
Buy this book now on Amazon.com
51 comments on “Head First Java”
My first book on programming, bought while on the path to my Associate’s after falling in love with Java.
Fantastic resource that both gives you the knowledge needed to make good programs but sets you on a good path of practice. This is like a “just add water” kind of package as far as learning Java, only replace water with “Don’t stop practicing afterwards” and you’re set for success.
Thanks for the book!
I can’t find Java 2 standard edition sdk! HELP ME PLZ!
I can’t find Java 2 Standard Edition SDK! HELP I SPENT 50$ on this book! Can anyone HELP ME.
If you do email me at… mcflurry1059@gmail.com
C:Javabook exampleshfjavafinalsampleschap15>java SimpleChatClient
Exception in thread “main” java.lang.NoClassDefFoundError: SimpleChatClient (wro
ng name: chap15/SimpleChatClient)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
i cant get it to compile 🙁
Same problem – same error. Sample code won’t compile.
I just purchased the book and started reading. The book said some of the suggested answers for the ‘Sharpen your Pencil’ exercises are on this site, but I can’t locate them. Can someone point me to the right location.
thank you
Just got the book as well, what do I need to install before I can Run any of the above source codes? Using Win7 64-bit IE9
I recently installed JRE.
Please help!
you can find it here:
http://search.oracle.com/search/search?start=1&search_p_main_operator=all&q=JDK&group=Technology+Network
You will need the JDK from oracle, http://www.oracle.com/technetwork/java/javase/downloads/index.html
thanks Karl
This book got me started with the Head First series and I have not looked back. Conveniently, for what I have been looking to achieve, the series has proven itself invaluable. They have books for each of the topics that have been important to the tasks I have been provided – giving me the ability to learn quickly and the methods used for teaching have been fantastic. The part at the beginning of the books mentioning “how” they are going to teach you and “why” really helped me appreciate this book because that side of learning development is something else I have read a lot on. They had me from hello, so to speak.
I found myself picking up the JSP book (and will probably get the design patterns book) for no reason other than I know I will learn something new from them, and quickly.
This is not just a review for this book, but all of them really.
I must admit the HTML5 book is the only one that appeared to be a little rushed. A few typos here and there can be forgiven in what has been the best series of books I have come across for learning the topics covered.
Brilliant work guys and girls – anyone undecided on whether this is the book for them… if it’s Head First, you won’t go far wrong.
Jake, thanks for your comments. I’m curious: other than typos (which all the books have!), what about the HTML5 Programming book felt rushed?
Thanks!
I love this book and I’ll definetely check out other Head First books!
The code is in a package so go one directory above the *.class file and use the java command.
java chap01/BeerSong on UNIX
java chap01BeerSong on Windows I believe
Chapter 17 explains packages. Or just comment out the package label and recompile the code.
This answers the question below also.
See the above answer.
I’m running Ubuntu 10.04 and I’ve just purchased this book, it seems great ot me, but the very first example of code (page 33 in Russian version of the book ) compiles OK but doesn’t run with the following error:
Exception in thread “main” java.lang.NoSuchMethodError: main
Could you help me?
Thanks for your book!
hey java 7 is released..several months ago..so do u guys going to update ‘head first java ‘ with java 7 ?
public class practice {
public static void main (String[]args) {
int x= 1;
while(x<———–){
System.out.—————————-("Doo");
System.out.—————————-("Bee");
x=x+1;
}
if(x==————–){
System.out.println("Do");
}
}
}
me too, stuff on constructors is messing with me.
Hy everyone !
I’ve just started to learn java SE, and I don’t see any topics on the forum about this.
Where can I ask questions about java ?
just curious but will you be making new java books as the java gets updated?
I just bought the Head First Java book, 2nd Ed. (teaches Java 5.0), but I want to download the latest SE version of Java (Java SE 7). Will the code used in the book run if I use the latest version? Are Java 5.0 SE and Java 7 SE compatible? I will appreciate your help. Thanks.
while(x<3)
and
if(x==1)
would you please, elaborate on “page 79” about set and get on “class ElectricGuitar” example!
The head first java book said the sharpen you pencil answers would be on here…does anyone know where they are?
They might be in the code bundle? You can download that here: http://wickedlysmart.com/get-code/ That’s all we have from Kathy and Bert for Head First Java.
Hi Mike,
I know you said you didn’t want a response, but I hate to see a frustrated reader (as I’m sure Kathy and Bert do too).
Are you on a Mac or PC? If you’re on a mac, then likely you already have Java installed. Open a terminal window and type:
java -version
If you have Java you’ll see something like:
java version “1.6.0_37”
Java(TM) SE Runtime Environment (build 1.6.0_37-b06-434-11M3909)
Java HotSpot(TM) 64-Bit Server VM (build 20.12-b01-434, mixed mode)
and you should be good to go. You can access the API documentation online here:
http://docs.oracle.com/javase/6/docs/api/
No need to download them.
If you’re on windows, you’ll have to download Java. You can follow these instructions:
http://www.java.com/en/download/help/windows_manual_download.xml
Note that things change fairly frequently in the Windows world in particular with regards to Java, so that’s likely why the instructions in Kathy & Bert’s book might be somewhat out of date.
Hope this helps!
Elisabeth
p.s. I can’t speak to your problems with Javaranch, not sure what’s going on there!
Elisabeth,
Thanks for your message. This, however, does not answer my questions. (I truly believe that in order to learn ANY thing in computer science, you have to already KNOW it, because no one is able to explain simple concepts). I have to change my system PATH environment variable. (Windows 7)….Control Panel…System…Advanced System Settings…Environment Variables…. and then what??? I append some address, blah, blah, blah, to the PATH variable. EXACTLY WHAT ADDRESS???? How?? What’s the PATH variable? Sounds simple, hey? Well, I’ve done it four times and I can’t open ANY thing with the command window. . . and it’s now 12:33 a.m. and I’m sick to death of computers, Java, and people who cannot explain things to Where do I SAVE files?? I can’t find simple answers to simple questions, I’m juggling three different texts (including the Head’s Up book) and I can’t even log into a website where there MIGHT be an answer. So, heads-up . . . catch this . . . it’s my towel. I’m throwing it in. Nothing is worth this idiocy.
MD
Wow, I thought Elisabeth was very thoughtful with her response. No need to be rude. You’re sick to death of people who can’t hand-hold you through simple concepts? Sounds like you just don’t have the capability (based on the fact that you can’t write a grammatically correct sentence) to for computer science. So, heads-up — catch your own towel – no one cares.
Hello there…
I agree that was a rant, but he has a point about the path.
I’ve just started reading the book and I can’t work out what to add either. Do I edit the existing path variable (which seems to point to SQL Server), or add a new one? If a new one, can I just call that ‘path’ as well? Presumably the value for the new path variable is the full directory path to the java…/bin folder, including the ‘bin’?
Cheers, John
Hello there…
I’m having a similar problem (sorry!) I followed the link for the ‘download Java’ that you gave. Downloaded and installed, and got v confused. It turns out that link is to the JRE which is a runtime, not the SDK which has the compiler etc. Thought you’d like to know.
Cheers, John
Hi,
Ive been working through the book although I still cant find the answers to the exercises. Ive checked in the code bundle and they dont seem to be in there. Please help.
We’ve forwarded your comment to Bert & Kathy!
Is anyone having problems getting the guessgame (p39-40) code to run? I copied it out but keep getting the error ‘Error: Main method not found in class guessgame.GuessGame, please define the main method as:
public static void main(String[] args)
This error comes up on the Game launcher class, on the line ‘public static void main(String[] args)’. I don’t understand why I’m being told this line isn’t in the project on the very line that states it? I get the same error if I copy the wickedlysmart download code into a new file. I’m using NetBeans if that is anything to do with it?
————————————————————
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package guessgame;
/**
*
* @author D.C
*/
public class GuessGame {
/**
* @param args the command line arguments
*/
Player p1;
Player p2;
Player p3;
public void startGame() {
// TODO code application logic here
p1 = new Player();
p2 = new Player();
p3 = new Player();
int guessp1 = 0;
int guessp2=0;
int guessp3=0;
boolean p1isRight = false;
boolean p2isRight = false;
boolean p3isRight=false;
int targetNumber = (int) (Math.random()) *10;
System.out.println(“I’m thinking of a number between 1 and 9…”);
while (true){
System.out.println(“Number to guess is ” + targetNumber);
p1.guess();
p2.guess();
p3.guess();
guessp1 = p1.number;
System.out.println(“Player one guessed “+ guessp1);
guessp2 = p2.number;
System.out.println(“Player two guessed “+guessp2);
guessp3 = p3.number;
System.out.println(“Player three guessed ” + guessp3);
if (guessp1 == targetNumber){
p1isRight = True;
}
if (guessp2 == targetNumber){
p2isRight = True;
}
if (guessp3 == targetNumber){
p3isRight = True;
}
if (p1isRight |p2isRight|p3isRight){
System.out.println(“We have a winner”);
System.out.println(“Player one got it right? ” +p1isRight);
System.out.println(“Player two got it right?” + p2isRight);
System.out.println(“Player three got it right?”+ p3isRight);
System.out.println(“Game is over”);
break; // game over, so break out of the loop
}else{
//Keep going until someone is right
System.out.println(“Players will have to try again”);
}// end if / else
} //end loop
// end method
//end class
}
public class Player{
int number =0; // where the guess goes
public void guess(){
number = (int) (Math.random()*10);
System.out.println(“I’m guessing ” + number);
}
public class GameLauncher{
public static void main(String[] args){
GuessGame game = new GuessGame();
game.startGame();
}
}
}
}
Hi,
First – Love the book.
However, I downloaded the zip files that you have on the site, and it seems that the source code doesn’t follow the format in the book (specifically referring to the ready-bake code). There’s extra files with extra code in Chapter 05. Additionally, packages aren’t explained in the book prior to Chapter 05. It took quite a bit of tweaking to figure out how to get the files in the ZIP above to *kind’ve* work.. and ended up just being easier to type it straight out of the book.
Overall, liking the book quite a bit so far.
What IDE should i use when i read head first java book..Thank you
In socket programming in java,how does the server know how to communicate with the client?..plz reply
Really hard to understand…
I’m sure you’ve already found this out, but in case you haven’t the answer is yes. Java 7 simply adds some classes and and further functionality, the only disadvantage to buying a java 5 book is that your a little behind the times.
Try harder
Don’t use an IDE, use notepad or something until after chapter 16 and just run your programs in a command prompt window
The point of using methods in a class to access and set your instance variables in another class is so you can set a classes instance variables to ‘private’ and keep them safe in other classes.
Thank you for the information
how are you guys gonna say in your book you have answers to the exercises on your website but yet they are nowhere to be found. fail
Sam, “you guys” is Kathy and Bert, so we will pass that info along but we don’t speak for them and this isn’t our book. Now, the exercises are answered IN THE BOOK, except for Brain Builders/Power types. So what are you referring to?
Yes, it’s unfortunate, but the books don’t scale well for Kindle. And because of the way the books are created it’s impossible to reformat for Kindle.
If you have a specific question about Chapter 4, let us know!
In case this helps someone, here is a link to the answers for the Sharpen your Pencil exercises: http://www.headfirstlabs.com/books/hfjava/hfjava_sharpen.pdf
Thanks Benjamin!
I just bought the 2nd ed and am pretty disappointed, so far. I have no Java experience and expected step-by-step instruction, at least in the beginning.
This book seems to assume you already know a lot.
I downloaded the Java files but can’t figure out how to use them.
Harold, we have passed your comments on to the authors Kathy and Bert. We support the book files on this site for legacy reasons but this is not your book. I’m sorry we can’t be more helpful.
Comments are closed