Summary: Using Classes and Objects
In this lesson, we will look the important points we covered in this chapter.
- The Java Class Library, which contains a collection of standard classes that we can use in our programs, is organized into packages of classes.
- We use the operator
new
to create a new object of a class type. - A variable of a primitive data type contains the actual value of the data it represents. A variable of a class type contains a reference to the object that it represents.
- Characters within strings are represented by Unicode values.
- Certain escape characters are written as two characters. For example, the new-line character is
\n
. - Methods within the class
String
enable us to manipulate strings. For example, we can join two strings end to end, get the length of a string, get the character at a certain position, locate a substring, and compare strings. - We can use the class
Scanner
to extract tokens from a string that is either defined in our program or read as data. By default, white space separates the tokens, but we can define other characters as delimiters. - An object of the class
LocalTime
represents the time that it was created. We can compare two such objects and decide which one represents the earlier time. - The class
BigDecimal
provides accurate decimal arithmetic with arbitrarily large numbers. - A wrapper class such as
Integer
represents primitive data as an object.Integer
contains the methodparseInt
that converts a string containing an integer to anint
. It also defines constants that represent the minimum and maximum values of anint
value. - The class
Random
has methods to generate numbers that appear to be random. - The class
DecimalFormat
enables us to format the output of a real number or an integer according to a pattern that we create.
Get hands-on with 1400+ tech skills courses.