O'Reilly logo

Beginning Programming with Java For Dummies, 5th Edition by Barry A. Burd

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 17

Programming with Objects and Classes

IN THIS CHAPTER

check Programming with class (and with style and finesse)

check Making objects from classes

check Joining the exclusive “I understand classes and objects” society

Chapters 6, 7, and 8 introduce Java’s primitive types — things like int, double, char, and boolean. That’s great, but how often does a real-world problem deal exclusively with such simple values? Consider an exchange between a merchant and a customer. The customer makes a purchase, which can involve item names, model numbers, credit card info, sales tax rates, and lots of other stuff. A purchase is more complicated than an int value. It’s more complicated than a double value. How do you represent an entire purchase in a Java program?

In older computer programming languages, you treat an entire purchase like a big pile of unbundled laundry. Imagine a mound of socks, shirts, and other pieces of clothing. You have no basket, so you grab as much as you can handle. As you walk to the washer, you drop a few things — a sock here and a washcloth there. This is like the older way of storing the values in a purchase. In older languages, there’s no purchase. There are only double values, ...

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