Deck 3: Introduction to Objects and Inputoutput

Full screen (f)
exit full mode
Question
The default output of decimal numbers of the type float is up to nine decimal places.
Use Space or
up arrow
down arrow
to flip the card.
Question
String variables are reference variables.
Question
If length denotes the length of a nonnull string, then length - 1 gives the index of the last character in the string.
Question
String objects are mutable.
Question
Suppose z = 1834.762. The output of the statement System.out.printf("%.1f", z); is 1834.800.
Question
In the class String, the substring method inserts a string into another string.
Question
The method printf is used only to format the output of integers and decimal numbers.
Question
Reference type variables directly store data into their memory space.
Question
Given int num; the value of num is directly stored in its memory space.
Question
The new operator is used to create an int variable.
Question
In a format specifier, the option width specifies the maximum number of characters to be written to the output.
Question
The classes Integer, Float, and Double are called wrapper classes.
Question
In a string, the index (position) of the first character is 1.
Question
Suppose that name is a String variable. Then the following two statements are equivalent. name = "Danny"; name = new String("Danny");
Question
To use the contents of the java.lang package in a program, they must be imported using the import statement.
Question
Java provides automatic garbage collection.
Question
In a format specifier, if the flag is set to 'l', then the output of the result is left justified.
Question
In order to use a predefined method, you only need to know the name of the method and the type of each parameter.
Question
The value of the expression Integer.parseInt("+782") is "782".
Question
The dot (.) operator is also called the member specific operator.
Question
When writing output to a file, if the file is not closed at the end of the program, you may not be able to view your output properly.
Question
What will most probably happen if you omit the dot operator when accessing a method?

A) An exception will be thrown.
C) A syntax error will be reported.
B) The computer will crash.
D) The program will execute as planned.
Question
Which of the following is the member access operator?

A) +
C) -
B) .
D) ->
Question
In Java, all variables declared using a class are ____.

A) primitive variables
C) constants
B) reference variables
D) operators
Question
Given a decimal number, the method format of the class String returns the string containing the digits of the formatted number.
Question
The class JOptionPane allows a programmer to use graphical interface components to obtain input from a user.
Question
An expression such as str.length(); is an example of a(n) ____.

A) system call
C) class
B) object call
D) method call
Question
What is the value of the following statement? Math.pow(3,4)

A) 7
C) 34
B) 12
D) 81
Question
Suppose str is a String variable. The statement str = new String("Programming"); is similar to which of the following?

A) new String = "Programming";
B) String new = "Programming";
C) str = "Programming";
D) str new "Programming";
Question
Which package is automatically imported by the Java system?

A) java.io
C) java.util
B) java.lang
D) java.swing
Question
There are ____ type(s) of methods in a class.

A) one
C) three
B) two
D) four
Question
The statement System.exit(0); is found at the end of every working Java program.
Question
Which statement instructs a program to run the garbage collector?

A) System.clearGarbage();
B) System.flushGarbage();
C) System.out();
D) System.gc();
Question
Which of the following method is contained in the package java.util?

A) format
C) nextInt
B) Integer
D) printf
Question
Based on the code above, what is the value of str1?

A) exam i
C) exam is
B) exam
D) on Monday
Question
The class JOptionPane is part of the package java.swing.
Question
Suppose the String variable str points to the String object "Sunny day" at the memory address 3600. Then the value of str is:

A) the memory address 3600
C) 3600 + "Sunny day"
B) "Sunny day"
D) None of these
Question
Based on the code above, what is the value of str2?

A) Firs
C) Monda
B) First
D) exam
Question
Based on the code above, what is the value of length1?

A) 20
C) 24
B) 21
D) 26
Question
Which of the following is a valid statement? (i) int num = new int(67); (ii) String name = new ("Doe"); (iii) String name = "Doe";

A) Only (i)
C) Only (iii)
B) Only (i) and (ii)
D) Only (ii) and (iii)
Question
Suppose that you have the declaration: int num = 94; double x = 73.92; String str = "Programming"; What is the output of the following statements? System.out.println("123456789012345678901234567890"); System.out.printf("%5d%6.2f %15s%n", num, x, str);

A) 123456789012345678901234567890
B) 123456789012345678901234567890
C) 123456789012345678901234567890
D) 123456789012345678901234567890
Question
Based on the code above, what is the value of str3?

A) "First exam is on Monday."
B) "F#rst exam #s on Monday."
C) "F#rst exam is on Monday."
D) "#i### #### i###########."
Question
Consider the following statements. double x; String y; y = String.format("%.2f", x); If x = 285.679, what is the value of y?

A) "285.00"
C) "285.68"
B) "285.680"
D) "285.068"
Question
Which of the following outputs 56734.9875 to three decimal places?

A) System.out.printf("3f%", 56734.9875);
B) System.out.printf(".3f%", 56734.9875);
C) System.out.printf(".03f%", 56734.9875);
D) System.out.printf("%.3f", 56734.9875);
Question
The showMessageDialog method has ____ parameter(s).

A) one
C) three
B) two
D) four
Question
What is the output of the following statement? System.out.printf("%.2f", 48.9);

A) 48.00
C) 49
B) 48.90
D) 49.00
Question
Which of the following is an area of secondary storage used to hold information?

A) file
C) constant
B) variable
D) buffer
Question
Which of the following statements would store input in name?

A) name =
B) name =
C) name = System.in();
D) name = JOptionPane.input("Enter your name and press OK");
Question
What happens when JOptionPane.PLAIN_MESSAGE is chosen as the messageType parameter?

A) No icon is displayed in the dialog box.
B) An X is displayed in the dialog box.
C) A question mark is displayed in the dialog box.
D) An exclamation point is displayed in the dialog box.
Question
Based on the code above, what is the value of str4?

A) 11
C) 13
B) 12
D) 14
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/50
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 3: Introduction to Objects and Inputoutput
1
The default output of decimal numbers of the type float is up to nine decimal places.
False
2
String variables are reference variables.
True
3
If length denotes the length of a nonnull string, then length - 1 gives the index of the last character in the string.
True
4
String objects are mutable.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
5
Suppose z = 1834.762. The output of the statement System.out.printf("%.1f", z); is 1834.800.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
6
In the class String, the substring method inserts a string into another string.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
7
The method printf is used only to format the output of integers and decimal numbers.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
8
Reference type variables directly store data into their memory space.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
9
Given int num; the value of num is directly stored in its memory space.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
10
The new operator is used to create an int variable.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
11
In a format specifier, the option width specifies the maximum number of characters to be written to the output.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
12
The classes Integer, Float, and Double are called wrapper classes.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
13
In a string, the index (position) of the first character is 1.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
14
Suppose that name is a String variable. Then the following two statements are equivalent. name = "Danny"; name = new String("Danny");
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
15
To use the contents of the java.lang package in a program, they must be imported using the import statement.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
16
Java provides automatic garbage collection.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
17
In a format specifier, if the flag is set to 'l', then the output of the result is left justified.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
18
In order to use a predefined method, you only need to know the name of the method and the type of each parameter.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
19
The value of the expression Integer.parseInt("+782") is "782".
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
20
The dot (.) operator is also called the member specific operator.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
21
When writing output to a file, if the file is not closed at the end of the program, you may not be able to view your output properly.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
22
What will most probably happen if you omit the dot operator when accessing a method?

A) An exception will be thrown.
C) A syntax error will be reported.
B) The computer will crash.
D) The program will execute as planned.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
23
Which of the following is the member access operator?

A) +
C) -
B) .
D) ->
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
24
In Java, all variables declared using a class are ____.

A) primitive variables
C) constants
B) reference variables
D) operators
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
25
Given a decimal number, the method format of the class String returns the string containing the digits of the formatted number.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
26
The class JOptionPane allows a programmer to use graphical interface components to obtain input from a user.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
27
An expression such as str.length(); is an example of a(n) ____.

A) system call
C) class
B) object call
D) method call
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
28
What is the value of the following statement? Math.pow(3,4)

A) 7
C) 34
B) 12
D) 81
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
29
Suppose str is a String variable. The statement str = new String("Programming"); is similar to which of the following?

A) new String = "Programming";
B) String new = "Programming";
C) str = "Programming";
D) str new "Programming";
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
30
Which package is automatically imported by the Java system?

A) java.io
C) java.util
B) java.lang
D) java.swing
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
31
There are ____ type(s) of methods in a class.

A) one
C) three
B) two
D) four
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
32
The statement System.exit(0); is found at the end of every working Java program.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
33
Which statement instructs a program to run the garbage collector?

A) System.clearGarbage();
B) System.flushGarbage();
C) System.out();
D) System.gc();
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
34
Which of the following method is contained in the package java.util?

A) format
C) nextInt
B) Integer
D) printf
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
35
Based on the code above, what is the value of str1?

A) exam i
C) exam is
B) exam
D) on Monday
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
36
The class JOptionPane is part of the package java.swing.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
37
Suppose the String variable str points to the String object "Sunny day" at the memory address 3600. Then the value of str is:

A) the memory address 3600
C) 3600 + "Sunny day"
B) "Sunny day"
D) None of these
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
38
Based on the code above, what is the value of str2?

A) Firs
C) Monda
B) First
D) exam
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
39
Based on the code above, what is the value of length1?

A) 20
C) 24
B) 21
D) 26
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
40
Which of the following is a valid statement? (i) int num = new int(67); (ii) String name = new ("Doe"); (iii) String name = "Doe";

A) Only (i)
C) Only (iii)
B) Only (i) and (ii)
D) Only (ii) and (iii)
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
41
Suppose that you have the declaration: int num = 94; double x = 73.92; String str = "Programming"; What is the output of the following statements? System.out.println("123456789012345678901234567890"); System.out.printf("%5d%6.2f %15s%n", num, x, str);

A) 123456789012345678901234567890
B) 123456789012345678901234567890
C) 123456789012345678901234567890
D) 123456789012345678901234567890
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
42
Based on the code above, what is the value of str3?

A) "First exam is on Monday."
B) "F#rst exam #s on Monday."
C) "F#rst exam is on Monday."
D) "#i### #### i###########."
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
43
Consider the following statements. double x; String y; y = String.format("%.2f", x); If x = 285.679, what is the value of y?

A) "285.00"
C) "285.68"
B) "285.680"
D) "285.068"
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
44
Which of the following outputs 56734.9875 to three decimal places?

A) System.out.printf("3f%", 56734.9875);
B) System.out.printf(".3f%", 56734.9875);
C) System.out.printf(".03f%", 56734.9875);
D) System.out.printf("%.3f", 56734.9875);
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
45
The showMessageDialog method has ____ parameter(s).

A) one
C) three
B) two
D) four
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
46
What is the output of the following statement? System.out.printf("%.2f", 48.9);

A) 48.00
C) 49
B) 48.90
D) 49.00
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
47
Which of the following is an area of secondary storage used to hold information?

A) file
C) constant
B) variable
D) buffer
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
48
Which of the following statements would store input in name?

A) name =
B) name =
C) name = System.in();
D) name = JOptionPane.input("Enter your name and press OK");
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
49
What happens when JOptionPane.PLAIN_MESSAGE is chosen as the messageType parameter?

A) No icon is displayed in the dialog box.
B) An X is displayed in the dialog box.
C) A question mark is displayed in the dialog box.
D) An exclamation point is displayed in the dialog box.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
50
Based on the code above, what is the value of str4?

A) 11
C) 13
B) 12
D) 14
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 50 flashcards in this deck.