Java Reference
In-Depth Information
33
Chapter 2 Using Objects
C HAPTER G OALS
ȗ
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
T To implement test programs
ȗ
To be able to browse the API documentation
ȗ
To realize 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 represent 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 define classes that describe the behavior of these objects. In this
chapter, you will learn how to manipulate objects that belong to predefined classes.
This knowledge will prepare you for the next chapter in which you will learn how to
implement your own classes.
33
34
2.1 Types and Variables
In Java, every value has a type. For example, ÐHello, WorldÑ has the type
String , the object System.out has the type PrintStream , and the number 13
has the type int (an abbreviation for Ȓintegerȓ). The type tells you what you can do
with the values. You can call println on any object of type PrintStream . You
can compute the sum or product of any two integers.
Search WWH ::




Custom Search