Questions From Project 4
String
1. Which is a valid way to declare a String?
A) string name = “Bob”
B) String name = Bob
C) name = “Bob”
D)
String name = “Bob”
2. Which method concatenates (combines) two or more Strings together?
A) concat ( String str)
B) connates ()
C) combine()
D) combineString ()
3 Once a string is created, it is constant, it cannot be changed.
A)
True
B)
False
4 The case of the entire string can be changed.
A) True
B) False
5 Which of the following is a legal constructor for the string class?
A) String()
B) String(StringBuffer buffer)
C) String(char[] value)
D) All of the above
StringTokenizer
6 Which of these can be used as a delimiter?
A) A comma
B) A space
C) A semicolon
D)
All of the above
7 Which method is to check if there are any more tokens?
A) hasMoreTokens()
B) tokensLeft()
C) anyTokens()
D) None of the above
8 StringTokenizer is known as a(n) _________ class.
A) Historic
B) Sub
C)
Legacy
D) External
9 When would you need to use stringtokenizer?
A)
To parse/split strings
10 What is the character called which separates the tokens?
A) The delimiter
11 You cannot parse a string with more than 10 characters.
A) False
Math
12
When using the round(
) method, if
your input value is of type double. What type will your return value be?
A)
Int
B) Long
C)
Double
D)
float
13
The sqrt
() method will automatically convert a
negative input number to a positive number and compute the square root.
A) False
14
Which of the following is not a method in the math class?
A)
abs()
B)
tan()
C) avg()
D)
round()
15 Which methods have multiple return types?
A) max()
B) min()
C) abs()
D)
All of the above
16 How
many constructors does the Math class have?
A)
0
B) 1
C) 2
D) 3
17 The Math class contains constants as fields; therefore, there is no need for constructors.
A)
True
Random
18 By default, how does the Random
class generate a random number?
A)
User specified
B)
System’s current time
C) from -2147483648 to
2147483647
D) None of the above
19 Which of the following IS the
correct way to create an instance of the Random class given the following code:
private
Random randomGen;
A) randomGen
= new Random;
B) Random = new randomGen;
C)
randomGen = new Random();
D) All of above are incorrect.
20 How do you create a random
integer between 0 and 10?
A) nextInt
(10);
B) nextInt
(9);
C)
nextInt(11);
D) nextInt
(0, 10);
E) nextInt
(0, 9);
21 What
does the Random class use to generate the values?
A) Randomize
B)
Seed
C) Pick
D) Generate
22 Is
it possible to use Random in conjunction with other classes?
A) No
B) Yes,
without any import statement
C)
Yes, as long as the appropriate import statement is used
D) Not
enough information provided
23 If
two Random objects are created at the same exact time, each will generate a
different pattern of random numbers.
A)
False
24 If
a seed is not declared when a Random object is generated, the default seed is
the time in milliseconds since 1970.
A)
True
Integer
25 Which
type of numeric value is the most accurate?
A) Byte
B) Short
C) Int
D)
Double
26 Which
method header is used to create an integer representation of a string object?
A)
parseInt (String s)
B) Equals(Object
obj)
C) doubleValue()
D) intValue()
27 We need to convert primitive type ints into the Integer class in order to create a collection of int values.
A)
True
28 When
dealing with the
compareTo
method if the method runs and returns a value of 0, does that mean:
A) The
two objects are different
B) The
new object is greater than the first object
C)
The objects are equal
Double
29 Which
method header is used to compare a double’s numeric value to another double’s
numeric value?
A) parseInt(String s)
B) Equals(Object obj)
C) doubleValue()
D)
compareTo ( Double anotherDouble)
30 The doubleValue () performs which operation?
A)
takes a given integer and returns its value as a
double.
B) to compare the instance object to another parameter object integer value.
C) creates a string representation of a double object.
D) used to type cast a double value to an integer.
31 Double
is accurate to 9 decimal places.
A)
True
32 Which
method of Class Double returns a string representation of the Double object?
A) doubleValue()
B)
toString()
C) valueOf()
D) intValue()
33 If you have a set of percentages (which can be up to three or four decimal places long), which of the following class should you use in order to create a collection?
A) Integer
B)
Double
C) int
D) double
34 The following are all of a primitive type, except:
A) int
B) char
C) double
D) boolean
E)
Double
DecimalFormat
35 Using this pattern ####.#0, what would the output be for 1.5?
A)
Answer: 1.50
DateFormat
36 In what real world instance would we use the DateFormat class?
A)
Any
computing system that requires the time and date to be kept.
Character
37 What is JAVA Character information based on?
A)
The Unicode Standard
38 Is there a method in the character class that will allow you to convert from uppercase to lowercase?
A)
Yes, toLowerCase(
int
codePoint )
39 Other
than wrapping a value of the primitive type char in an object, what
else does class character do?
A)
Determines the type of character and coverts characters from
uppercase to lowercase.
40 What primitive type does class Character have in its single field?
A)
char
41 Which would be most accurate in comparing two characters?
A) Using = =
B) Using =
C)
Using compareTo()
Boolean
42 What is the default value of a Boolean?
A)
False
43 In
addition to wrapping a value of the primitive type Boolean in an object,
what else does class Boolean do?
A)
Provides various methods for converting a Boolean to a String
and a String to a Boolean.
44 What are the two primary values of a Boolean variable?
A)
True and False
45 What does the parseBoolean (String s) method do?
A)
Parses the string argument as a Boolean.
46 When would you use the toString method?
A)
For creating and or formatting output.
Date
47 What method is used to compare to 2 dates?
A)
compareTo(Date anotherDate)
48 What method is used to change the month?
A)
setMonth (int month)
49 What integer would represent the month of
January?
A)
0
50 The toString ( ) method in class Date overrides the toString ( ) method in class Object?
A)
True
B) False
Calendar
51
Calendar() constructs a Calendar
with the default time zone and locale?
A)
True
ArrayList
52
What are some of the important characteristics of the
ArrayList
class?
A) It
is able to increase its internal capacity as required
B) It
keeps its own private count of how many items it is currently storing
C) It
maintains the order of items you insert into it
D)
All of the above
E) None
of the above
53
Which of the following are valid constructors for
ArrayList?
A) ArrayList(
)
B) ArrayList
(Collection c)
C) ArrayList
(int
initialCapacity)
D)
All of the above
E) None of the above
54 Which is the best description of what an ArrayList is like?
A) Customers waiting in a checkout line
B)
A rocking chair
C) A filing cabinet
D) A gas station
55 What are some important factors of an ArrayList?
A) It is able to increase its internal capacity as required
B) It keeps its own private count of how many items it is currently storing.
C) It maintains the order of items you insert into it
D) All of the above
56 What index does an ArrayList start with?
A) 0
B) 1
C) 2
D) It does not use index
Vector
57
Vector increases the capacity of the collection before it adds
the objects.
A) True
58 Which of the following classes has a capacityIncrement as an argument?
A) Vector
59 How does a vector differ from an array?
A)
A vector’s size is variable while an array’s size is fixed.
B) An array’s size is variable while a vector’s size is fixed.
C) Vectors and arrays are the same thing.
D) Arrays can only hold numbers but a vector can hold any type of data.
60 Vectors can increase in size, but cannot decrease.
A) True
B) False
61 For which situation would a vector be most appropriate?
A) To hold the value of pi.
B) To contain a list of names which will never change.
C) To keep track of the inventory of ice cream at a grocery store.
D) The use of vectors should be avoided at all costs.
Queue
62 A
Queue could be modeled as:
A) standing
in line at the DMV
B) stacking
plates on top of each other
C) waiting
in the cafeteria lunch line
D)
A and C
E) All
of the above.
63 In
a Queue, it is possible to retrieve which elements in the list
A)
The head or first element ONLY
B) The
last element ONLY
C) All
elements in the queue are retrievable
D) Elements
in a queue CANNOT be accessed
E) None
of the above
64 In a Queue, insertion occurs at the ___________ of the queue and deletion occurs at the ___________ of the queue.
A) head, head
B) tail, tail
C)
tail, head
D) head,
tail
E) None
of the above
Linked List
65 Where can insertion, deletion and element access occur in the LinkedList class?
A) At the beginning of the list
B) At the end of the list
C) Any place in the middle of the list
D)
A, B, and C
E) None
of the above
66 A LinkedList is defined as a (an) ___________ while a queue is defined as a (an) __________.
A)
Class, interface
B) Constructor, Method
C) Interface, class
D) Superclass, subclass
E) None of the above