Java Reference
In-Depth Information
As you have learned, Java supplies wrapper classes such as
Integer
and
Float
for each
of the primitive types. By using class methods defined in those classes, you can convert
objects to primitive types and convert primitive types to objects.
For example, the
parseInt()
class method in the
Integer
class can be used with a string
argument, returning an
int
representation of that string.
The following statement shows how the
parseInt()
method can be used:
int count = Integer.parseInt(“42”);
In the preceding statement, the
String
value
“42”
is returned by
parseInt()
as an inte-
ger with a value of
42
, and this is stored in the
count
variable.
The lack of a
static
keyword in front of a method name makes it an instance method.
Instance methods operate in a particular object, rather than a class of objects. On Day 1,
“Getting Started with Java,” you created an instance method called
checkTemperature()
that checked the temperature in the robot's environment.
TIP
Most methods that affect a particular object should be defined as
instance methods. Methods that provide some general capability
but do not directly affect an instance of the class should be
declared as class methods.
Now that you know how to create classes, objects, class and instance variables, and class
and instance methods, you can put it all together in a Java program.
To refresh your memory,
applications
are Java classes that can be run on their own.
NOTE
Applications are different from
applets
, which are run by a Java-
enabled browser as part of a web page.
A Java application consists of one or more classes and can be as large or as small as you
want it to be. Although all the applications you've created up to this point do nothing but
output some characters to the screen, you also can create Java applications that use win-
dows, graphics, and a graphical user interface.