data structure - Answer- supports for accessing and manipulating the data
data structure - Answer- an object that stores other objects, referred to as data or
elements
True or False to define a data structure is to essentially define a class - Answer-
True
To create a list to store integers, use
A. ArrayList<Object> list = new ArrayList<>();
B. ArrayList<Integer> list = new ArrayList<>();
C. ArrayList<int> list = new ArrayList<int>();
D. ArrayList<Number> list = new ArrayList<>(); - Answer- B. ArrayList<Integer> list
= new ArrayList<>();
Suppose List<String> list = new ArrayList<String>().
Which of the following operations are correct?
ist.add(new Integer(100));
list.add(new ArrayList());
list.add("Red");
list.add(new java.util.Date()); - Answer- list.add("Red");
Which of the following is a correct statement to sort the elements in a list called lst ?
Collections.sort(lst)
Arrays.sort(lst)
new LinkedList(new String[]{"red", "green", "blue"})
lst.sort() - Answer- Collections.sort(lst)
Given the following statement, what is the best way to find a maximum object in an
array of strings ?
String[] names = {"red", "green", "blue"})
Collections.max(names)
Arrays.max(names)
Collections.max(Arrays.asList(names))
Arrays.sort(names) - Answer- Collections.max(Arrays.asList(names))
True or False: A recursive call can result in many more recursive calls, because the
method keeps on dividing a subproblem into new subproblems. - Answer- True
Which of the following statements are characteristics of recursive methods ?
The method is implemented using an if-else or a switch statement that leads to
different cases.
, One or more base cases (the simplest case) are used to stop recursion.
Every recursive call reduces the original problem, bringing it increasingly closer to a
base case until it becomes that case.
All of these are characteristics of a recursive method - Answer- All of these are
characteristics of a recursive methods
True or False: Any problem that can be solved recursively can be solved non
recursively with iterations. - Answer- True
Recursive methods need _____________ time and memory to execute than non
recursive methods. - Answer- more
True or False: Any recursive method can be converted into a non recursive method.
- Answer- True
Recursive programs can run out of memory, causing a _________
logic error
syntax error
end of file error
stack overflow error - Answer- Stack flow error
_________________ occurs when method 1 invokes method 2, which in turn
invokes method 1 - Answer- Indirect recursion
What lets you parameterize types? - Answer- Generics
True or False: The motivation for using Java generics is to detect errors at compile
time. - Answer- True
True or False: A generic type can be defined for a class or interface. A concrete type
must be specified when using the class to create an object or using the class or
interface to declare a reference variable. - Answer- True
To declare a generic method, you place the _________________ immediately after
the keyword static in the method header.
instances
generic type <E>
actual type
subtype - Answer- generic type <E>
True or False: A generic type can be defined for a static method. - Answer- True
You can use _________________ wildcards, bounded wildcards, or lower-bound
wildcards to specify a range for a generic type. - Answer- Unbounded
The information on generics is used by the compiler but is not available at runtime. -
Answer- type erasure