O'Reilly logo

Head First Java, 2nd Edition by Bert Bates, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 6. Get to Know the Java API: Using the Java Library

image with no caption

Java ships with hundreds of pre-built classes. You don’t have to reinvent the wheel if you know how to find what you need in the Java library, known as the Java API. You’ve got better things to do. If you’re going to write code, you might as well write only the parts that are truly custom for your application. You know those programmers who walk out the door each night at 5 PM? The ones who don’t even show up until 10 AM? They use the Java API. And about eight pages from now, so will you. The core Java library is a giant pile of classes just waiting for you to use like building blocks, to assemble your own program out of largely pre-built code. The Ready-bake Java we use in this book is code you don’t have to create from scratch, but you still have to type it. The Java API is full of code you don’t even have to type. All you need to do is learn to use it.

In our last chapter, we left you with the cliff-hanger. A bug

How it’s supposed to look

Here’s what happens when we run it and enter the numbers 1,2,3,4,5,6. Lookin’ good.

A complete game interaction

(your mileage may vary)

image with no caption

How the bug looks

Here’s what happens when we enter 2,2,2.

A different game interaction

(yikes)

In the current version, once you get a hit, you can simply repeat ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required