A. import java.util.Vector;
C. import static java.util.Vector.*;
Front
13. Which of the following are legal import statements?
A. import java.util.Vector;
B. static import java.util.Vector.*;
C. import static java.util.Vector.*;
D. import java.util.Vector static;
Back
A. "is a"
Front
8. The keyword extends refers to what type of relationship?
A. "is a"
B. "has a"
C. "was a"
D. "will be a"
E. None of the above
Back
B. False
Front
17. The developer can force garbage collection by calling System.gc().
A. True
B. False
Back
A. Garbage collection cannot be forced.
Front
8. How can you force garbage collection of an object?
A. Garbage collection cannot be forced.
B. Call System.gc().
C. Call System.gc(), passing in a reference to the object to be garbage-collected.
D. Call Runtime.gc().
E. Set all references to the object to new values (null, for example).
Back
A. x[24] is 0
E. x.length is 25
Front
5. Consider the following line of code:
int[] x = new int[25];
After execution, which statements are true? (Choose all that apply.)
A. x[24] is 0
B. x[24] is undefined
C. x[25] is 0
D. x[0] is null
E. x.length is 25
Back
D. −27 through 27 − 1
Front
10. What is the range of values that can be assigned to a variable of type byte?
A. Depends on the underlying hardware
B. 0 through 28 − 1
C. 0 through 216 − 1
D. −27 through 27 − 1
E. −215 through 215 − 1
Back
E. public, protected, default, private
Front
5. Select the order of access modifiers from least restrictive to most restrictive.
A. public, private, protected, default
B. default, protected, private, public
C. public, default, protected, private
D. default, public, protected, private
E. public, protected, default, private
Back
D. Package declaration, imports, class/interface/enum definitions.
Front
4. If all three top-level elements occur in a source file, they must appear in which order?
A. Imports, package declarations, classes/interfaces/enums
B. Classes/interfaces/enums, imports, package declarations
C. Package declaration must come first; order for imports and class/interfaces/enum definitions is not significant
D. Package declaration, imports, class/interface/enum definitions.
E. Imports must come first; order for package declarations and class/interface/enum definitions is not significant
Back
A. boolean
C. char
D. float
Front
18. Select the valid primitive data types. (Select all that apply.)
A. boolean
B. bit
C. char
D. float
E. All of the above
Back
C. native
Front
6. Which access modifier allows you to access method calls in libraries not created in Java?
A. public
B. static
C. native
D. transient
E. volatile
Back
C. The code does not compile.
Front
10. Given the following code, what will be the outcome?
public class Funcs extends java.lang.Math { public int add(int x, int y) {
return x + y;
}
public int sub(int x, int y) { return x - y;
}
public static void main(String [] a) { Funcs f = new Funcs(); System.out.println("" + f.add(1, 2));
}
}
A. The code compiles but does not output anything.
B. "3" is printed out to the console.
C. The code does not compile.
D. None of the above.
Back
A. Vector<Map> v;
B. Set<String> s;
D. Map<String, String> m;
Front
1. Which of the following are valid declarations? Assume java.util.* is imported.
A. Vector<Map> v;
B. Set<String> s;
C. Map<String> m;
D. Map<String, String> m;
Back
A. True
Front
4. An abstract class can contain methods with declared bodies.
A. True
B. False
Back
D. 3
Front
12. What is the value of x after the following operation is performed?
x = 23 % 4;
A. 23
B. 4
C. 5.3
D. 3
E. 5
Back
C. int c = 0xabcd;
D. int d = 0XABCD;
Front
16. Which of the following are legal? (Choose all that apply.)
A. int a = abcd;
B. int b = ABCD;
C. int c = 0xabcd;
D. int d = 0XABCD;
E. int e = 0abcd;
F. int f = 0ABCD;
Back
A. True
Front
21. A StringBuffer is slower than a StringBuilder, but a StringBuffer is threadsafe.
A. True
B. False
Back
D. A final object cannot be reassigned a new address in memory.
Front
7. Which of the following statements are true? (Select all that apply.)
A. A final object's data cannot be changed.
B. A final class can be subclassed.
C. A final method cannot be overloaded.
D. A final object cannot be reassigned a new address in memory.
E. None of the above.
Back
B. super
Front
9. Which of the following keywords is used to invoke a method in the parent class?
A. this
B. super
C. final
D. static
Back
B. notify()
Front
14. What method call is used to tell a thread that it has the opportunity to run?
A. wait()
B. notify()
C. start()
D. run()
Back
C. After line 2 executes, the StringBuffer object is eligible for garbage collection.
Front
19. Consider the following code:
1. StringBuffer sbuf = new StringBuffer();
2. sbuf = null;
3. System.gc();
Choose all true statements:
A. After line 2 executes, the StringBuffer object is garbage collected.
B. After line 3 executes, the StringBuffer object is garbage collected.
C. After line 2 executes, the StringBuffer object is eligible for garbage collection.
D. After line 3 executes, the StringBuffer object is eligible for garbage collection.
Back
D. java.text.DateFormat
Front
23. Which class provides locale-sensitive text formatting for date and time information?
A. java.util.TimeFormat
B. java.util.DateFormat
C. java.text.TimeFormat
D. java.text.DateFormat
Back
B. public static void main(String arg[])
D. public static void main(String[] args)
Front
3. Which of the following signatures are valid for the main() method entry point of an application?
(Choose all that apply.)
A. public static void main()
B. public static void main(String arg[])
C. public void main(String [] arg)
D. public static void main(String[] args)
E. public static int main(String [] arg)
Back
B. Compilation takes slightly more time.
Front
11. Suppose a source file contains a large number of import statements. How do the imports affect the time required to compile the source file?
A. Compilation takes no additional time.
B. Compilation takes slightly more time.
C. Compilation takes significantly more time.
Back
A. The code will not compile because of line 4.
Front
15. Given the following code, which of the results that follow would you expect?
1. package mail; 2.
3. interface Box {
4. protected void open();
5. void close();
6. public void empty();
7. }
A. The code will not compile because of line 4.
B. The code will not compile because of line 5.
C. The code will not compile because of line 6.
D. The code will compile.
Back
D. 32
Front
19. How many bits does a float contain?
A. 1
B. 8
C. 16
D. 32
E. 64
Back
B. False
Front
1. A signed data type has an equal number of non-zero positive and negative values available.
A. True
B. False
Back
A. By getting a Set object from the Map and iterating through it.
Front
2. You can determine all the keys in a Map in which of the following ways?
A. By getting a Set object from the Map and iterating through it.
B. By iterating through the Iterator of the Map.
C. By enumerating through the Enumeration of the Map.
D. By getting a List from the Map and enumerating through the List.
E. You cannot determine the keys in a Map.
Back
B. False
Front
24. The following line of code is valid.
int x = 9; byte b = x;
A. True
B. False
Back
D. 101
Front
6. Consider the following application:
1. class Q6 {
2. public static void main(String args[]) {
3. Holder h = new Holder();
4. h.held = 100;
5. h.bump(h);
6. System.out.println(h.held);
7. }
8. } 9.
10. class Holder {
11. public int held;
12. public void bump(Holder theHolder) {
13. theHolder.held++; }
14. }
15. }
What value is printed out at line 6?
A. 0
B. 1
C. 100
D. 101
Back
C. Arguments that are primitive type are passed by value.
Front
28. Which of the following statements accurately describes how variables are passed to methods?
A. Arguments are always passed by value.
B. Arguments are always passed by reference.
C. Arguments that are primitive type are passed by value.
D. Arguments that are passed with the & operator are passed by reference.
Back
C. The code compiles, and prints out >>null<<
Front
15. What happens when you try to compile and run the following code?
public class Q15 { static String s;
public static void main(String[] args) {
System.out.println(">>" + s + "<<");
}
}
A. The code does not compile
B. The code compiles, and prints out >><<
C. The code compiles, and prints out >>null<<
Back
D. −215 through 215 − 1
Front
9. What is the range of values that can be assigned to a variable of type short?
A. Depends on the underlying hardware
B. 0 through 216 − 1
C. 0 through 232 − 1
D. −215 through 215 − 1
E. −231 through 231 − 1
Back
A. private readObject
Front
30. Suppose you are writing a class that provides custom deserialization. The class implements java.io.Serializable (and not java.io.Externalizable). What method should imple- ment the custom deserialization, and what is its access mode?
A. private readObject
B. public readObject()
C. private readExternal()
D. public readExternal()
Back
D. The code does not compile.
Front
11. Given the following code, what is the expected outcome?
public class Test {
public static void main(String [] a) { int [] b = [1,2,3,4,5,6,7,8,9,0]; System.out.println("a[2]=" + a[2]);
}
}
A. The code compiles but does not output anything.
B. "a[2]=3" is printed out to the console.
C. "a[2]=2" is printed out to the console.
D. The code does not compile.
E. None of the above.
Back
B. False
Front
27. Java arrays always start at index 1.
A. True
B. False
Back
C. Exceptions
Front
16. Assertions are used to enforce all but which of the following?
A. Preconditions
B. Postconditions
C. Exceptions
D. Class invariants
Back
A. double d = 1.2d;
B. double d = 1.2D;
Front
17. Which of the following are legal? (Choose all that apply.)
A. double d = 1.2d;
B. double d = 1.2D;
C. double d = 1.2d5;
D. double d = 1.2D5;
Back
D. char, int, float, long
Front
22. Select the list of primitives ordered in smallest to largest bit size representation.
A. boolean, char, byte, double
B. byte, int, float, char
C. char, short, long, float
D. char, int, float, long
E. None of the above
Back
A. Integer i = 7;
B. Integer i = new Integer(5); int j = i;
C. byte b = 7;
Front
25. Which of the following code snippets compile?
A. Integer i = 7;
B. Integer i = new Integer(5); int j = i;
C. byte b = 7;
D. int i = 7; byte b = i;
E. None of the above
Back
B. Primitives are passed by value.
D. References are passed by value.
Front
20. Which of the following are true? (Choose all that apply.)
A. Primitives are passed by reference.
B. Primitives are passed by value.
C. References are passed by reference.
D. References are passed by value.
Back
D. transient
Front
3. What keyword is used to prevent an object from being serialized?
A. private
B. volatile
C. protected
D. transient
E. None of the above
Back
A. 32
Front
20. What is the value of x after the following line is executed?
x = 32 (31 - 10 3);
A. 32
B. 31
C. 3
D. 704
E. None of the above
Back
C. break
Front
13. Given the following code, what keyword must be used at line 4 in order to stop execution of the
for loop?
1. boolean b = true;
2. for (;;) {
3. if (b) {
4. <insert code>
5. }
6. // do something
7. }
A. stop
B. continue
C. break
D. None of the above
Back
D. "same" will be printed out to the console.
Front
26. What will be the output of the following code?
public class StringTest {
public static void main(String [] a) { String s1 = "test string";
String s2 = "test string"; if (s1 == s2) {
System.out.println("same");
} else { System.out.println("different");
}
}
}
A. The code will compile but not run.
B. The code will not compile.
C. "different" will be printed out to the console.
D. "same" will be printed out to the console.
E. None of the above.
Back
C. 12.3
Front
7. Consider the following application:
1. class Q7 {
2. public static void main(String args[]) {
3. double d = 12.3;
4. Decrementer dec = new Decrementer();
5. dec.decrement(d);
6. System.out.println(d);
7. }
8. } 9.
10. class Decrementer {
11. public void decrement(double decMe) {
12. decMe = decMe - 1.0;
13. }
14. }
What value is printed out at line 6?
A. 0.0
B. 1.0
C. 12.3
D. 11.3
Back
C. char c = '\u1234';
Front
18. Which of the following are legal?
A. char c = 0x1234;
B. char c = \u1234;
C. char c = '\u1234';
Back
B. Static method names
C. Static field names
Front
14. Which of the following may be statically imported? (Choose all that apply.)
A. Package names
B. Static method names
C. Static field names
D. Method-local variable names
Back
A. BigOlLongStringWithMeaninglessName
B. $int
C. bytes
D. $1
E. finalist
Front
2. Choose the valid identifiers from those listed here. (Choose all that apply.)
A. BigOlLongStringWithMeaninglessName
B. $int
C. bytes
D. $1
E. finalist
Back
B. int x = 6; if (!(x > 3)) {}
C. int x = 6; x = ~x;
Front
2. Which of the following expressions are legal? (Choose all that apply.)
A. int x = 6; x = !x;
B. int x = 6; if (!(x > 3)) {}
C. int x = 6; x = ~x;
Back
C. x = 13, a = 7, b = 8
Front
1. After execution of the following code fragment, what are the values of the variables x, a, and b?
1. int x, a = 6, b = 7;
2. x = a++ + b++;
A. x = 15, a = 7, b = 8
B. x = 15, a = 6, b = 7
C. x = 13, a = 7, b = 8
D. x = 13, a = 6, b = 7
Back
Section 2
(35 cards)
B. A class
C. An interface
Front
19. Which of the following may appear on the right-hand side of an instanceof operator? (Choose all that apply.)
A. A reference
B. A class
C. An interface
D. A variable of primitive type
E. The name of a primitive type
Back
E. Transient variables are not serialized.
Front
4. Which of the following statements is true?
A. Transient methods may not be overridden.
B. Transient methods must be overridden.
C. Transient classes may not be serialized.
D. Transient variables must be static.
E. Transient variables are not serialized.
Back
A. int x = -1; x = x >>> 5;
Front
3. Which of the following expressions results in a positive value in x?
A. int x = -1; x = x >>> 5;
B. int x = -1; x = x >>> 32;
C. byte x = -1; x = x >>> 5;
D. int x = -1; x = x >> 5;
Back
E. The code compiles and execution produces the output x = 3.
Front
5. Which statement is true about this application?
1. class StaticStuff
2 {
3. static int x = 10; 4.
5. static { x += 5; } 6.
7. public static void main(String args[])
8. {
9. System.out.println("x = " + x);
10. } 11.
12. static {x /= 5; }
13. }
A. Lines 5 and 12 will not compile because the method names and return types are missing.
B. Line 12 will not compile because you can only have one static initializer.
C. The code compiles and execution produces the output x = 10.
D. The code compiles and execution produces the output x = 15.
E. The code compiles and execution produces the output x = 3.
Back
A. Yes
Front
10. Is it possible to define a class called Thing so that the following method can return true under certain circumstances?
boolean weird(Thing s) { Integer x = new Integer(5); return s.equals(x);
}
A. Yes
B. No
Back
A. public
C. protected
D. Default
Front
16. Suppose class A has a method called doSomething(), with default access. Suppose class B extends A and overrides doSomething(). Which access modes may apply to B's version of doSomething()? (Choose all that apply.)
A. public
B. private
C. protected
D. Default
Back
D. A boolean
Front
17. What is the return type of the instanceof operator?
A. A reference
B. A class
C. An int
D. A boolean
Back
Front
3. What is the minimal modification that will make this code compile correctly?
1. final class Aaa
2. {
3. int xxx;
4. void yyy() { xxx = 1; }
5. } 6.
7.
8. class Bbb extends Aaa
9. {
10. final Aaa finalref = new Aaa(); 11.
12. final void yyy()
13. {
14. System.out.println("In method yyy()");
15. finalref.xxx = 12345;
16. }
17. }
A. On line 1, remove the final modifier.
B. On line 10, remove the final modifier.
C. Remove line 15.
D. On lines 1 and 10, remove the final modifier.
E. The code will compile as is. No modification is needed.
Back
E. The program compiles and the output is x = 104.
Front
6. Which statement is true about this code?
1. class HasStatic
2. {
3. private static int x = 100; 4.
5. public static void main(String args[])
6. {
7. HasStatic hs1 = new HasStatic();
8. hs1.x++;
9. HasStatic hs2 = new HasStatic();
10. hs2.x++;
11. hs1 = new HasStatic();
12. hs1.x++;
13. HasStatic.x++;
14. System.out.println("x = " + x);
15. }
16. }
A. Line 8 will not compile because it is a static reference to a private variable.
B. Line 13 will not compile because it is a static reference to a private variable.
C. The program compiles and the output is x = 102.
D. The program compiles and the output is x = 103.
E. The program compiles and the output is x = 104.
Back
B. 3
Front
6. What is 7 % -4?
A. -3
B. 3
C. -4
D. 4
Back
B. Throws an exception.
Front
9. What does the following code do?
Integer i = null;
if (i != null & i.intValue() == 5) System.out.println("Value is 5");
A. Prints "Value is 5".
B. Throws an exception.
Back
C. int
Front
12. When a byte is added to a char, what is the type of the result?
A. byte
B. char
C. int
D. short
E. You can't add a byte to a char.
Back
C. String x = "Hello"; int y = 9; x = x + y;
A. String x = "Hello"; int y = 9; x += y;
Front
4. Which of the following expressions are legal? (Choose all that apply.)
A. String x = "Hello"; int y = 9; x += y;
B. String x = "Hello"; int y = 9; if (x == y) {}
C. String x = "Hello"; int y = 9; x = x + y;
D. String x = "Hello"; int y = 9; y = y + x;
Back
A. default String s;
D. abstract double d;
E. abstract final double hyperbolicCosine();
Front
1. Which of the following declarations are illegal? (Choose all that apply.)
A. default String s;
B. transient int i = 41;
C. public final static native int w();
D. abstract double d;
E. abstract final double hyperbolicCosine();
Back
C. The class will compile if it is declared abstract.
D. The class may not be instantiated.
Front
13. Suppose interface Inty defines five methods. Suppose class Classy declares that it implements
Inty but does not provide implementations for any of the five interface methods. Which is/are true?
A. The class will not compile.
B. The class will compile if it is declared public.
C. The class will compile if it is declared abstract.
D. The class may not be instantiated.
Back
A. A reference
Front
18. Which of the following may appear on the left-hand side of an instanceof operator?
A. A reference
B. A class
C. An interface
D. A variable of primitive type
Back
A. -3
Front
5. What is -8 % 5?
A. -3
B. 3
C. -2
D. 2
Back
A. Classes
B. Data
C. Methods
Front
14. Which of the following may be declared final? (Choose all that apply.)
A. Classes
B. Data
C. Methods
Back
D. transient
Front
8. Which modifier or modifiers should be used to denote a variable that should not be written out as part of its class's persistent state? (Choose the shortest possible answer.)
A. private
B. protected
C. private protected
D. transient
E. volatile
Back
B. A final class may not have any abstract methods.
Front
2. Which of the following statements is true?
A. An abstract class may not have any final methods.
B. A final class may not have any abstract methods.
Back
D. -25
Front
20. What is -50 >> 1?
A. A negative number with very large magnitude.
B. A positive number with very large magnitude.
C. -100
D. -25
E. 100
F. 25
Back
F. None of the above.
Front
12. Which of the following statements are true?
A. An abstract class may be instantiated.
B. An abstract class must contain at least one abstract method.
C. An abstract class must contain at least one abstract data field.
D. An abstract class must be overridden.
E. An abstract class must declare that it implements an interface.
F. None of the above.
Back
C. The output: value is 9.0
Front
8. What results from attempting to compile and run the following code?
1. public class Conditional {
2. public static void main(String args[]) {
3. int x = 4;
4. System.out.println("value is " +
5. ((x > 4) ? 99.99 : 9));
6. }
7. }
A. The output: value is 99.99
B. The output: value is 9
C. The output: value is 9.0
D. A compiler error at line 5
Back
A. It always returns 0.
Front
14. Which statement is true about the following method?
int selfXor(int i) { return i ^ i;
}
A. It always returns 0.
B. It always returns 1.
C. It always an int where every bit is 1.
D. The returned value varies depending on the argument.
Back
D. None of these
Front
15. Which of the following operations might throw an ArithmeticException?
A. >>
B. >>>
C. <<
D. None of these
Back
A. public
B. protected
Front
11. Suppose class Supe, in package packagea, has a method called doSomething(). Suppose class Subby, in package packageb, overrides doSomething(). What access modes may Subby's version of the method have? (Choose all that apply.)
A. public
B. protected
C. Default
D. private
Back
D. A final class may not be extended.
Front
18. Which of the following statements are true?
A. A final class must be instantiated.
B. A final class must contain at least one final method.
C. A final class must contain at least one final data field.
D. A final class may not be extended.
E. None of the above.
Back
B. The output: b contains 5
Front
7. What results from running the following code?
1. public class Xor {
2. public static void main(String args[]) {
3. byte b = 10; // 00001010 binary
4. byte c = 15; // 00001111 binary
5. b = (byte)(b ^ c);
6. System.out.println("b contains " + b);
7. }
8. }
A. The output: b contains 10
B. The output: b contains 5
C. The output: b contains 250
D. The output: b contains 245
Back
B. No
Front
11. Suppose ob1 and ob2 are references to instances of java.lang.Object. If (ob1 == ob2) is
false, can ob1.equals(ob2) ever be true?
A. Yes
B. No
Back
D. A final class may not be extended.
Front
19. Which of the following statements are true?
A. A final class must be instantiated.
B. A final class may only contain final methods.
C. A final class may not contain non-final data fields.
D. A final class may not be extended.
E. None of the above.
Back
D. -1
Front
20. What does the following code print?
public class A
{
static int x;
public static void main(String[] args) { A that1 = new A();
A that2 = new A(); that1.x = 5; that2.x = 1000;
x = -1; System.out.println(x);
}
}
A. 0
B. 5
C. 1000
D. -1
Back
B. Data
C. Methods
D. Code blocks enclosed in curly brackets
Front
15. Which of the following may follow the static keyword? (Choose all that apply.)
A. Class definitions
B. Data
C. Methods
D. Code blocks enclosed in curly brackets
Back
D. line 3: private; line 8: protected
Front
7. Given the following code, and making no other changes, which combination of access modifiers (public, protected, or private) can legally be placed before aMethod() on line 3 and be placed before aMethod() on line 8?
1. class SuperDuper
2. {
3. void aMethod() { }
4. } 5.
6. class Sub extends SuperDuper
7. {
8. void aMethod() { }
9. }
A. line 3: public; line 8: private
B. line 3: protected; line 8: private
C. line 3: default; line 8: private
D. line 3: private; line 8: protected
E. line 3: public; line 8: protected
Back
C. float
Front
13. When a short is added to a float, what is the type of the result?
A. short
B. int
C. float
D. You can't add a short to a float.
Back
D. /
Front
16. Which of the following operations might throw an ArithmeticException?
A. +
B. -
C. *
D. /
E. None of these