How to Use This Book: Intro
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, technical lectures?
this book is for you.
Note
This is NOT a reference book. Head First Java is a book designed for learning, not an encyclopedia of Java facts.
Who should probably back away from this book?
If you can answer âyesâ to any one 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 that a technical book canât be serious if thereâs a picture of a duck in the memory management section?
this book is not for you.
Note
[note from marketing: who took out the part about how this book is for anyone with a valid credit card? And what about that âGive the Gift of Javaâ holiday promotion we discussed... -Fred]
We know what youâre thinking
âHow can this be a serious Java programming book?â
âWhatâs with all the graphics?â
âCan I actually learn it this way?â
âDo I smell pizza?â
And we know what your brain is thinking
Your brain craves novelty. Itâs always searching, scanning, waiting for something unusual. It was built that way, and it helps you stay alive.
Today, youâre less likely to be a tiger snack. But your brainâs still looking. You just never know.
So what does your brain do with all the routine, ordinary, normal things you encounter? Everything it can to stop them from interfering with the brainâs real jobârecording things that matter. It doesnât bother saving the boring things; they never make it past the âthis is obviously not importantâ filter.
How does your brain know whatâs important? Suppose youâre out for a day hike and a tiger jumps in front of you, what happens inside your head?
Neurons fire. Emotions crank up. Chemicals surge .
And thatâs how your brain knows...
This must be important! Donât forget it!
But imagine youâre at home, or in a library. Itâs a safe, warm, tiger-free zone. Youâre studying. Getting ready for an exam. Or trying to learn some tough technical topic your boss thinks will take a week, ten days at the most.
Just one problem. Your brainâs trying to do you a big favor. Itâs trying to make sure that this obviously non-important content doesnât clutter up scarce resources. Resources that are better spent storing the really big things. Like tigers. Like the danger of fire. Like how you should never again snowboard in shorts.
And thereâs no simple way to tell your brain, âHey, brain, thank you very much, but no matter how dull this book is, and how little Iâm registering on the emotional richter scale right now, I really do want you to keep this stuff around.â
Metacognition: thinking about thinking
If you really want to learn, and you want to learn more quickly and more deeply, pay attention to how you pay attention. Think about how you think. Learn how you learn.
Most of us did not take courses on metacognition or learning theory when we were growing up. We were expected to learn, but rarely taught to learn.
But we assume that if youâre holding this book, you want to learn Java. And you probably donât want to spend a lot of time.
To get the most from this book, or any book or learning experience, take responsibility for your brain. Your brain on that content.
The trick is to get your brain to see the new material youâre learning as Really Important. Crucial to your well-being. As important as a tiger. Otherwise, youâre in for a constant battle, with your brain doing its best to keep the new content from sticking.
So just how DO you get your brain to treat Java like it was a hungry tiger?
Thereâs the slow, tedious way, or the faster, more effective way. The slow way is about sheer repetition. You obviously know that you are able to learn and remember even the dullest of topics, if you keep pounding on the same thing. With enough repetition, your brain says, âThis doesnât feel important to him, but he keeps looking at the same thing over and over and over , so I suppose it must be.â
The faster way is to do anything that increases brain activity, especially different types of brain activity. The things on the previous page are a big part of the solution, and theyâre all things that have been proven to help your brain work in your favor. For example, studies show that putting words within the pictures they describe (as opposed to somewhere else in the page, like a caption or in the body text) causes your brain to try to makes sense of how the words and picture relate, and this causes more neurons to fire. More neurons firing = more chances for your brain to get that this is something worth paying attention to, and possibly recording.
A conversational style helps because people tend to pay more attention when they perceive that theyâre in a conversation, since theyâre expected to follow along and hold up their end. The amazing thing is, your brain doesnât necessarily care that the âconversationâ is between you and a book! On the other hand, if the writing style is formal and dry, your brain perceives it the same way you experience being lectured to while sitting in a roomful of passive attendees. No need to stay awake.
But pictures and conversational style are just the beginning.
Hereâs what WE did:
We used pictures, because your brain is tuned for visuals, not text. As far as your brainâs concerned, a picture really is worth 1024 words. And when text and pictures work together, we embedded the text in the pictures because your brain works more effectively when the text is within the thing the text refers to, as opposed to in a caption or buried in the text somewhere.
We used repetition, saying the same thing in different ways and with different media types, and multiple senses , to increase the chance that the content gets coded into more than one area of your brain.
We used concepts and pictures in unexpected ways because your brain is tuned for novelty, and we used pictures and ideas with at least some emotional content, because your brain is tuned to pay attention to the biochemistry of emotions. That which causes you to feel something is more likely to be remembered, even if that feeling is nothing more than a little humor, surprise, or interest.
We used a personalized, conversational style, because your brain is tuned to pay more attention when it believes youâre in a conversation than if it thinks youâre passively listening to a presentation. Your brain does this even when youâre reading .
We included more than 50 exercises because your brain is tuned to learn and remember more when you do things than when you read about things. And we made the exercises challenging-yet-do-able, because thatâs what most people prefer.
We used multiple learning styles, because you might prefer step-by-step procedures, while someone else wants to understand the big picture first, while someone else just wants to see a code example. But regardless of your own learning preference, everyone benefits from seeing the same content represented in multiple ways.
We include content for both sides of your brain, because the more of your brain you engage, the more likely you are to learn and remember, and the longer you can stay focused. Since working one side of the brain often means giving the other side a chance to rest, you can be more productive at learning for a longer period of time.
And we included stories and exercises that present more than one point of view, because your brain is tuned to learn more deeply when itâs forced to make evaluations and judgments.
We included challenges, with exercises, and by asking questions that donât always have a straight answer, because your brain is tuned to learn and remember when it has to work at something (just as you canât get your body in shape by watching people at the gym). But we did our best to make sure that when youâre working hard, itâs on the right things. That youâre not spending one extra dendrite processing a hard-to-understand example, or parsing difficult, jargon-laden, or extremely terse text.
We used an 80/20 approach. We assume that if youâre going for a PhD in Java, this wonât be your only book. So we donât talk about everything . Just the stuff youâll actually use .
Hereâs what YOU can do to bend your brain into submission
So, we did our part. The rest is up to you. These tips are a starting point; Listen to your brain and figure out what works for you and what doesnât. Try new things.
Note
Cut this out and stick it on your refrigerator.
Slow down. The more you understand, the less you have to memorize.
Donât just read. Stop and think. When the book asks you a question, donât just skip to the answer. Imagine that someone really is asking the question. The more deeply you force your brain to think, the better chance you have of learning and remembering.
Do the exercises. Write your own notes.
We put them in, but if we did them for you, that would be like having someone else do your workouts for you. And donât just look at the exercises. Use a pencil. Thereâs plenty of evidence that physical activity while learning can increase the learning.
Read the âThere are No Dumb Questionsâ
That means all of them. Theyâre not optional sidebarsâtheyâre part of the core content! Sometimes the questions are more useful than the answers.
Donât do all your reading in one place.
Stand up, stretch, move around, change chairs, change rooms. Itâll help your brain feel something, and it keeps your learning from being too connected to a particular place.
Make this the last thing you read before bed. Or at least the last challenging thing.
Part of the learning (especially the transfer to long-term memory) happens after you put the book down. Your brain needs time on its own, to do more processing. If you put in something new during that processing time, some of what you just learned will be lost.
Drink water. Lots of it.
Your brain works best in a nice bath of fluid. Dehydration (which can happen before you ever feel thirsty) decreases cognitive function.
Talk about it. Out loud.
Speaking activates a different part of the brain. If youâre trying to understand something or increase your chance of remembering it later, say it out loud. Better still, try to explain it out loud to someone else. Youâll learn more quickly, and you might uncover ideas you hadnât known were there when you were reading about it.
Listen to your brain.
Pay attention to whether your brain is getting overloaded. If you find yourself starting to skim the surface or forget what you just read, itâs time for a break. Once you go past a certain point, you wonât learn faster by trying to shove more in, and you might even hurt the process.
Feel something!
Your brain needs to know that this matters. Get involved with the stories. Make up your own captions for the photos. Groaning over a bad joke is still better than feeling nothing at all.
Type and run the code.
Type and run the code examples. Then you can experiment with changing and improving the code (or breaking it, which is sometimes the best way to figure out whatâs really happening). Most of the code, expecially long examples and Ready-Bake Code, are at https://oreil.ly/hfJava_3e_examples.
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. 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.
Note
This book assumes youâre using Java 11 (with the exception of Appendix B). However, if youâre using Java 8, you will find most of the code still works.
If thereâs discussion of a feature from a version of Java higher than Java 8, the required version will be mentioned.
The code from this book is available at https://oreil.ly/hfJava_3e_examples.
Last-minute things you need to know:
This is a learning experience, not a reference book. We deliberately stripped out everything that might get in the way of learning whatever it is weâre working on at that point in the book. And the first time through, you need to begin at the beginning, because the book makes assumptions about what youâve already seen and learned.
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 conflict 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.
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, but since building and deploying Java applications generally relies on third-party build tools like Maven and Gradle, we have assumed youâll learn those tools separately.
The end-of-chapter exercises are mandatory; puzzles are optional. Answers for both are at the end of each chapter.
One thing you need to know about the puzzlesâtheyâre puzzles. As in logic puzzles, brain teasers, crossword puzzles, etc. The exercises are here to help you practice what youâve learned, and you should do them all. The puzzles are a different story, and some of them are quite challenging in a puzzle way. These puzzles are meant for puzzlers , and you probably already know if you are one. If youâre not sure, we suggest you give some of them a try, but whatever happens, donât be discouraged if you canât solve a puzzle or if you simply canât be bothered to take the time to work them out.
The âSharpen Your Pencilâ exercises donât all have answers.
Not printed in the book, anyway. For some of them, there is no right answer, and for the others, part of the learning experience for the Sharpen activities is for you to decide if and when your answers are right.
The code examples are as lean as possible.
Itâs frustrating to wade through 200 lines of code looking for the two lines you need to understand. Most examples in this book are shown within the smallest possible context, so that the part youâre trying to learn is clear and simple. So donât expect the code to be robust, or even complete. Thatâs your assignment for after you finish the book. The book examples are written specifically for learning and arenât always fully functional.
Technical Reviewers for the 3rd Edition
Marc Loy
Marc started with Java training at Sun Microsystems in the early days (shout-out to HotJava!) and never looked back. He authored a number of early Java books and training courses, working with a wide variety of companies across the US, Europe, and Asia along the way. Most recently for OâReilly, Marc authored Smaller C and co-authored the fifth edition of Learning Java. Currently in Ohio, Marc is a software developer and maker specializing in microcontrollers.
Abraham Marin-Perez
Abraham is a Java programmer, consultant, author, and public speaker with more than ten years of experience in a variety of industries. Originally from Valencia, Spain, Abraham has built most of his career in London, UK, working with entities like JP Morgan or the United Kingdomâs Home Office, frequently in collaboration with Equal Experts. Thinking his experiences could be useful to others, Abraham became a Java news editor at InfoQ, authored Real-World Maintainable Software, and co-authored Continuous Delivery in Java. He also helps run the London Java Community. Always the learner, Abraham is pursuing a degree in physics.
Other people to acknowledge for the 3rd Edition
At OâReilly:
Huge thanks to Zan McQuade and Nicole Taché for enabling us to finally get this edition out! Zan, thanks for connecting Trisha back up to the Head First world, and Nicole, fantastic work driving us to get this done. Thanks to Meghan Blanchette, who left OâReilly a hundred years ago, but it was she who introduced Bert and Trisha back in 2014.
Trisha would like to thank:
Helen Scott, for providing frequent feedback on the new topics covered. She consistently stopped me from going too deep or assuming too much knowledge, and is a true champion of the learner. I canât wait to start working even more closely with her on our next project.
My team at JetBrains for their patience and encouragement: Dalia Abo Sheasha, for test-driving the lambdas and streams chapter, and Mala Gupta, for giving me exactly the information I needed about modern Java certifications. Extra special thanks to Hadi Hariri for all his support, always.
The Friday Pub Lunch informaticos , for tolerating lunchtime conversations on whatever aspect of Java I was trying to explain that day or week, and Alys, Jen, and Clare for helping me to figure out when to prioritize this book over family. Thanks to Holly Cummins for finding a last minute bug.
Evie and Amy for the suggestions on how to improve the ice cream examples for Javaâs Optional type. Thank you both for being genuinely interested in my progress, and for the spontaneous high-fives when you heard Iâd finished.
None of this would have been possible without Israel Boza Rodriguez. You put up with me derailing important conversations like âwhat should we have for dinner?â with questions like âdo you think CountDownLatch is too niche to teach beginner developers?â Crucially, you helped me to create space and time to work on the book, and regularly reminded me why I wanted to take on the project in the first place.
Thank you to Bert and Kathy for bringing me on this journey. It was an honor to learn how to be a Head First author from the horseâs mouth, so to speak.
Bert and Kathy would like to thank:
Beth Robson and Eric Freeman, for their overall, ongoing, badass support of the Head First series. A special thanks to Beth for the many conversations we had discussing what new Java topics to teach and how to teach them.
Paul Wheaton and the amazing moderators at CodeRanch.com (a.k.a. JavaRanch), for keeping CodeRanch a friendly place for Java beginners. A special thanks to Campbell Ritchie, Jeanne Boyarsky, Stephan van Hulst, Rob Spoor, Tim Cooke, Fred Rosenberger, and Frits Walraven for their invaluable input concerning what have been the truly important additions to Java since the 2nd edition.
Dave Gustafson, for teaching me so much about software development and rock climbing, AND for great discussions concerning the state of programming. Eric Normand, for teaching us a little FP, and helping us figure out how to slip a few of the best ideas from FP into an OO book. Simon Roberts, for his ongoing and passionate teaching of Java to students all over the world. Thanks to Heinz Kabutz and Venkat Subramaniam for helping us explore the nooks and crannies of Java Streams.
Laura Baldwin and Mike Loukides, for their tireless support of Head First for all these years. Ron Bilodeau and Kristen Brown, for their outstanding, always patient and friendly support.
Technical Editors for the 2nd Edition
Endless thanks to Jessica and Val for their hard work editing the 2nd edition.
Jess works at Hewlett-Packard on the Self-Healing Services Team. She has a bachelorâs in computer engineering from Villanova University, has her SCJP 1.4 and SCWCD certifications, and is literally months away from receiving her masterâs in software engineering at Drexel University (whew!).
When sheâs not working, studying, or motoring in her MINI Cooper S, Jess can be found fighting her cat for yarn as she completes her latest knitting or crochet project (anybody want a hat?). She is originally from Salt Lake City, Utah (no, sheâs not Mormon...yes, you were too going to ask) and is currently living near Philadelphia with her husband, Mendra, and two cats: Chai and Sake.
You can catch her moderating technical forums at javaranch.com .
Valentin has a masterâs degree in information and computer science from the Swiss Federal Institute of Technology in Lausanne (EPFL). He has worked as a software engineer with SRI International (Menlo Park, CA) and as a principal engineer in the Software Engineering Laboratory of EPFL.
Valentin is the cofounder and CTO of Condris Technologies, a company specializing in the development of software architecture solutions.
His research and development interests include aspect-oriented technologies, design and architectural patterns, web services, and software architecture. Besides taking care of his wife, gardening, reading, and doing some sport, Valentin moderates the SCBCD and SCDJWS forums at Javaranch.com. He holds the SCJP, SCJD, SCBCD, SCWCD, and SCDJWS certifications. He has also had the opportunity to serve as a co-author for Whizlabs SCBCD Exam Simulator.
(Weâre still in shock from seeing him in a tie .)
Other people to credit, for the 2nd Edition
At OâReilly:
Our biggest thanks to Mike Loukides at OâReilly, for taking a chance on this, and helping to shape the Head First concept into a book (and series). As this second edition goes to print there are now five Head First books, and heâs been with us all the way. To Tim OâReilly, for his willingness to launch into something completely new and different. Thanks to the clever Kyle Hart for figuring out how Head First fits into the world and for launching the series. Finally, to Edie Freedman for designing the Head First âemphasize the head â cover.
Our intrepid beta testers and reviewer team:
Our top honors and thanks go to the director of our javaranch tech review team, Johannes de Jong. This is your fifth time around with us on a Head First book, and weâre thrilled youâre still speaking to us. Jeff Cumps is on his third book with us now and relentless about finding areas where we needed to be more clear or correct.
Corey McGlone, you rock. And we think you give the clearest explanations on JavaRanch. Youâll probably notice we stole one or two of them. Jason Menard saved our technical butts on more than a few details, and Thomas Paul, as always, gave us expert feedback and found the subtle Java issues the rest of us missed. Jane Griscti has her Java chops (and knows a thing or two about writing), and it was great to have her helping on the new edition along with long-time javarancher Barry Gaunt.
Marilyn de Queiroz gave us excellent help on both editions of the book. Chris Jones, John Nyquist, James Cubeta, Terri Cubeta, and Ira Becker gave us a ton of help on the first edition.
Special thanks to a few of the Head Firsters whoâve been helping us from the beginning: Angelo Celeste, Mikalai Zaikin, and Thomas Duff (twduff.com). And thanks to our terrific agent, David Rogelberg of StudioB (but seriously, what about the movie rights?)
Just when you thought there wouldnât be any more acknowledgments*
More Java technical experts who helped out on the first edition (in pseudo-random order):
Emiko Hori, Michael Taupitz, Mike Gallihugh, Manish Hatwalne, James Chegwidden, Shweta Mathur, Mohamed Mazahim, John Paverd, Joseph Bih, Skulrat Patanavanich, Sunil Palicha, Suddhasatwa Ghosh, Ramki Srinivasan, Alfred Raouf, Angelo Celeste, Mikalai Zaikin, John Zoetebier, Jim Pleger, Barry Gaunt, and Mark Dielen.
The first edition puzzle team:
Dirk Schreckmann, Mary âJavaCross Championâ Leners, Rodney J. Woodruff, Gavin Bong, and Jason Menard. Javaranch is lucky to have you all helping out.
Other co-conspirators to thank:
Paul Wheaton, the javaranch Trail Boss for supporting thousands of Java learners. Solveig Haugland, mistress of J2EE and author of Dating Design Patterns. Authors Dori Smith and Tom Negrino (backupbrain.com), for helping us navigate the tech book world.
Our Head First partners in crime, Eric Freeman and Beth Freeman (authors of Head First Design Patterns), for giving us the Bawls⢠to finish this on time.
Sherry Dorris, for the things that really matter.
Brave early adopters of the Head First series:
Joe Litton, Ross P. Goldberg, Dominic Da Silva, honestpuck, Danny Bromberg, Stephen Lepp, Elton Hughes, Eric Christensen, Vulinh Nguyen, Mark Rau, Abdulhaf, Nathan Oliphant, Michael Bradly, Alex Darrow, Michael Fischer, Sarah Nottingham, Tim Allen, Bob Thomas, and Mike Bibby (the first).
*The large number of acknowledgments is because weâre testing the theory that everyone mentioned in a book acknowledgment will buy at least one copy, probably more, what with relatives and everything. If youâd like to be in the acknowledgment of our next book, and you have a large family, write to us.
Get Head First Java, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.