You are on page 1of 12

Java 6 ZC12110-5QSQ-SGYF ZC12110-5QSQ-SGYF Java 6 ZC12110-QUYR-ZYXE Java 5 Fundamentals ZC12086-NLF5-PDH8

Java 5 Fundamentals Progress:

Why do you provide accessor methods in a class rather than making the class's fields publicly accessible? Choice 1 They are automatically available to other tasks using the RMI subsystem. Public fields cannot be remotely accessed. Choice 2 They can be made accessible to classes in other packages. Public fields are onl y usable from the same package. Choice 3 They can ensure data integrity by validating the proposed value. Any value coul d be written to a public field. ******** Choice 4 They can prevent memory overwrites by performing bounds checks on arrays. Publi c fields are not checked for bounds overrun. Choice 5 They improve performance by avoiding a context switch in the bytecode interpret er. Accessing a public field requires loading the object's data pointer. Java 5 Fundamentals, Question 1 of 40

Take a 15 minute break AFTER this question Copyright 2010 Brainbench All Rights Reserved. What is the purpose of using a thread pool? Choice 1 To schedule tasks based upon a non-standard priority Choice 2 To avoid recreating Thread objects when they complete their task ************* Choice 3 To swap tasks among executing threads Choice 4 To avoid recreating Runnable objects when they complete their task Choice 5 To ensure newly created threads all share the same priority, group, and daemon status Java 5 Fundamentals, Question 2 of 40 Sample Code What is the output from the sample code above? Choice 1 Result is 4.12 Choice 2 Result is 5.11 Choice 3 Result is 6.1 ************* Choice 4 Result is 23.11 Choice 5 Result is 24.11 Java 5 Fundamentals, Question 3 of 40 How does Sun recommend that Java package namespaces be used in order to guaran tee unique namespaces even when installing third party packages? Choice 1 Register the package name at java.sun.com. Choice 2 Reverse a registered domain name. Choice 3 Use the head developer's name in the package names. Choice 4 Use the name of your company as the whole package name. Choice 5 Use the product's name. *********** Java 5 Fundamentals, Question 4 of 40 In the sample code above, on which line do you place a documentation comment t hat describes the purpose of the class DocumentationSample? Choice 1 Line A Choice 2 Line B Choice 3 Line C *********** Choice 4 Line D

Choice 5 Line E Java 5 Fundamentals, Question 5 of 40 When do you override the finalize() method? Choice 1 When you want to kill a thread Choice 2 When there is cleanup activity needed before an object is destroyed ********** Choice 3 When you instantiate a final class Choice 4 When the object is declared on the heap so that its memory may be reclaimed Choice 5 When an object is no longer needed Java 5 Fundamentals, Question 6 of 40 Referring to the sample code above, in the getDifference() method, to which on e of the following do you set the local variable diff so that the number of seco nds elapsed is returned? Choice 1 cal2.get(java.util.Calendar.SECOND) - cal1.get(java.util.Calendar.SECOND) Choice 2 (cal2.getTime().getTime() - cal1.getTime().getTime()) / 1000 Choice 3 (long) (cal2 - cal1) Choice 4 cal2.getTimeInMillis() - cal1.getTimeInMillis() ***** Choice 5 (cal2 - cal1) / System.currentTimeMillis() Java 5 Fundamentals, Question 7 of 40 What is the output when you invoke the class in the sample code above from the command line? Choice 1 Finished creating the deck Finished creating Creating an Object Choice 2 Finished creating the deck ************** Creating an Object Finished creating Choice 3 Creating an Object Finished creating the deck Finished creating Choice 4 Creating an Object Finished creating Finished creating the deck Choice 5 Finished creating Creating an Object Finished creating the deck Java 5 Fundamentals, Question 8 of 40 What is the value of b when the execution of the sample code above reaches Lin e A?

Choice 0 Choice 6 Choice 7 Choice 8 Choice 14

1 2 3 4 5 Java 5 Fundamentals, Question 9 of 40 *************

What is the potential usage error in the sample code above? Choice 1 The two objects may represent the same date but do not satisfy dv1==dv2. Choice 2 System.out may have been redirected away from the console. Choice 3 The dv1==dv2 comparison may fail if DateValue does not override the equals() me thod. ******** Choice 4 The println statement may fail if DateValue does not implement toString(). Choice 5 System.out.println() may throw an IOException that is not caught or rethrown by printIfEqual. Java 5 Fundamentals, Question 10 of 40 Where is the data representing the internal state of a Java object held? Choice 1 Exceptions Choice 2 Methods Choice 3 Method arguments Choice 4 Packages Choice 5 Member variables **** Java 5 Fundamentals, Question 11 of 40 What is the purpose of acquiring an object's monitor by using a synchronized(obj ect) {} construct before accessing the object's resources? Choice 1 To prevent flicker on the user's screen during updates that cover more than 80 percent of the display area Choice 2 To prevent a deadlock or race situation from occurring between multiple threads during event handling Choice 3 To ensure that objects accessed on remote machines have their dates expressed i n the local time zone Choice 4 To prevent multiple threads from accessing the same resource at the same time, which could leave the resource in an undefined state ************** Choice 5 To establish scheduling priority over other threads so that the bytecode interp reter gives more processor time to the synchronized thread Java 5 Fundamentals, Question 12 of 40

Referring to the above sample code, what does the array named bArray contain a fter execution? Choice 1 The status of ByteArrayOutputStream b (0x20 open, 0x21 closed) Choice 2 **************** A serialized version of a StringBuffer object string Hello Choice 3 Unicode values for each character in Hello Choice 4 A hash code created from StringBuffer Choice 5 A reference to ByteOutputStream b Java 5 Fundamentals, Question 13 of 40 String s = "Hello, World"; s.replace('o', 'u'); s.toUpperCase(); System.out.println(s.substring(7)); After manipulating the string in the sample code above, what is printed? Choice 1 Wurld Choice 2 world Choice 3 WORLD Choice 4 WURLD ********** Choice 5 World Java 5 Fundamentals, Question 14 of 40 How do you define the enumeration representing the suits in a standard playing c ard deck? Choice 1 public class Suit { enum CLUBS; enum DIAMONDS; enum HEARTS; enum SPADES; } Choice 2 public enumeration Suit { CLUBS, DIAMONDS, HEARTS, SPADES } Choice 3 public enum Suit { CLUBS, DIAMONDS, HEARTS, SPADES } Choice 4 public enum Suit { int CLUBS = 0; int DIAMONDS = 1; int HEARTS = 2; int SPADES = 3; } Choice 5

public class Suit extends Enum { CLUBS, DIAMONDS, HEARTS, SPADES } Java 5 Fundamentals, Question 15 of 40 How do you define the enumeration representing the suits in a standard playing card deck? Choice 1 public class Suit { enum CLUBS; enum DIAMONDS; enum HEARTS; enum SPADES; } Choice 2 public enumeration Suit { CLUBS, DIAMONDS, HEARTS, SPADES ******* } Choice 3 public enum Suit { CLUBS, DIAMONDS, HEARTS, SPADES } Choice 4 public enum Suit { int CLUBS = 0; int DIAMONDS = 1; int HEARTS = 2; int SPADES = 3; } Choice 5 public class Suit extends Enum { CLUBS, DIAMONDS, HEARTS, SPADES } Java 5 Fundamentals, Question 15 of 40

Which one of the following statements returns the IP address of www.brainbench .com? Choice 1 String ip=InetAddress.DNSLookup("www.brainbench.com"); Choice 2 InetAddress ip=InetAddress.getByName("www.brainbench.com"); Choice 3 InetAddress ip=Socket.DNSLookup("www.brainbench.com"); Choice 4 InetAddress ip=System.getHostByName("www.brainbench.com"); ********** Choice 5 InetAddress ip=new InetAddress("www.brainbench.com"); Java 5 Fundamentals, Question 16 of 40 What happens when you add a primitive data type into a collection? Choice 1 A compilation error occurs. Choice 2 The data type is converted to a String and then added. Choice 3

The data type n added. Choice 4 The primitive Choice 5 The data type Java 5

is automatically boxed into the appropriate wrapper class and the data type is added as is. is converted into a Double and then added. Fundamentals, Question 17 of 40

What is the output from running the command java TestSub after compiling the s ample code above? Choice 1 SuperClass SuperClass Choice 2 SuperClass SubClass Choice 3 SubClass Super-part 2 ************* Choice 4 SubClass SuperClass Choice 5 SubClass SubClass Java 5 Fundamentals, Question 18 of 40 int i = 5; if (i++ == 5 || false) { i += i++; } System.out.println(i); When the sample code above is executed, what is the value of i? Choice 1 5 Choice 2 6 Choice 3 10 Choice 4 11 ************* Choice 5 12 Java 5 Fundamentals, Question 19 of 40 32 java int Where does the Java virtual machine keep space for local method variables? Choice 1 With hotspot Choice 2 In the heap Choice 3 In the reference pool Choice 4 The shared memory queue

Choice 5 On the stack ********** Java 5 Fundamentals, Question 21 of 40 Where do you add @SuppressWarnings("fallthrough") to the sample code above in order for the following command to NOT generate any warnings? javac -Xlint:fallthrough Test.java Choice 1 Before each case clause that falls through Choice 2 Within the javadoc for the main method Choice 3 Within the javadoc for the class ********* Choice 4 Above the main method declaration Choice 5 Immediately above the switch statement Java 5 Fundamentals, Question 22 of 40 int f = 2; int g = 5; int h; h = 3+f/g+2; What is the value of h after you execute the sample code above? Choice 1 2 Choice 2 5 Choice 3 5.2 Choice 4 5.4 *************** Choice 5 6 Java 5 Fundamentals, Question 24 of 40 Casting a short to which one of the following may result in a loss of informa tion? Choice 1 int Choice 2 float Choice 3 double Choice 4 long Choice 5 byte ********** Java 5 Fundamentals, Question 25 of 40 Sample Code

for (int j=0;j<=20;j++) { j++; System.out.println(j); } System.out.println(j); // Line A What is the result when the execution of the sample code above reaches line A? Choice 1 The value of j is 0 Choice 2 The value of j is 20 Choice 3 The value of j is 22 Choice 4 An IndexOutOfBoundsException is thrown Choice 5 There is a compilation error ******* Java 5 Fundamentals, Question 26 of 40 * The (horizontal/vertical) distances of point (width/height) */ public int width, height; Referring to the sample code above, what comments are in the generated javadoc for the variables width and height? Choice 1 width gets The (horizontal/vertical) distances of point (width/height) height gets The (horizontal/vertical) distances of point (width/height) Choice 2 width gets The vertical distances of point height height gets The horizontal distances of point width Choice width height The Choice width height Choice width The height 3 gets nothing gets (horizontal/vertical) distances of point (width/height) 4 gets The horizontal distances of point width gets The vertical distances of point height 5 gets (horizontal/vertical) distances of point (width/height) *************** gets nothing Java 5 Fundamentals, Question 27 of 40

What does the sample code above do? Choice 1 It prints "Hello" two times. Choice 2 It prints "Hello" three times. Choice 3 It prints "Hello" 11 times. Choice 4 It does not compile because variable i has been declared twice. Choice 5

It does not compile because doIt() cannot reference non-static variable i. Java 5 Fundamentals, Question 28 of 40 Code MessageFormat format = new MessageFormat( "First {2} Second {1}"); String[] input = {"one", "two", "three"}; System.out.println(format.format(input)); When Choice First Choice First Choice First Choice First Choice First the sample code above is executed, what is printed out? 1 three Second two 2 Second 3 two Second three 4 two Second one ****** 5 one Second two Java 5 Fundamentals, Question 29 of 40

Which one of the following classes do you subclass in order to package several locale-specific versions of a set of greetings? Choice 1 java.text.CollationKey Choice 2 java.text.RuleBasedCollator Choice 3 java.util.TimeZone Choice 4 java.util.ResourceBundle ****** Choice 5 java.lang.Cloneable Java 5 Fundamentals, Question 30 of 40 When you call the deleteOnExit() method for a File, at what point does the file get deleted? Choice 1 When the current method ends Choice 2 When the virtual machine exits Choice 3 When the current thread ends Choice 4 When you close the file ************ Choice 5 When all the threads in the current thread group end Java 5 Fundamentals, Question 31 of 40

After execution, what is the output of the above sample code? Choice 1 0 Choice 2 4 Choice 3 5 Choice 4

6 Choice 5 10 ****************** Java 5 Fundamentals, Question 32 of 40 Which keyword hides a field from all code EXCEPT from the methods local to the class that holds the field? Choice 1 public Choice 2 void Choice 3 protected Choice 4 final Choice 5 private ********* Java 5 Fundamentals, Question 33 of 40 Which one of the following statements is true for a non-abstract class that impl ements the Iterator interface? Choice 1 It is used to store associative arrays. Choice 2 It is an implementation of the Collection interface. Choice 3 It works with the StringTokenizer class. Choice 4 It has implementations of the nextElement() and hasMoreElements() methods. *** **** Choice 5 It contains implementations of the hasNext() and next() methods. Java 5 Fundamentals, Question 34 of 40 When subclassing the Thread class, which one of the following is a LIMITATION on the subclass? Choice 1 It must declare the class final. Choice 2 It must catch the ThreadDeath exception. Choice 3 It cannot subclass any other class. ************ Choice 4 It is forced to declare all of its methods static. Choice 5 It must implement the ThreadPolicy interface. Java 5 Fundamentals, Question 35 of 40 What Choice A A A Choice A A A Choice A A B Choice A A B Choice A B C is the output from the sample code above? 1 B C A A A B C A A A B C 2 B C B C 3 B C A C A 4 C B B 5 A B C A B C

Java 5 Fundamentals, Question 36 of 40 You use an ArrayList as the implementation for a List collection. Referring to the scenario above, what happens when you add an element that exc eeds the ArrayList's capacity? Choice 1 This type of error cannot be trapped by the code. Choice 2 The call throws an ArrayIndexOutOfBounds exception. ******** Choice 3 The add() call returns with a value of -1 rather than the index. Choice 4 The virtual machine terminates the application. Choice 5 The ArrayList expands automatically to fit the addition. Java 5 Fundamentals, Question 37 of 40 public class Foo { public String bar = "hello, world"; } The class Foo in the sample code above extends which one of the following clas ses? Choice 1 java.lang.Runtime Choice 2 java.lang.Class Choice 3 java.lang.Base Choice 4 java.lang.Core Choice 5 java.lang.Object ***** Java 5 Fundamentals, Question 38 of 40 EnhancedForStatement: for ( Type Identifier : Expression ) Statement As defined in the sample code above, what interface must the instance variable obtained from Expression implement in order to use it with the "enhanced for lo op" construct? Choice 1 Enumeration Choice 2 Queue Choice 3 Iterable *********** Choice 4 Collection Choice 5 Map Java 5 Fundamentals, Question 39 of 40

You might also like