1. What is the output from the following code snippet?
public class Test {
public static void main(String[] args) {
System.out.println(1 + 2 + "java" + 3);
}
}
__________________
The code will compile and print "3java3"
2. What is the output from the following code?
int x=5;
if (x>6)
System. out. println("x>l");
else if (x>=5)
System. out .println("x>=5");
else if (x<10)
System. out. println("x<10");
else
System.out.println("none of the above");
____________________
x>=5
4. What is the output from the following code snippet?
String str1= "java";
String str2=new String("java");
System.out.println( str1==str2 );
System.out.println( str1==str2.intern() );
______________________
The code will compile and print "false true"
5. The following code can be compiled, True/False?
byte b = 1;
b = b + 1;
___________________
false
6. What is the output from the following code?
int x=0;
int y=5;
do{
++x;
y--;
}while(x<3);
System.out.println(x + " " + y);
_______________
3 2
8. Interfaces define what?
______________________
All method definitions without any implementations
9. Modeling classes for a business problem requires understanding of the business
not Java. True or false?
______________________
false
10. The state of an object differentiates it from other objects of the same class.
True or False?
__________________________
true
11. In what order do multiple catch statements execute?
____________________________
The order they are declared in ( most specific first).
12. What symbol(s) is used to separate multiple exceptions in one catch statement?
_____________________________
A single vertical bar |
13. What is special about including a resource in a try statement?(Choose Two)
_____________________________
An error will be thrown if the resources does not open.
14. Which of the following statements is false?
____________________________
An ArrayList has a fixed length.
15. The main purpose of unit testing is to verify that an individual unit (a class,
in Java) is working correctly before it is combined with other components in the
system. True or false?
_______________________________
true
16. Unit testing is the phase in software testing in which individual software
modules are combined and tested as a whole. True or false?
_______________________________
false
17. Virtual method invocation must be defined with the instanceof operator.
True or false?
______________________________
false
18. You can always upcast a subclass to an interface provided you don't need to
access any members of the concrete class.
True or false?
___________________________
true
20. You can't downcast an object explicitly because you must use virtual method
invocation.
True or false?
________________________
false
22. The following code will compile.
class Node<T> implements Comparable<T>{
public int compareTo(T obj){return 1;}
}
class Test{
public static void main(String[] args){
Node<String> nc=new Node<>();
Comparable<String> com=nc;
}
________________________
true
23. Generic methods are required to be declared as static.
True or False?
______________________________
false
24. What is the result from the following code snippet?
public static void main(String[] args) {
List <Gum> list1 = new ArrayList<Gum>();
list1.add(new Gum());
List list2 = list1;
list2.add(new Integer(9));
System.out.println(list2.size());
}
____________________
2
25. < ? extends Animal > is an example of a bounded generic wildcard.
True or False?
__________________________
true
26. Stacks are identical to Queues.
True or false?
________________
false
27. A LinkedList is a list of elements that is dynamically stored.
True or false?
_______________
true
28. A LinkedList is a type of Stack.
True or False?
_______________________
true
29. What are maps that link a Key to a Value?
__________________
HashMaps
30. Which of the following describes a deque.
___________________
All of the above
31. Why might a sequential search be inefficient?
__________________________
It requires incrementing through the entire array in the worst case, which is
inefficient on large data sets.
32. Which of the following best describes lexicographical order?
____________________________
An order based on the ASCII value of characters.
33. Which of the following best describes lexicographical order?
________________________
An order based on the ASCII value of characters.
34. Which of the following is the correct lexicographical order for the conents of
the following int array?
____________________________
{1, 1, 17, 22, 28, 29, 3, 50, 71, 83}
35. A sequential search is an iteration through the array that stops at the index
where the desired element is found. True or false?
_________________________
true
36. Which is the correct way to initialize a HashSet?
_______________________
HashSet<String> classMates =
new HashSet<String>>();
37. What is the output from the following code snippet?
TreeSet <String> t = new TreeSet<String>();
if (t.add("one"))
if (t.add("two"))
if (t.add ("three"))
t.add("four");
for (String s : t)
System.out.print (s);
__________________________
fouronethreetwo
38. Which of these could be a set? Why?
___________________________
{1, 2, 5, 178, 259} because it contains no duplicates and all its elements are of
the same type.
40. In a regular expression, {x} and {x,} represent the same thing, that the
preceding character may occur x or more times to create a match.
True or false?
__________________________
false
41. Consider that you are making a calendar and decide to write a segment of code
that returns true if the string month is April, May, June, or July. Which code
segment correctly implements use of regular expressions to complete this task?
__________________________
return month.matches("April|May|June|July");
42. A regular expression is a character or a sequence of characters that represent
a string or multiple strings.
True or false?
__________________________
true
43. Your teacher asks you to write a segment of code that returns true if String
str contains zero or one character(s) and false otherwise. Which of the following
code segments completes this task?(Choose Two)
____________________________
if( str.length() == 0 || str.length() == 1)
{ return true;}
return false; (*)
44. A non-linear recursive method can call how many copies of itself?
_______________________________
2 or more
45. A non-linear recursive method is less expensive than a linear recursive method.
True or false?
__________________
false
50. Identify the method, of those listed below, that is not available to both
StringBuilders and Strings?
_________________
delete(int start, int end)