Java Reference
In-Depth Information
• Locale-specific formatting is an important part of internationalization—the process of custom-
izing your applications for users' various locales and spoken languages.
BigDecimal gives you control over how values are rounded—by default all calculations are exact
and no rounding occurs. If you do not specify how to round BigDecimal values and a given value
cannot be represented exactly an ArithmeticException occurs.
• You can specify the rounding mode for BigDecimal by supplying a MathContext object (package
java.math ) to class BigDecimal 's constructor when you create a BigDecimal . You may also pro-
vide a MathContext to various BigDecimal methods that perform calculations. By default, each
pre-configured MathContext uses so called “bankers rounding.”
•A BigDecimal 's scale is the number of digits to the right of its decimal point. If you need a Big-
Decimal rounded to a specific digit, you can call BigDecimal method setScale .
Self-Review Exercise
8.1
Fill in the blanks in each of the following statements:
a) A(n) imports all static members of a class.
b) String class static method is similar to method System.out.printf , but re-
turns a formatted String rather than displaying a String in a command window.
c)
If a method contains a local variable with the same name as one of its class's fields, the
local variable
the field in that method's scope.
d)
The public methods of a class are also known as the class's
or
.
e)
A(n)
declaration specifies one class to import.
f)
If a class declares constructors, the compiler will not create a(n)
.
g)
An object's
method is called implicitly when an object appears in code where
a String is needed.
h)
Get methods are commonly called
or
.
i)
A(n)
method tests whether a condition is true or false.
j)
For every enum , the compiler generates a static method called
that returns an
array of the enum 's constants in the order in which they were declared.
k)
Composition is sometimes referred to as a(n)
relationship.
l)
A(n)
declaration contains a comma-separated list of constants.
m) A(n)
variable represents classwide information that's shared by all the objects
of the class.
declaration imports one static member.
n)
A(n)
o)
The states that code should be granted only the amount of privilege and access
that it needs to accomplish its designated task.
p)
Keyword specifies that a variable is not modifiable after initialiation in a dec-
laration or constructor.
q)
A(n)
declaration imports only the classes that the program uses from a partic-
ular package.
r)
Set methods are commonly called
because they typically change a value.
s)
Use class
to perform precise monetary calculations.
t)
Use the
statement to indicate that a problem has occurred.
Answers to Self-Review Exercise
8.1 a) static import on demand. b) format . c) shadows. d) public services, public interface.
e) single-type-import. f) default constructor. g) toString . h) accessor methods, query methods.
i) predicate. j) values . k) has-a . l) enum . m) static . n) single static import. o) principle of least
privilege. p) final . q) type-import-on-demand. r) mutator methods. s) BigDecimal . t) throw .
 
Search WWH ::




Custom Search