O'Reilly logo

Big Java, 4th Edition by Cay Horstmann

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 2. Using Objects

CHAPTER GOALS

  • To learn about variables

  • To understand the concepts of classes and objects

  • To be able to call methods

  • To learn about parameters and return values

  • To be able to browse the API documentation

    T To implement test programs

  • To understand the difference between objects and object references

    G To write programs that display simple shapes

Most useful programs don't just manipulate numbers and strings. Instead, they deal with data items that are more complex and that more closely represent1 entities in the real world. Examples of these data items include bank accounts, employee records, and graphical shapes.

The Java language is ideally suited for designing and manipulating such data items, or objects. In Java, you implement classes that describe the behavior of these objects. In this chapter, you will learn how to manipulate objects that belong to classes that have already been implemented. This knowledge will prepare you for the next chapter in which you will learn how to implement your own classes.

Types

Before we start with the main topic of this chapter, we need to go over some basic programming terminology. In the first three sections of this chapter, you will learn about the concepts of types, variables, and assignment.

A computer program processes values: numbers, strings, and more complex data items. In Java, every value has a type. For example, the number 13 has the type int (an abbreviation for "integer"), "Hello, World" has the type String, and the object ...

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