B.1 Fill in the blanks in each of the following:
a) Each class declaration that begins with keyword _________ must be stored in a file that has exactly the same name as the class and ends with the .java
file-name extension.
b) Keyword ____________ in a class declaration is followed immediately by the class’s name.
c) Keyword ____________ requests memory from the system to store an object, then calls the corresponding class’s constructor to initialize the object.
d) Each parameter must specify both a(n) ____________ and a(n) ____________.
e) By default, classes that are compiled in the same directory are considered to be in the same package, known as the ____________.
f) When each object of a class maintains its own copy of an attribute, the field that represents the attribute is also known as a(n) ____________.
g) Java provides two primitive types for storing floating-point numbers in memory: ____________ and ____________.
h) Variables of type double
represent ____________ floating-point numbers.
i) Scanner
method ____________ returns a double
value.
j) Keyword public
is an access ____________.
k) Return type ____________ indicates that a method will not return a value.
l) Scanner
method ____________ reads characters until it encounters a newline character, then returns those characters as a String
.
m) Class String
is in package ____________.
n) A(n) ____________ is not required if you always refer to a class with its fully qualified class name.
o) A(n) ____________ is a number with a decimal point, such as 7.33, 0.0975 or 1000.12345.
p) Variables of type float
represent ____________ floating-point numbers.
q) The format specifier ____________ is used to output values of type float
or double
.
r) Types in Java are divided into two categories—____________ types and ____________ types.
B.2 State whether each of the following is true or false. If false, explain why.
a) By convention, method names begin with an uppercase first letter, and all subsequent words in the name begin with a capital first letter.
b) An import
declaration is not required when one class in a package uses another in the same package.
c) Empty parentheses following a method name in a method declaration indicate that the method does not require any parameters to perform its task.
d) Variables or methods declared with access modifier private
are accessible only to methods of the class in which they’re declared.
e) A primitive-type variable can be used to invoke a method.
f) Variables declared in the body of a particular method are known as instance variables and can be used in all methods of the class.
g) Every method’s body is delimited by left and right braces ({
and }
).
h) Primitive-type local variables are initialized by default.
i) Reference-type instance variables are initialized by default to the value null
.
j) Any class that contains public static void main( String[] args )
can be used to execute an application.
k) The number of arguments in the method call must match the number of parameters in the method declaration’s parameter list.
l) Floating-point values that appear in source code are known as floating-point literals and are type float
by default.
B.3 What is the difference between a local variable and a field?
B.4 Explain the purpose of a method parameter. What is the difference between a parameter and an argument?