133
1 293702. Which of the following is NOT part of the definition of a class? ? 293702. It may have superclasses and subclasses 293702. It defines properties and their types 293702. It may have methods 293702. It is an active object (***) 293703. Java's security manager does NOT check ? 293703. read<font face="Symbol">&#164;</font>write file permissions 293703. network connections (***) 293703. subscripts which are out-of-range 293703. access to system properties 293704. Java's reflection package contains methods for ? 293704. doing garbage collection 293704. finding the methods of a class 293704. designing components (***) 293704. reformatting windows 293705. JDBC is ? 293705. Java's event delegation model 293705. Java's remote relational database interface 293705. Java's persistent object interface 293705. Java Database Connectivitive (***) 293706. A Jar file ? 293706. is a source file 293706. is an object file (***) 293706. keeps track of versions 293706. may contain many files 293707. An "appletcation" does NOT need which of the following methods? ? 293707. init( ) 293707. main( ) 293707. start( ) (***) 293707. exit( ) 293708. What is the main disadvantage of Java garbage collection? ? 293708. It cannot run in parallel with other threads. 293708. It is slow. (***) 293708. It uses a heap. 293708. It uses the system's memory allocation 293709. A Swing panel is a kind of ? 293709. container (***) 293709. event 293709. thread. 293709. dialog box 293710. A Java thread ?

Cse Test Java2 Filepdf Mrmai Full

Embed Size (px)

DESCRIPTION

f

Citation preview

1

293702. Which of the following is NOT part of the definition of a class? ?

293702. It may have superclasses and subclasses

293702. It defines properties and their types

293702. It may have methods

293702. It is an active object (***)

293703. Java's security manager does NOT check ?

293703. read<font face="Symbol">&#164;</font>write file permissions

293703. network connections (***)

293703. subscripts which are out-of-range

293703. access to system properties

293704. Java's reflection package contains methods for ?

293704. doing garbage collection

293704. finding the methods of a class

293704. designing components (***)

293704. reformatting windows

293705. JDBC is ?

293705. Java's event delegation model

293705. Java's remote relational database interface

293705. Java's persistent object interface

293705. Java Database Connectivitive (***)

293706. A Jar file ?

293706. is a source file

293706. is an object file (***)

293706. keeps track of versions

293706. may contain many files

293707. An "appletcation" does NOT need which of the following methods? ?

293707. init( )

293707. main( )

293707. start( ) (***)

293707. exit( )

293708. What is the main disadvantage of Java garbage collection? ?

293708. It cannot run in parallel with other threads.

293708. It is slow. (***)

293708. It uses a heap.

293708. It uses the system's memory allocation

293709. A Swing panel is a kind of ?

293709. container (***)

293709. event

293709. thread.

293709. dialog box

293710. A Java thread ?

2

293710. is created by calling a Thread constructor. (***)

293710. is started by calliing "init( )"

293710. can wait for at most one device.

293710. is a separate process.

293711. RMI does NOT use ?

293711. serialization (***)

293711. stubs and skeletons

293711. a special class loader

293711. a special compiler

293712. Which of the following is NOT true of a Java bean? ?

293712. All of its properties x have a "getx( )" method, where x is any property name.

293712. It uses the AWT event delegation model. (***)

293712. It is stored in a ".bean" file.

293712. It has a constructor function which has no arguments.

293713. The "event delegation" model of AWT 1.1 ?

293713. allows one bean to throw an event to another bean.

293713. allows one event to be heard by several listeners.

293713. uses delegates to inform listeners. (***)

293713. uses multicasting TCP<font face="Symbol">&#164;</font>IP sockets.

293714. A call to "sleep(milliseconds)" must be nested inside of ?

293714. a "synchronized" statement.

293714. a "try-catch" statement.

293714. a window

293714. an inner class (***)

293715. Analyze the following code:

<BR>

<BR>

abstract class Test implements Runnable {

<BR>

public void doSomething() {

<BR>

};

<BR>

}

<BR>

?

293715. The program will not compile because it does not implement the run() method.

293715. The program will not compile because it does not contain abstract methods.

293715. The program compiles fine. (***)

293715. None of the other answers

293716. Analyze the following code:

<BR>

3

<BR>

class Test extends Thread {

<BR>

public static void main(String[] args) {

<BR>

Thread t = new Thread(this);

<BR>

t.start();

<BR>

}

<BR>

<BR>

public void run() {

<BR>

System.out.println("test");

<BR>

}

<BR>

}

<BR>

?

293716. The program does not compile because this cannot be referenced in a static method.

293716. The program compiles fine, but it does not print anything because t does not invoke the run() method. (***)

293716. The program compiles and runs fine and displays test on the console.

293716. None of the other answers

293717. When you run the following program, what will happen?

<BR>

<BR>

class Test extends Thread {

<BR>

public static void main(String[] args) {

<BR>

Test t = new Test();

<BR>

t.start();

<BR>

t.start();

<BR>

}

<BR>

<BR>

public void run() {

<BR>

4

System.out.println("test");

<BR>

}

<BR>

}

<BR>

?

293717. Nothing is displayed.

293717. The program displays test twice. (***)

293717. The program has a runtime error because the thread t was started twice.

293717. The program displays test once.

293718. Analyze the following code:

<BR>

<BR>

class Test implements Runnable {

<BR>

public static void main(String[] args) {

<BR>

Test t = new Test();

<BR>

t.start();

<BR>

}

<BR>

<BR>

public void run() {

<BR>

}

<BR>

}

<BR>

<BR>

?

293718. The program does not compile because the start() method is not defined in the Test class.

293718. The program compiles, but it does not run because the start() method is not defined.

293718. The program compiles and runs fine.

293718. The program compiles, but it does not run because the run() method is not implemented. (***)

293719. Analyze the following code:

<BR>

<BR>

class Test implements Runnable {

<BR>

5

public static void main(String[] args) {

<BR>

Test t = new Test();

<BR>

}

<BR>

<BR>

public Test() {

<BR>

Thread t = new Thread(this);

<BR>

t.start();

<BR>

}

<BR>

<BR>

public void run() {

<BR>

System.out.println("test");

<BR>

}

<BR>

}

<BR>

<BR>

?

293719. The program has a compilation error because t is defined in both the main() method and the constructor

Test().

293719. The program compiles fine, but it does not run because you cannot use the keyword this in the constructor.

(***)

293719. The program compiles and runs and displays test.

293719. The program compiles and runs and displays nothing.

293720. Which of the following methods is a static method in Thread? ?

293720. sleep()

293720. resume()

293720. start() (***)

293720. setPriority()

293721. Which of the following methods in Thread throws InterruptedException? ?

293721. suspend()

293721. sleep() (***)

293721. resume()

293721. start()

293722. Which of the following methods is (are) not defined in ThreadGroup? ?

6

293722. suspend()

293722. setMaxPriority() (***)

293722. start()

293722. stop()

293723. Given the following code, which set of code can be used to replace the comment so that the program

displays time to the console every second?

<BR>

<BR>

import java.applet.*;

<BR>

import java.util.*;

<BR>

<BR>

class Test extends Applet implements Runnable {

<BR>

public void init() {

<BR>

Thread t = new Thread(this);

<BR>

t.start();

<BR>

}

<BR>

<BR>

public void run() {

<BR>

for(; ;) {

<BR>

<font face="Symbol">&#164;</font><font face="Symbol">&#164;</font>display time every second

<BR>

System.out.println(new Date().toString());

<BR>

}

<BR>

}

<BR>

}

<BR>

?

293723. try { sleep(1000); }

<BR>

catch(InterruptedException e) { }

<BR>

7

293723. try { t.sleep(1000); }

<BR>

catch(InterruptedException e) { }

<BR>

293723. try { Thread.sleep(1000); }

<BR>

catch(InterruptedException e) { }

<BR>

(***)

293723. try { Thread.sleep(1000); }

<BR>

catch(RuntimeException e) { }

<BR>

293724. Which method do you have to override if you implement the Runnable interface? ?

293724. start()

293724. stop()

293724. init()

293724. run() (***)

293725. Why does the following class have a syntax error?

<BR>

<BR>

import java.applet.*;

<BR>

<BR>

class Test extends Applet implements Runnable {

<BR>

public void init() throws InterruptedException {

<BR>

Thread t = new Thread(this);

<BR>

t.sleep(1000);

<BR>

}

<BR>

<BR>

public synchronized void run() {

<BR>

}

<BR>

}

<BR>

?

8

293725. The sleep() method is not invoked correctly; it should be invoked as Thread.sleep(1000).

293725. You cannot put the keyword synchronized in the run() method.

293725. The sleep() method should be put in the try-catch block. This is the only reason for the compilation failure.

(***)

293725. The init() method is defined in the Applet class, and it is overridden incorrectly because it cannot claim

exceptions in the subclass.

293726. Which of the following expressions must be true if you create a thread using Thread = new Thread(object)? ?

293726. object instanceof Thread

293726. object instanceof Frame (***)

293726. object instanceof Runnable

293726. object instanceof Applet

293727. Which of the following statements is correct to create a thread group and a new thread in the group? ?

293727. ThreadGroup tg = new ThreadGroup();

<BR>

Thread t1 = new Thread(tg, new Thread());

<BR>

293727. ThreadGroup tg = new ThreadGroup();

<BR>

Thread t1 = new Thread(tg, new Thread(" "));

<BR>

293727. ThreadGroup tg = new ThreadGroup(" ");

<BR>

Thread t1 = new Thread(tg, new Runnable());

<BR>

(***)

293727. ThreadGroup tg = new ThreadGroup(" ");

<BR>

Thread t1 = new Thread(tg, new Thread());

<BR>

293728. The keyword to synchronize methods in Java is __________. ?

293728. synchronize

293728. synchronizing

293728. synchronized (***)

293728. all of other answers

293729. The safe way to stop a thread in JDK 1.2 is __________. ?

293729. t = null;

293729. t.stop();

293729. t.suspend();

293729. t.destroy(); (***)

293730. How do you add a listener to an instance of the Timer class? ?

293730. You cannot add a listener in the Timer constructor;

9

293730. You can use the addActionListener method in the Timer class to add a listenner. (***)

293730. A Timer object does not need a listener.

293730. None of the other answers

293731. Which of the following is incorrect? ?

293731. The wait(), notify(), and notifyAll() methods must be invoked from a synchronized method or a

synchronized block.

293731. When wait() is invoked, it pauses the thread and releases the lock on the object simultaneously. When the

thread is restarted after being notified, the lock is automatically reacquired.

293731. An except would occur if no thread is waiting on the object when the notify() method is invoked on the

object. (***)

293731. The notify() method can wake only one waiting thread.

293732. InputStream and OutputSteam are __________. ?

293732. The top-level abstract classes defined in the java.io package, from which all other stream classes inherit.

293732. The top-level abstract classes defined in the java.io package, from which all other byte stream classes inherit.

(***)

293732. Interfaces that define methods that can be used to read and write bytes.

293732. Classes that you can instantiate to read and write bytes.

293733. Which of the data type below could be used to store elements in their natural order based on the compareTo

method. ?

293733. HashMap

293733. TreeSet

293733. ArrayList.

293733. LinkedList. (***)

293734. Which of the following data types does not implement the Collection interface? ?

293734. Map.

293734. TreeSet

293734. LinkedList.

293734. ArrayList. (***)

293735. Which of the following data types do not have iterators? ?

293735. Map.

293735. TreeSet (***)

293735. LinkedList.

293735. ArrayList.

293736. If you want to store non-duplicated objects in the order in which they are inserted, you should use ___. ?

293736. HashSet

293736. LinkedHashSet (***)

293736. ArrayList

293736. TreeSet

293737. To get an iterator from a set, you may use the _______ method. ?

293737. getIterator

293737. findIterator

293737. iterators

10

293737. iterator (***)

293738. The elements in ________ are sorted. ?

293738. TreeSet (***)

293738. List

293738. HashSet

293738. HashMap

293739. Stack is a subclass of __________. ?

293739. ArrayList (***)

293739. LinkedList

293739. Vector

293739. AbstractList

293740. Which data type should you use if you want to store duplicate elements and be able to insert or delete

elements anywhere efficiently. ?

293740. Stack

293740. LinkedList

293740. Set

293740. Vector (***)

293741. To empty a Collection or a Map, you use the __________ method. ?

293741. empty

293741. clear

293741. setEmpty (***)

293741. zero

293742. The update methods are synchronized in the ___________ classe. ?

293742. HashSet

293742. LinkedList

293742. Vector (***)

293742. TreeMap

293743. Which of the following is correct to perform the set union of two sets s1 and s2. ?

293743. s1.union(s2)

293743. s1 + s2

293743. s1.addAll(s2)

293743. s1.add(s2) (***)

293744. Which of the following is correct to perform the set difference of two sets s1 and s2. ?

293744. None of the other answers

293744. s1 - s2

293744. s1.subtract(s2) (***)

293744. s1.removeAll(s2)

293745. Which of the following is correct to perform the set intersection of two sets s1 and s2. ?

293745. s1.merge(s2)

293745. s1.join(s2) (***)

293745. s1.retainAll(s2)

11

293745. s1.intersection(s2)

293746. Which method do you use to test if an element is a set or list named x? ?

293746. x.include(element)

293746. x.in(element)

293746. x.contains(element)

293746. x.contain(element) (***)

293747. Which method do you use to find the number of elements in a set or list named x? ?

293747. x.sizes()

293747. x.count()

293747. x.size()

293747. x.counts() (***)

293748. Which method do you use to remove an element from the a set or list named x? ?

293748. x.delete(element) (***)

293748. x.remove(element)

293748. x.deletes(element)

293748. x.removes(element)

293749. A Type 3 JDBC Driver is… ?

293749. A pure Java library that translates JDBC requests directly to a database specific protocol.

293749. Written partly in Java and partly in native code that communicates with the client API of a Database. To use

this type of driver, you must install some platform specific code in addition to the Java library.

293749. Translates JDBC to ODBC and relies on an ODBC driver to communicate with the database. Sun includes

the JDBC<font face="Symbol">&#164;</font>ODBC bridge with the JDK. The bridge is handy for testing,

however, it is not recommended for production use. (***)

293749. A pure Java client library that uses a Database-independent protocol to communicate database requests to a

server component. Which, then translates the request to a database specific protocol. The client library is

independent of the actual database, thus simplifying the deployment.

293750. Which of the following statements will delete all records from the Invoices table that have a value of 0 in the

InvoiceTotal field?

<BR>

String query = "DELETE FROM Invoices " +

<BR>

"WHERE InvoiceTotal = 0 ";

<BR>

Statement statement = connection.createStatement();

<BR>

?

293750. statement.executeQuery(query);

293750. statement.executeUpdate(query); (***)

293750. statement.deleteRows(query);

293750. statement.delete(query);

293751. JDBC defines Java Classes for: ?

293751. Result sets

293751. SQL statements

12

293751. Database metadata, Database connection

293751. All of the other answers (***)

293752. Which of the following is not an action of an applet: ?

293752. All are actions of an applet.

293752. It can initialize itself.

293752. It can perform a virus scan on your applications. (***)

293752. It can start running.

293753. The ____ method of the ServletRequest object returns the vlaue of the form element with a given name. ?

293753. getParameter (***)

293753. request

293753. servlets

293753. servlet

293754. You need a ____ to access a database from a Java program. ?

293754. JDBC (***)

293754. Servlet

293754. Connection

293754. ResultSet

293755. You use a ____ object to access a database from a Java

<BR>

program. ?

293755. Connection (***)

293755. JDBC

293755. ResultSet

293755. ODBC

293756. In Java, the result of a SQL query is returned in a ____ object. ?

293756. ResultSet (***)

293756. Connection

293756. JDBC

293756. Command

293757. The ____ method empties the PrintWriter's buffer <BR>and forwards all waiting characters to the

destination. ?

293757. flush (***)

293757. ServerSocket

293757. URLConnection

293757. push

293758. The ____ class is used by server applications to listen for client connections. ?

293758. ServerSocket (***)

293758. flush

293758. URLConnection

293758. ServerPort

293759. The ____ class makes it easy to communicate with a web server without having to issue HTTP commands. ?

13

293759. URLConnection (***)

293759. ServerSocket

293759. Socket

293759. UserDatagramSocket

293760. Which protocol defines the communication between

<BR>

web browsers and web servers? ?

293760. HTTP (***)

293760. SMX<font face="Symbol">&#164;</font>IX

293760. WWW

293760. TCP<font face="Symbol">&#164;</font>IP

293761. A ____ is a pointer to an information resource (such <BR>as a web page or an image) on the World Wide

<BR>Web. ?

293761. URL (***)

293761. socket

293761. server

293761. port

293762. In Java, which statement will establish a new TCP<font face="Symbol">&#164;</font>IP

<BR>

connection to a server, java.sun.com? ?

293762. Socket s = new Socket("java.sun.com", 80); (***)

293762. ServerSocket server = new ServerSocket(8000);

293762. Connection s = new Connection("java.sun.com", 80);

293762. connect("java.sun.com",80);

293763. In Java, a ____ is an object that encapsulates a TCP<font face="Symbol">&#164;</font>IP

<BR>

connection. ?

293763. socket (***)

293763. TCP<font face="Symbol">&#164;</font>IP

293763. URL

293763. HTTP

293764. In Java, you use ____ methods for object locking. ?

293764. synchronized (***)

293764. Unlock

293764. asynchronized

293764. Lock

293765. The ____ method temporarily releases an object

<BR>

lock and deactivtes the current thread. ?

293765. wait (***)

293765. sleeping

293765. sleep

293765. waitting

14

293766. When a thread is interrupted the most

<BR>

common response is ?

293766. to terminate the thread. (***)

293766. To throw the exception up to the caller.

293766. to ignore the interruption.

293766. to generate an InterruptedException.

293767. To begin execution of a thread call its ____

<BR>

method. ?

293767. start (***)

293767. do

293767. begin

293767. run

293768. The ____ method stops execution of the current thread for a given number of milliseconds. ?

293768. sleep (***)

293768. end

293768. stop

293768. interrupt

293769. What is the first step to take to run a thread? ?

293769. Write a class that extends the Thread class (***)

293769. Use the makeThread method of the System class.

293769. Write a class that implements the Thread interface.

293769. Use the ThreadFactory class to create a Thread.

293770. When a Thread object is started, the code in its

<BR>

____ method is executed in a new thread. ?

293770. run (***)

293770. start

293770. do

293770. begin

293771. To declare that a method should be terminated when a checked exception occurs within it, tag the method

with a ____ specifier. ?

293771. throws (***)

293771. through

293771. throw

293771. throwns

293772. All exceptions fall into either of two categories: ?

293772. checked and unchecked (***)

293772. RunTime and CompileTime

293772. good and badunchecked

293772. Exception and Errored

15

293773. Unchecked exceptions are ?

293773. the programmer's fault (***)

293773. the compiler's fault

293773. the system's fault

293773. the user's fault

293774. Which of the following values for x will not do this? <BR>Code: <BR>switch(x){ <BR>case(1):

<BR>System.out.println("1"); <BR>case(2): <BR>case(3): <BR>System.out.println("3"); <BR>break; <BR>default:

<BR>System.out.println("Default"); <BR>} ?

293774. 5

293774. 2

293774. 4 (***)

293774. 3

293775. You want SubClass in any package to have access to method of a SuperClass. Which most restric access

modifier that will accomplish this objective? ?

293775. public

293775. private

293775. transient

293775. protected (***)

293776. Given the following, <BR><BR>1. class MyThread extends Thread { <BR>2. <BR>3. public static void

main(String [] args) { <BR>4. MyThread t = new MyThread(); <BR>5. t.run(); <BR>6. } <BR>7. <BR>8. public

void run() { <BR>9. for(int i=1;i<FONT face=Symbol>&lt;</FONT>3;++i) { <BR>10. System.out.print(i + "..");

<BR>11. } <BR>12. } <BR>13. } <BR><BR>what is the result? ?

293776. An exception is thrown at runtime. (***)

293776. This code will not compile due to line 5.

293776. This code will not compile due to line 4.

293776. 1..2..3..

293777. Which&nbsp;of the following methods are defined in class Thread? ?

293777. dispose()

293777. wait()

293777. run() (***)

293777. notify()

293778. The following block of code creates a Thread using a Runnable target: <BR>Runnable target = new

MyRunnable(); <BR>Thread myThread = new Thread(target); <BR>Which of the following classes can be used to

create the target, so that the preceding code <BR>compiles correctly? ?

293778. public class MyRunnable implements Runnable{public void start(){}}

293778. public class MyRunnable extends Object{public void run(){}}

293778. public class MyRunnable implements Runnable{void run(){}}

293778. public class MyRunnable implements Runnable{public void run(){}} (***)

293779. Given the following,

<BR>

<BR>

16

1. class MyThread extends Thread {

<BR>

2.

<BR>

3. public static void main(String [] args) {

<BR>

4. MyThread t = new MyThread();

<BR>

5. t.start();

<BR>

6. System.out.print("one. ");

<BR>

7. t.start();

<BR>

8. System.out.print("two. ");

<BR>

9. }

<BR>

10.

<BR>

11. public void run() {

<BR>

12. System.out.print("Thread ");

<BR>

13. }

<BR>

14. }

<BR>

<BR>

what is the result of this code? ?

293779. Compilation fails

293779. An exception occurs at runtime. (***)

293779. The output cannot be determined.

293779. Thread one. Thread two.

293780. Given the following,

<BR>

1. public class MyRunnable implements Runnable {

<BR>

2. public void run() {

<BR>

3. <font face="Symbol">&#164;</font><font face="Symbol">&#164;</font> some code here

<BR>

4. }

<BR>

5. }

<BR>

17

<BR>

which of these will create and start this thread? ?

293780. new Runnable(MyRunnable).start();

293780. new Thread(MyRunnable).run();

293780. new MyRunnable().start();

293780. new Thread(new MyRunnable()).start(); (***)

293781. Given the following, <BR>1. class MyThread extends Thread { <BR>2. <BR>3. public static void

main(String [] args) { <BR>4. MyThread t = new MyThread(); <BR>5. Thread x = new Thread(t); <BR>6. x.start();

<BR>7. } <BR>8. <BR>9. public void run() { <BR>10. for(int i=0;i<FONT face=Symbol>&lt;</FONT>3;++i) {

<BR>11. System.out.print(i + ".."); <BR>12. } <BR>13. } <BR>14. } <BR>what is the result of this code? ?

293781. An exception occurs at runtime.

293781. 1..2..3..

293781. 0..1..2.. (***)

293781. 0..1..2..3..

293782. Given the following,

<BR>

1. class Test {

<BR>

2.

<BR>

3. public static void main(String [] args) {

<BR>

4. printAll(args);

<BR>

5. }

<BR>

6.

<BR>

7. public static void printAll(String[] lines) {

<BR>

8. for(int i=0;i<font face="Symbol">&#60;</font>lines.length;i++){

<BR>

9. System.out.println(lines[i]);

<BR>

10. Thread.currentThread().sleep(1000);

<BR>

11. }

<BR>

12. }

<BR>

13. }

<BR>

the static method Thread.currentThread() returns a reference to the currently executing Thread object. What is the

result of this code? ?

293782. Each String in the array lines will output, with a 1-second pause.

18

293782. Each String in the array lines will output, with no pause in between because this method is

<BR>

not executed in a Thread.

293782. This code will not compile. (***)

293782. Each String in the array lines will output, and there is no guarantee there will be a pause

<BR>

because currentThread() may not retrieve this thread.

293783. Assume you have a class that holds two private variables: a and b. Which of the following pairs can prevent

concurrent access problems in that class? (Choose all that apply.) ?

293783. public synchronized(this) int read(int a, int b){return a+b;} <BR>public synchronized(this) void set(int a, int

b){this.a=a;this.b=b;}

293783. public synchronized int read(int a, int b){return a+b;} <BR>public synchronized void set(int a, int

b){this.a=a;this.b=b;} (***)

293783. public int read(int a, int b){synchronized(a){return a+b;}} <BR>public void set(int a, int

b){synchronized(b){this.a=a;this.b=b;}}

293783. public int read(int a, int b){synchronized(a){return a+b;}} <BR>public void set(int a, int

b){synchronized(a){this.a=a;this.b=b;}}

293784. Which class or interface defines the wait(), notify(), and notifyAll() methods? ?

293784. Object (***)

293784. Thread

293784. Class

293784. Runnable

293785. Which two are true? ?

293785. When a thread invokes wait(), it releases its locks.

293785. If a class has synchronized code, multiple threads can still access the nonsynchronized code. (***)

293785. When a thread sleeps, it releases its locks.

293785. Variables can be protected from concurrent access problems by marking them with the synchronized

keyword.

293786. Which&nbsp;is methods of the Object class? ?

293786. interrupt();

293786. notifyAll(); (***)

293786. synchronized();

293786. isInterrupted();

293787. Given the following, <BR>1. public class WaitTest { <BR>2. public static void main(String [] args) <BR>3.

System.out.print("1 "); <BR>4. synchronized(args){ <BR>5. System.out.print("2 "); <BR>6. try { <BR>7.

args.wait(); <BR>8. } <BR>9. catch(InterruptedException e){} <BR>10. } <BR>11. System.out.print("3 ");

<BR>12. } <BR>13. } <BR>what is the result of trying to compile and run this program? ?

293787. At runtime, it throws an IllegalMonitorStateException when trying to wait.

293787. 1 2 3

293787. 1 2 (***)

293787. 1 3

293788. Assume the following method is properly synchronized and called from a thread A on an object B:

<BR>

19

wait(2000);

<BR>

After calling this method, when will the thread A become a candidate to get another turn at the CPU? ?

293788. After thread A is notified, or after two seconds. (***)

293788. After the lock on B is released, or after two

293788. Two seconds after lock B is released.

293788. Two seconds after thread A is notified.

293789. Assume you create a program and one of your threads (called backgroundThread) does some <BR>lengthy

numerical processing. What would be the proper way of setting its priority to try to get <BR>the rest of the system to

be very responsive while the thread is running? (Choose all that apply.) ?

293789. backgroundThread.setPriority(Thread.MIN_PRIORITY);

293789. backgroundThread.setPriority(Thread.MAX_PRIORITY);

293789. backgroundThread.setPriority(Thread.NO_PRIORITY);

293789. backgroundThread.setPriority(1); (***)

293790. Which three guarantee that a thread will leave the running state? ?

293790. aLiveThread.join()

293790. wait() (***)

293790. notify()

293790. notifyAll()

293791. Which two are true? ?

293791. The notify() method is overloaded to accept a duration.

293791. A thread will resume execution as soon as its sleep duration expires.

293791. The wait() method is overloaded to accept a duration. (***)

293791. Synchronization can prevent two objects from being accessed by the same thread.

293792. Which&nbsp;is valid constructors for Thread? ?

293792. Thread(Runnable r, int priority) (***)

293792. Thread(String name)

293792. Thread(Runnable r, ThreadGroup g)

293792. Thread(int priority)

293793. Given the following, <BR>class MyThread extends Thread { <BR>MyThread() { <BR>System.out.print("

MyThread"); <BR>} <BR>public void run() { <BR>System.out.print(" bar"); <BR>} <BR>public void run(String s)

{ <BR>System.out.println(" baz"); <BR>} <BR>} <BR>public class TestThreads { <BR>public static void main

(String [] args) { <BR>Thread t = new MyThread() { <BR>public void run() { <BR>System.out.println(" foo");

<BR>} <BR>}; <BR>t.start(); <BR>} <BR>} <BR><BR>what is the result? ?

293793. foo bar baz

293793. MyThread foo (***)

293793. foo bar

293793. MyThread bar

293794. Given the following, <BR>1. public class Test { <BR>2. public static void main (String [] args) { <BR>3.

final Foo f = new Foo(); <BR>4. Thread t = new Thread(new Runnable() { <BR>5. public void run() { <BR>6.

f.doStuff(); <BR>7. } <BR>8. }); <BR>9. Thread g = new Thread() { <BR>10. public void run() { <BR>11.

f.doStuff(); <BR>12. } <BR>13. }; <BR>14. t.start(); <BR>15. g.start(); <BR>16. } <BR>17. } <BR>1. class Foo {

<BR>2. int x = 5; <BR>3. public void doStuff() { <BR>4. if (x <FONT face=Symbol>&lt;</FONT> 10) { <BR>5.

20

<FONT face=Symbol>¤</FONT><FONT face=Symbol>¤</FONT> nothing to do <BR>6. try { <BR>7. wait();

<BR>8. } catch(InterruptedException ex) { } <BR>9. } else { <BR>10. System.out.println("x is " + x++); <BR>11.

if (x <FONT face=Symbol>&gt;</FONT>= 10) { <BR>12. notify(); <BR>13. } <BR>14. } <BR>15. } <BR>16. }

<BR><BR>what is the result? ?

293794. none of them (***)

293794. The code will not compile because of an error on line 7 of class Foo.

293794. The code will not compile because of some other error in class Test.

293794. The code will not compile because of an error on line 4 of class Test.

293795. Given the following,

<BR>

public class MyOuter {

<BR>

public static class MyInner {

<BR>

public static void foo() { }

<BR>

}

<BR>

}

<BR>

which statement, if placed in a class other than MyOuter or MyInner, instantiates an instance of the nested class? ?

293795. MyOuter.MyInner m = new MyOuter.MyInner(); (***)

293795. MyOuter.MyInner mi = new MyInner();

293795. MyInner mi = new MyOuter.MyInner();

293795. MyOuter m = new MyOuter();

<BR>

MyOuter.MyInner mi = m.new MyOuter.MyInner();

293796. Which istrue about a static nested class? ?

293796. It must extend the enclosing class.

293796. It can access to nonstatic members of the enclosing

293796. Its variables and methods must be static.

293796. It can be instantiated using new MyOuter.MyInner(); (***)

293797. Given the following, <BR>class Boo { <BR>Boo(String s) { } <BR>Boo() { } <BR>} <BR>class Bar

extends Boo { <BR>Bar() { } <BR>Bar(String s) {super(s);} <BR>void zoo() { <BR><FONT

face=Symbol>¤</FONT><FONT face=Symbol>¤</FONT> insert code here <BR>} <BR>} <BR>which two create

an anonymous inner class from within class Bar? (Choose two.)TY ?

293797. Boo f = new Boo.Bar(String s) { };

293797. Bar f = new Bar() { };

293797. Bar f = new Boo(String s) { };

293797. Boo f = new Boo() {String s; }; (***)

293798. Given the following, <BR>1.class Foo { <BR>2. class Bar{ } <BR>3.} <BR>4.class Test { <BR>5. public

static void main (String [] args) { <BR>6. Foo f = new Foo(); <BR>7. <FONT face=Symbol>¤</FONT><FONT

face=Symbol>¤</FONT> Insert code here <BR>8. } <BR>9.} <BR>which statement, inserted at line 5, creates an

instance of Bar? ?

293798. Foo.Bar b = new f.Bar();

21

293798. Foo.Bar b = f.new Bar(); (***)

293798. Bar b = f.new Bar();

293798. Bar b = new f.Bar();

293799. Which two are true about a method-local inner class? ?

293799. It can access private members of the enclosing class.

293799. It can be marked abstract. (***)

293799. It can be marked static.

293799. It can be marked public.

293800. Which is true about an anonymous inner class? ?

293800. It can implement multiple interfaces if it does not extend a class.

293800. It can extend exactly one class and can implement multiple interfaces.

293800. It can implement multiple interfaces regardless of whether it also extends a class.

293800. It can extend exactly one class or implement exactly one interface. (***)

293801. Given the following, <BR>public class Foo { <BR>Foo() {System.out.print("foo");} <BR>class Bar{

<BR>Bar() {System.out.print("bar");} <BR>public void go() {System.out.print("hi");} <BR>} <BR>public static

void main (String [] args) { <BR>Foo f = new Foo(); <BR>f.makeBar(); <BR>} <BR>void makeBar() { <BR>(new

Bar() {}).go(); <BR>} <BR>} <BR>what is the result? ?

293801. hi

293801. An error occurs at runtime.

293801. barhi

293801. foobarhi (***)

293802. Given the following, <BR>1.public class TestObj { <BR>2. public static void main (String [] args) {

<BR>3. Object o = new Object() { <BR>4. public boolean equals(Object obj) { <BR>5. return true; <BR>6. }

<BR>7. } <BR>8. System.out.println(o.equals("Fred")); <BR>9. } <BR>10.} <BR>what is the result? ?

293802. Compilation fails because of an error on line 4.

293802. true

293802. Compilation fails because of an error on line 3.

293802. Compilation fails because of an error on a line other than 3, 4, or 8. (***)

293803. Given the following, <BR>1. public class HorseTest { <BR>2. public static void main (String [] args) {

<BR>3. class Horse { <BR>4. public String name; <BR>5. public Horse(String s) { <BR>6. name = s; <BR>7. }

<BR>8. } <BR>9. Object obj = new Horse("Zippo"); <BR>10. Horse h = (Horse) obj; <BR>11.

System.out.println(h.name); <BR>12. } <BR>13. } <BR>what is the result? ?

293803. Compilation fails because of an error on line 10.

293803. Zippo (***)

293803. Compilation fails because of an error on line 9.

293803. Compilation fails because of an error on line 3.

293804. Given the following, <BR>1. public class HorseTest { <BR>2. public static void main (String [] args) {

<BR>3. class Horse { <BR>4. public String name; <BR>5. public Horse(String s) { <BR>6. name = s; <BR>7. }

<BR>8. } <BR>9. Object obj = new Horse("Zippo"); <BR>10. System.out.println(obj.name); <BR>11. } <BR>12. }

<BR>what is the result? ?

293804. Compilation fails because of an error on line 10. (***)

293804. Zippo

293804. Compilation fails because of an error on line 9.

22

293804. Compilation fails because of an error on line 3.

293805. Given the following, <BR>public abstract class AbstractTest { <BR>public int getNum() { <BR>return 45;

<BR>} <BR>public abstract class Bar { <BR>public int getNum() { <BR>return 38; <BR>} <BR>} <BR>public

static void main (String [] args) { <BR>AbstractTest t = new AbstractTest() { <BR>public int getNum() {

<BR>return 22; <BR>} <BR>}; <BR><BR>AbstractTest.Bar f = t.new Bar() { <BR>public int getNum() {

<BR>return 57; <BR>} <BR>}; <BR>System.out.println(f.getNum() + " " + t.getNum()); <BR>} <BR>} <BR>what

is the result? ?

293805. Compilation fails. (***)

293805. 45 38

293805. An exception occurs at runtime.

293805. 45 57

293806. Given the following,

<BR>

11. x = 0;

<BR>

12. if (x1.hashCode() != x2.hashCode() ) x = x + 1;

<BR>

13. if (x3.equals(x4) ) x = x + 10;

<BR>

14. if (!x5.equals(x6) ) x = x + 100;

<BR>

15. if (x7.hashCode() == x8.hashCode() ) x = x + 1000;

<BR>

16. System.out.println("x = " + x);

<BR>

and assuming that the equals () and hashCode() methods are property implemented, if the

<BR>

output is “x = 1111”, which of the following statements will always be true?“ ?

293806. x2.equals(x1)

293806. x3.hashCode() (***)

293806. x8.equals(x7)

293806. x5.hashCode()

293807. Given the following, <BR>class Test1 { <BR>public int value; <BR>public int hashCode() { return 42; }

<BR>} <BR>class Test2 { <BR>public int value; <BR>public int hashcode() { return (int)(value^5); } <BR>}

<BR>which statement is true? ?

293807. The two hashcode() methods will have the same efficiency.

293807. The Test1 hashCode() method is more efficient than the Test2 hashCode() method.

293807. class Test2 will not compile.

293807. The Test1 hashCode() method is less efficient than the Test2 hashCode() method. (***)

293808. Which statement&nbsp;is true about comparing two instances of the same class, given that the equals() and

hashCode() methods have been properly overridden? (Choose two.) ?

293808. If the hashCode() comparison != returns true, the equals() method might return true. (***)

293808. If the equals() method returns false, the hashCode() comparison != must return <BR>true.

293808. If the hashCode() comparison == returns true, the equals() method must return <BR>true.

293808. None of them

23

293809. Which class does not override the equals() and hashCode() methods, inheriting them directly from class

Object? ?

293809. java.lang.String

293809. java.lang.StringBuffer (***)

293809. java.lang.Character

293809. java.util.ArrayList

293810. What two statements are true about properly overridden hashCode() and equals() methods? ?

293810. equals() can be true even if it‟s comparing different objects.

293810. equals() doesn‟t have to be overridden if hashCode() is.

293810. hashCode() can always return the same value, regardless of the object that invoked it. (***)

293810. If two different objects that are not meaningfully equivalent both invoke hashCode(), <BR>then hashCode()

can‟t return the same value for both invocations.

293811. Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but

whose methods are not synchronized? ?

293811. java.util.Vector

293811. java.util.LinkedHashSet

293811. java.util.List

293811. java.util.ArrayList (***)

293812. Which collection class allows you to access its elements by associating a key with an element‟s value, and

provides synchronization? ?

293812. java.util.SortedMap

293812. java.util.TreeMap

293812. java.util.HashMap

293812. java.util.Hashtable (***)

293813. Given the following,

<BR>

12. TreeSet map = new TreeSet();

<BR>

13. map.add("one");

<BR>

14. map.add("two");

<BR>

15. map.add("three");

<BR>

16. map.add("four");

<BR>

17. map.add("one");

<BR>

18. Iterator it = map.iterator();

<BR>

19. while (it.hasNext() ) {

<BR>

20. System.out.print( it.next() + " " );

<BR>

24

21. }

<BR>

what is the result? ?

293813. one two three four

293813. four three two one

293813. one two three four one

293813. four one three two (***)

293814. Which collection class allows you to associate its elements with key values, and allows you to retrieve

objects in FIFO (first-in, first-out) sequence? ?

293814. java.util.LinkedHashSet

293814. java.util.LinkedHashMap (***)

293814. java.util.TreeMap

293814. java.util.HashMap

293815. Given the following, <BR>1. public class X { <BR>2. public static void main(String [] args) { <BR>3. X x

= new X(); <BR>4. X x2 = m1(x); <BR>5. X x4 = new X(); <BR>6. x2 = x4; <BR>7. doComplexStuff(); <BR>8. }

<BR>9. static X m1(X mx) { <BR>10. mx = new X(); <BR>11. return mx; <BR>12. } <BR>13. } <BR>After line 6

runs. how many objects are eligible for garbage collection?u ?

293815. 4

293815. 1 (***)

293815. 3

293815. 2

293816. Which statement is true? ?

293816. Once an overridden finalize() method is invoked, there is no way to make that object <BR>ineligible for

garbage collection.

293816. Objects with at least one reference will never be garbage collected.

293816. Objects instantiated within anonymous inner classes are placed in the garbage collectible heap. (***)

293816. Objects from a class with the finalize() method overridden will never be garbage <BR>collected.

293817. Given the following, <BR>1. class X2 { <BR>2. public X2 x; <BR>3. public static void main(String [] args)

{ <BR>4. X2 x2 = new X2(); <BR>5. X2 x3 = new X2(); <BR>6. x2.x = x3; <BR>7. x3.x = x2; <BR>8. x2 = new

X2(); <BR>9. x3 = x2; <BR>10. doComplexStuff(); <BR>11. } <BR>12. } <BR>after line 9 runs, how many objects

are eligible for garbage collection? ?

293817. 5

293817. 1

293817. 3

293817. 2 (***)

293818. Which statement is true? ?

293818. Calling Runtime.gc() will cause eligible objects to be garbage collected.

293818. The garbage collector uses a mark and sweep algorithm.

293818. If an object can be accessed from a live thread, it can‟t be garbage collected. (***)

293818. If object 1 refers to object 2, then object 2 can‟t be garbage collected.

293819. Given the following, <BR>12. X3 x2 = new X3(); <BR>13. X3 x3 = new X3(); <BR>14. X3 x5 = x3;

<BR>15. x3 = x2; <BR>16. X3 x4 = x3; <BR>17. x2 = null; <BR>18. <FONT face=Symbol>¤</FONT><FONT

25

face=Symbol>¤</FONT> insert code <BR>what two lines of code, inserted independently at line 18, will make an

object eligible for garbage collection? (Choose two.) ?

293819. x5 = x4;

293819. x4 = null;

293819. x3 = x4;

293819. x5 = null; (***)

293820. Given the following, <BR>12. void doStuff3() { <BR>13. X x = new X(); <BR>14. X y = doStuff(x);

<BR>15. y = null; <BR>16. x = null; <BR>17. } <BR>18. X doStuff(X mx) { <BR>19. return doStuff2(mx);

<BR>20. } <BR>at what point is the object created in line 13 eligible for garbage collection? ?

293820. It is not possible to know for sure.

293820. After line 16 runs (***)

293820. The object is not eligible.

293820. After line 17 runs

293821. Given:

<BR>

11. public void foo(boolean a, boolean b){

<BR>

12. if(a){

<BR>

13. System.out.println("A");

<BR>

14. }else if(a<font face="Symbol">&#38;</font><font face="Symbol">&#38;</font>b){

<BR>

15. System.out.println("A<font face="Symbol">&#38;</font><font face="Symbol">&#38;</font>B");

<BR>

16. }else{

<BR>

17. if( !b ){

<BR>

18. System.out.println("notB");

<BR>

19. }else{

<BR>

20. System.out.println("ELSE");

<BR>

21. }

<BR>

22. }

<BR>

23. }

<BR>

What is correct? ?

293821. If a is true and b is true then the output is "A<font face="Symbol">&#38;</font><font

face="Symbol">&#38;</font>B".

293821. If a is true and be is false then the output is "notB".

293821. If a is false and b is false then the output is "ELSE".

293821. If a is false and be is true then the output is "ELSE". (***)

26

293822. Given: <BR>1. public class ServletTest extends HttpServlet{ <BR>2. public void goGet( <BR>3.

HttpServletRequest request <BR>4. HttpServletResponse response) <BR>5. throws ServletException, IOException

<BR>6. { <BR>7. String message = *In doGet*; <BR>8. <BR>9. } <BR>10. } <BR>Which two, inserted

individually at line 8, will each place an entry in the servlet log file? (Choose two) ?

293822. getServletContext().log(message); (***)

293822. request.log(message);

293822. getServletConfig().log(message);

293822. getServletInfo().log(message);

293823. Given:

<BR>

11. public class Test{

<BR>

12. public void foo(){

<BR>

13. assert false;

<BR>

14. assert false;

<BR>

15. }

<BR>

16. public void bar(){

<BR>

17. while(true){

<BR>

18. assert false;

<BR>

19. }

<BR>

20. assert false;

<BR>

21. }

<BR>

22. }

<BR>

What causes compilation to fail?

<BR>

?

293823. Line 13

293823. Line 14

293823. Line 20 (***)

293823. Line 18

293824. Given: <BR>1. public interface Test{ <BR>2. int frood=42; <BR>3. } <BR>4. class Testlmpl implements

Test{ <BR>5. public static void main(String[]args){ <BR>6. System.out.printIn(++frood); <BR>7. } <BR>8. }

<BR>What is the result? ?

293824. Compilation fails. (***)

293824. 1

27

293824. 43

293824. 42

293825. Which statement is true? ?

293825. Memory is reclaimed by calling Runtime.gc().

293825. Objects are not collected if they are accessible from live threads. (***)

293825. Objects that have finalize() methods always have their finalize() methods called before the program ends.

293825. Objects that have finalize() methods are never garbage collected.

293826. Given:

<BR>

11. for (int i=0;i<font face="Symbol">&#60;</font>3;i++){

<BR>

12. switch(i){

<BR>

13. case 0:break;

<BR>

14. case 1:System.out.print("one");

<BR>

15. case 2:System.out.print("two");

<BR>

16. case 3:System.out.print("three");

<BR>

17. }

<BR>

18. }

<BR>

19. System.out.println("done");

<BR>

What is the result? ?

293826. Done

293826. One two done

293826. Compilation fails.

293826. One two three two three done (***)

293827. Given:

<BR>

11. try{

<BR>

12. int x=0;

<BR>

13. int y=5<font face="Symbol">&#164;</font>x;

<BR>

14. }catch(Exception c){

<BR>

15. System.out.println("Exception");

<BR>

16. }catch(ArithmeticException ac){

<BR>

28

17. System.out.println("Arithmetic Exception");

<BR>

18. }

<BR>

19. System.out.println("finished");

<BR>

What is the result? ?

293827. finished

293827. Exception

293827. Compilation fails. (***)

293827. Arithmetic Exception

293828. Given:

<BR>

10. public Object m(){

<BR>

11. Object o=new Float(3.14F);

<BR>

12. Object[]oa=new Object[1];

<BR>

13. ao[0]=o;

<BR>

14. o=null;

<BR>

15. oa[0]=null;

<BR>

16. return o;

<BR>

17. }

<BR>

When is the Float object, created in line 11, eligible for garbage collection?; ?

293828. Just after line 13.

293828. Just after line 14.

293828. Just after line 16(that is, as the method returns).

293828. Just after line 15. (***)

293829. Which statement is true? ?

293829. Except in case of VM shutdown, if a try block starts to execute, a corresponding finally block must always

<BR>run to completion.

293829. Multiple catch statements can catch the same class of exception more than once.

293829. Except in case of VM shutdown, if a try block starts to execute, a corresponding finally block will always

<BR>start to execute. (***)

293829. An Error that might be thrown in a method must be declared as thrown by that method, or be handled within

<BR>that method.

293830. Given: <BR>1. class Test{ <BR>2. private Demo d; <BR>3. void start(){ <BR>4. d=new Demo(); <BR>5.

this.takeDemo(d); <BR>6. } <BR>7. <BR>8. void takeDemo(Demo demo){ <BR>9. demo=null; <BR>10.

demo=new Demo(); <BR>11. } <BR>12. } <BR>When is the Demo object created on line 4, eligible for garbage

collection? ?

29

293830. When the instance running this code is made eligible for garbage collection.

293830. After line 9. (***)

293830. When the takeDemo() method completes.

293830. After the start() method completes.

293831. Which correctly defined "data integrity"? ?

293831. It guarantees that access to your confidential files will prompt the user for their password of the Web

<BR>browser.

293831. It guarantees that only a specific set of users may access your confidential files.

293831. It guarantees that delivery of your confidential files will not be altered during transmission. (***)

293831. It guarantees that delivery of your confidential files will not be read by a malicious user.

293832. Given: <BR>11. Float f=new Float("12"); <BR>12. switch(f){ <BR>13. case

12:System.out.println("Twelve"); <BR>14. case 0:System.out.println("Zero"); <BR>15. default:

System.out.println("Default"); <BR>16. } <BR>What is the result? ?

293832. Compilation fails (***)

293832. Twelve

293832. Twelve <BR>Zero <BR>Default

293832. Default

293833. Which can be thrown using the show statement? ?

293833. Exception (***)

293833. Event

293833. Class

293833. Object

293834. Which statement is true? ?

293834. Objects are garbage collected immediately after the system recognizes they are eligible.

293834. Objects that will never again be used are eligible for garbage collection.

293834. Objects that can be reached from a live thread will never be garbage collected. (***)

293834. Objects that are referred to by other objects will never be garbage collected.

293835. Given: <BR>1. public class Foo{ <BR>2. static String s; <BR>3. public static void main(String[]args){

<BR>4. System.out.println("s="+s); <BR>5. } <BR>6. } <BR>What is the result? ?

293835. Compilation fails because of an error at line 4.

293835. s=null (***)

293835. An exception is thrown at runtime.

293835. Compilation fails because of an error at line 2.

293836. Given: <BR>11. public void test(int x){ <BR>12. int odd=x%2; <BR>13. if(odd){ <BR>14.

System.out.println("odd"); <BR>15. }else{ <BR>16. System.out.println("even"); <BR>17. } <BR>18. } <BR>What

statement is true? ?

293836. "even" will be output for add values of x, and "odd" for even values. (***)

293836. "odd" will always be output.

293836. "odd" will be output for add values of x, and "even" for even values.

293836. "even" will always be output.

293837. Given: <BR>1. public class ExceptionTest{ <BR>2. class TestException extends Exception{} <BR>3.

public void runTest()throws TestExcpetion{} <BR>4. public void test()<FONT face=Symbol>¤</FONT>*Point

30

X*<FONT face=Symbol>¤</FONT>{ <BR>5. runTest(); <BR>6. } <BR>7. } <BR>At Point X on line 4, which

code is necessary to make the code compile? ?

293837. catch(TestException c)

293837. throws Exception (***)

293837. throws RuntimeException

293837. catch(Exception c)

293838. Which item provides tools to allow the formatting of currency and date information according to local

conventions? ?

293838. java.text package (***)

293838. java.util.Locale class

293838. java.lang.String class

293838. Readers and Writers in the java.io package.

293839. Given:

<BR>

1. public class X{

<BR>

2. public static void main(String[]args){

<BR>

3. try{

<BR>

4. badMethod();

<BR>

5. System.out.print("A");

<BR>

6. }

<BR>

7. catch(Exception ex){

<BR>

8. System.out.print("B");

<BR>

9. }

<BR>

10. finally{

<BR>

11. System.out.print("C");

<BR>

12. }

<BR>

13. Sytstem.out.print("D");

<BR>

14. }

<BR>

15. public static void badMethod(){

<BR>

16. throw new RuntimeException();

<BR>

31

17. }

<BR>

18. }

<BR>

What is the result? ?

293839. AB

293839. BC

293839. ABC

293839. BCD (***)

293840. Given:

<BR>

20. public float getSalary(Employee c){

<BR>

21. assert validEmployee(c);

<BR>

22. float sal=lookupSalary(c);

<BR>

23. assert (sal<font face="Symbol">&#62;</font>0);

<BR>

24. return sal;

<BR>

25. }

<BR>

26. private int getAge(Employee c){

<BR>

27. assert validEmployee(c);

<BR>

28. int age=lookupAge(c);

<BR>

29. assert (age<font face="Symbol">&#62;</font>0);

<BR>

30. return age;

<BR>

31. }

<BR>

Which line is a violation of appropriate use of the assertion mechanism? ?

293840. Line 21 (***)

293840. Line 23

293840. Line 29

293840. Line 27

293841. Given: <BR>1. package foo; <BR>2. <BR>3. import java.util.Vector; <BR>4. <BR>5. protected class

MyVector extends Vector{ <BR>6. int i=1; <BR>7. public MyVector(){ <BR>8. i=2; <BR>9. } <BR>10. }

<BR>11. <BR>12. public class MyNewVector extends MyVector{ <BR>13. public MyNewVector(); <BR>14. i=4;

<BR>15. } <BR>16. public static void main(String args[]){ <BR>17. MyVector v=new MyNewVector(); <BR>18. }

<BR>19. } <BR>What is the result? ?

293841. Compilation fails because of an error at line 17.

293841. Compilation fails because of an error at line 5. (***)

32

293841. Compilation fails because of an error at line 14.

293841. Compilation fails because of an error at line 6.

293842. Given: <BR>1. public class X{ <BR>2. public static void main(String[]args){ <BR>3. try{ <BR>4.

badMethod(); <BR>5. System.out.print("A"); <BR>6. } <BR>7. catch(Exception ex){ <BR>8.

System.out.print("B"); <BR>9. } <BR>10. finally{ <BR>11. System.out.print("C"); <BR>12. } <BR>13.

System.out.print("D"); <BR>14. } <BR>15. public static void badMethod(){} <BR>17. } <BR>What is the result? ?

293842. Compilation fails.

293842. BC

293842. ABCD

293842. ACD (***)

293843. Given: <BR>11. int i=0,j=5; <BR>12. tp:for(;;){ <BR>13. i++; <BR>14. for(;;){ <BR>15. if(i<FONT

face=Symbol>&gt;</FONT>--j){ <BR>16. break tp; <BR>17. } <BR>18. } <BR>19. } <BR>20.

System.out.println("i="+",j="+j); <BR><BR>What is the result? ?

293843. Compilation fails. (***)

293843. i=1, j=4

293843. i=3, j=0

293843. i=3, j=4

293844. Which fragment is an example of inappropriate use of assertions? ?

293844. assert(!map.contains(x)));

<BR>

map.add(x);

293844. if(x<font face="Symbol">&#62;</font>0){

<BR>

}else{

<BR>

assert(x==0);

<BR>

}

293844. assert(invariantCondition());

<BR>

return retval;

<BR>

E. switch(x){

<BR>

case 1:break;

<BR>

case 2:break;

<BR>

default:assert(x==0);

293844. public void atMethod(int x){

<BR>

assert(x<font face="Symbol">&#62;</font>0);

<BR>

(***)

33

293845. Given:

<BR>

1. class Bar{}

<BR>

1. class Test{

<BR>

2. Bar doBar(){

<BR>

3. Bar b=new Bar();

<BR>

4. return b;

<BR>

5. }

<BR>

6. public static void main(String args[]){

<BR>

7. Test t=new test();

<BR>

8. Bar newBar=t.doBar();

<BR>

9. System.out.println("newBar");

<BR>

10. newBar=new Bar();

<BR>

11. System.out.println("finishing");

<BR>

12. }

<BR>

13. }

<BR>

At what point is the Bar object, created on line 3, eligible for garbage collection? ?

293845. After line 8.

293845. After line 10. (***)

293845. After line 11, when main() completes.

293845. After line4, when doBar() completes.

293846. Given:

<BR>

11. int i=1,j=10;

<BR>

12. do{

<BR>

13. if(i<font face="Symbol">&#62;</font>j){

<BR>

14. continue;

<BR>

15. }

<BR>

34

16. j--;

<BR>

17. }while(++i<font face="Symbol">&#60;</font>6);

<BR>

18. System.out.println("i="+i+"and j="+j);

<BR>

What is the result? ?

293846. i=6 and j=5 (***)

293846. i=5 and j=5

293846. i=5 and j=6

293846. i=6 and j=4

293847. 11. public static void main(String[]args){ <BR>12. Object obj=new Object(){ <BR>13. public int

hashCode(){ <BR>14. return 42; <BR>15. } <BR>16. } <BR>17. System.out.println(obj.hashCode()); <BR>18. }

<BR>What is the result? ?

293847. Compilation fails because of an error on line 17.

293847. An exception is thrown at runtime.

293847. Compilation fails because of an error on line 16. (***)

293847. Compilation fails because of an error on line 12.

293848. Given: <BR>1. package foo; <BR>2. <BR>3. import java.util.Vector; <BR>4. <BR>5. protected class My

Vector Vector { <BR>6. init i = 1; <BR>7. public My Vector() { <BR>8. i = 2; <BR>9. } <BR>10.} <BR>11.

<BR>12. public class MyNewVector extends My Vector { <BR>13. public MyNewVector () { <BR>14. i = 4;

<BR>15.} <BR>16. public static void main (String args []) { <BR>17. My Vector v = new MyNewVector ();

<BR>18. } <BR>19. } <BR>What is the result? ?

293848. Compilation fails because of an error at line 17.

293848. Compilation fails because of an error at line 5. (***)

293848. Compilation fails because of an error at line 6.

293848. Compilation fails because of an error at line 14.

293849. Given:

<BR>

1. package foo;

<BR>

2. import java.util.Vector;

<BR>

3. private class MyVector extends Vector {

<BR>

4. int i = 1;

<BR>

5. public MyVector() {

<BR>

6. i = 2; } }

<BR>

7. public class MyNewVector extends MyVector {

<BR>

8. public MyNewVector () {14. i = 4; }

<BR>

35

9. public static void main (String args []) {

<BR>

10. My Vector v = new MyNewVector (); } }

<BR>

<BR>

What is the result? ?

293849. Compilation fails because of an error at line 5. (***)

293849. Compilation fails because of an error at line 14.

293849. Compilation fails because of an error at line 6.

293849. Compilation fails because of an error at line 17.

293850. Which statement is true for the class java.util.HashSet? ?

293850. The elements in the collections are guaranteed to be synchronized.

293850. The collection is guaranteed to be immutable.

293850. The elements in the collection are accessed using a unique key.

293850. The elements in the collection are guaranteed to be unique. (***)

293851. You need to store elements in a collection that guarantees that no duplicates are stored and all elements can

be accessed in natural order. Which interface provides that capability? ?

293851. Java.util.Collection.

293851. Java.util.Set.

293851. Java.util.List.

293851. Java.util.StoredSet. (***)

293852. You are assigned the task of building a panel containing a TextArea at the top, a label directly below it, and a

button directly below the label. If the three components are added directly to the panel. Which layout manager can the

panel use to ensure that the TextArea absorbs all of the free vertical space when <BR>the panel is resized? ?

293852. GridBagLayout. (***)

293852. CardLayout.

293852. BorderLayout.

293852. FlowLayout.

293853. Which is a method of the MouseMotionListener interface? ?

293853. Public boolean mouseMoved(MouseMotionEvent) (***)

293853. Public boolean mouseMoved(MouseEvent)

293853. Public boolean MouseMoved(MouseHoverEvent)

293853. Public void mouseMoved(MouseMotionEvent)

293854. Given the ActionEvent, which method allows you to identify the affected component? ?

293854. getClass.

293854. getTarget.

293854. getComponent.

293854. getSource. (***)

293855. Which is the most suitable Java collection class for storing various companies and their stock prices? It is

required that the class should support synchronization inherently. ?

293855. TreeMap (***)

293855. HashMap

36

293855. LinkedHashMap

293855. HashSet

293856. What will be the result of an attempt to compile and run the following program?

<BR>

class Test

<BR>

{

<BR>

public static void main(String args[])

<BR>

{

<BR>

String s1 = "abc";

<BR>

String s2 = "abc";

<BR>

s1 += "xyz";

<BR>

s2.concat("pqr");

<BR>

s1.toUpperCase();

<BR>

System.out.println(s1 + s2);

<BR>

}

<BR>

}

<BR>

Choices: ?

293856. "abcxyzabc" (***)

293856. "abcxyzabcpqr"

293856. "ABCXYZabc"

293856. "ABCXYZabcpqr"

293857. Which of the following statements is not true about threads? ?

293857. If the start() method is invoked twice on the same Thread object, an exception is thrown at runtime.

293857. The order in which threads were started might differ from the order in which they

<BR>

actually run.time.

293857. If the run() method is directly invoked on a Thread object, an exception is thrown at

<BR>

runtime.ime. (***)

293857. If the sleep() method is invoked on a thread while executing synchronized code, the lock is not released.

293858. Suppose that a legacy application is primarily comprised of COM objects. Which technologies could be used

to access these objects from Java? ?

293858. Java IDL

293858. JDBC

37

293858. RMI

293858. A Java-to-COM bridge (***)

293859. Suppose that an existing legacy database supports ODBC but not JDBC. Which technologies may be used to

access the database from a Java applet? ?

293859. The Java-ODBC bridge driver (***)

293859. OLEDB

293859. JNDI

293859. JNI

293860. What is the well-known port of HTTP? ?

293860. 21

293860. 25

293860. 137

293860. 80 (***)

293861. Suppose that a database server does not support a pure JDBC driver, but it does support an ODBC driver.

How can you access the database server using JDBC? ?

293861. Use SQL.

293861. Use JNDI.

293861. Use the JDBC-ODBC bridge driver. (***)

293861. Use Java RMI.

293862. Which of the following are used by Java RMI? ?

293862. stubs (***)

293862. frame

293862. IIOP

293862. ORBs

293863. Which of the following Java technologies support transaction processing? ?

293863. RMI

293863. JTS (***)

293863. JAXP

293863. JMAPI

293864. Which of the following is a Java API for managing enterprise services, systems, and networks. ?

293864. JTA (***)

293864. Java Server Pages

293864. JMAPI

293864. JDBC

293865. What type of diagram does a Java Architect frequently produce? ?

293865. Attribute diagram

293865. Property diagram

293865. Package dependency diagram (***)

293865. Constraint diagram

293866. Which function may be provided by the client tier of a Java application architecture? ?

293866. input validation

38

293866. applet viewer

293866. user interface (***)

293866. database access

293867. What is the purpose of a layout manager? ?

293867. to manage the interaction of JavaBeans

293867. to provide an area to display AWT components

293867. to display information about the coordinates of components in an applet

293867. to control the arrangement of components within the display area of a container (***)

293868. Which of the following are not a role of the Java architect? ?

293868. Evaluating the advantages and disadvantages of using Java technology for enterprise applications

293868. Designing distributed object architectures to a given set of business requirements

293868. Training users on how to operate a Java-based application (***)

293868. Evaluating proposed Java technology architectures and making

<BR>

recommendations to increase performance and security

293869. garbage collection?

<BR>

2. 1. import java.util.*;

<BR>

3. 2. public class Question {

<BR>

4. 3. public static void main(String[] args) {

<BR>

5. 4. Vector v1 = new Vector(); a

<BR>

6. 5. Vector v2 = new Vector();

<BR>

7. 6. v1.add("This");

<BR>

8. 7. v1.add(v2);

<BR>

9. 8. String s = (String) v1.elementAt(0);

<BR>

10. 9. v1 = v2;

<BR>

11. 10. v2 = v1;

<BR>

12. 11. v1.add(s);

<BR>

13. 12. }

<BR>

13.}Ý ?

293869. Line 5

293869. Line 6

293869. Line 9 (***)

293869. Line 8

39

293870. At which line in the following code is the Vector object, created in line 4, first subject to garbage collection?

<BR>1. import java.util.*; <BR>2. public class Question { <BR>3. public static void main(String[] args) { <BR>4.

Vector v1 = new Vector(); <BR>5. Vector v2 = new Vector();. 6. v1 = null; <BR>7. Vector v3 = v1;. 8. v1 = v2;

<BR>9. v1.add("This"); <BR>10. v1.add(v2); <BR>11. String s = (String) v1.elementAt(0); <BR>12. v1 = v2;

<BR>13. v2 = v1; <BR>14. v1.add(s); <BR>15. } <BR>16.} ?

293870. Line 6 (***)

293870. Line 7

293870. Line 8

293870. Lin 9

293871. How can you force an object to be garbage collected? ?

293871. Invoke its finalize() method.

293871. Remove all references to the object.

293871. You cannot force an object to be garbage collected. (***)

293871. Use all memory that is available to the program.

293872. Which of the following are true? ?

293872. Multithreading is unique to Java.

293872. Multithreading requires more than one CPU.

293872. Multithreading is supported by Java. (***)

293872. Multithreading requires that a computer have a single CPU.

293873. How can a class that is run as a thread be defined? ?

293873. By subclassing the MuitiThread class.

293873. By implementing the Throwable interface.

293873. By implementing the Runnable interface. (***)

293873. By implementing the Multithread interface.

293874. The Runnable interface declares which methods? ?

293874. start()

293874. run() (***)

293874. yield()

293874. stop()

293875. Given an object TTT that implements Runnable, which method of the Thread class should you invoke to

cause TTT to be executed as a separate thread? ?

293875. start() (***)

293875. init()

293875. run()

293875. main()

293876. Which of the following are not thread states? ?

293876. blocked

293876. runable

293876. start

293876. open (***)

293877. Which of the following thread state transitions are not&nbsp;valid? ?

40

293877. From waiting to ready.

293877. From running to ready.

293877. From waiting to running. (***)

293877. From running to waiting.

293878. When a thread blocks on I<font face="Symbol">&#164;</font>O, which of the following are true? ?

293878. The thread enters the ready state.

293878. The thread enters the dead state.

293878. The thread enters the waiting state. (***)

293878. No other thread may perform I<font face="Symbol">&#164;</font>O.

293879. Which of the following are true about a dead thread? ?

293879. The thread's object is discarded.

293879. The thread must wait until all other threads execute before it is restarted.

293879. The thread is synchronized.

293879. The thread cannot be restarted. (***)

293880. Which of the following are true? ?

293880. Java only supports preemptive scheduling.

293880. Java only supports time slicing.

293880. The JVM has been implemented on operating systems that use preemptive <BR>scheduling. (***)

293880. The JVM has not been implemented on operating systems that use time slicing.

293881. Which of the following are true? ?

293881. The sleep() method puts a thread in the ready state.

293881. The yield() method puts a thread in the waiting state.

293881. A thread's interrupt() method results in the throwing of the

<BR>

InterruptedException. (***)

293881. The suspend() method is the preferred method for stopping a thread's execution

293882. Which of the following are true? ?

293882. Only threads have locks.

293882. Classes have locks. (***)

293882. Only Runnable objects have locks.

293882. Primitive types have locks.

293883. Which of the following are true? ?

293883. The Thread class inherits the wait() and notify() methods from Runnable interface.

293883. The Object class declares the wait() and notify() methods. (***)

293883. Only the Synchronized class supports the wait() and notify() methods

293883. The wait() and notify() methods have been deprecated in JDK 1.2.

293884. Which of the following are true about the following program?\

<BR>

29. class Question {

<BR>

30. public static void main(String args[]) {

<BR>

41

31. MyThread t1 = new MyThread("t1");

<BR>

32. MyThread t2 = new MyThread("t2");

<BR>

33. t1.start();

<BR>

34. t2.start();

<BR>

35. }

<BR>

36. }

<BR>

37. class MyThread extends Thread {

<BR>

38. public void displayOutput(String s) {

<BR>

39. System.out.println(s);

<BR>

40. }

<BR>

41. public void run() {

<BR>

42. for(int i=0;i<font face="Symbol">&#60;</font>10;++i) {

<BR>

43. try {

<BR>

44. sleep((long)(3000*Math.random()));

<BR>

45. }catch(Exception ex) {

<BR>

46. }

<BR>

47. displayOutput(getName());

<BR>

48. }

<BR>

49. }

<BR>

50. public MyThread(String s) {

<BR>

51. super(s);

<BR>

52. }

<BR>

}

<BR>

?

293884. The program always displays t1 10 times, followed by t2 10 times.

293884. The program always displays t1 followed by t2.

42

293884. The output sequence will vary from computer to computer. (***)

293884. The program displays no output.

293885. What changes are needed to make the following program compile?

<BR>

2. import java.util.*;

<BR>

3. class Question {

<BR>

4. public static void main(String args[]) {

<BR>

5. String s1 = "abc";

<BR>

6. String s2 = "def";

<BR>

7. Vector v = new Vector();

<BR>

8. v.add(s1);

<BR>

9. v.add(s2);

<BR>

10. String s3 = v.elementAt(0) + v.elementAt(1);

<BR>

11. System.out.println(s3);

<BR>

12. }

<BR>

} ?

293885. Declare Question as public.

293885. Cast v.elementAt(0) to a String. (***)

293885. Import java.lang.

293885. Cast v.elementAt(1) to an Object.

293886. What output does the following program display?

<BR>

14. import java.util.*;

<BR>

15. class Question {

<BR>

16. public static void main(String args[]) {

<BR>

17. String s1 = "abc";

<BR>

18. String s2 = "def";

<BR>

19. Stack stack = new Stack();

<BR>

20. stack.push(s1);

<BR>

43

21. stack.push(s2);

<BR>

22. try {

<BR>

23. String s3 = (String) stack.pop() + (String) stack.pop();

<BR>

24. System.out.println(s3);

<BR>

25. }catch(EmptyStackException ex){

<BR>

26. }

<BR>

27. }

<BR>

} ?

293886. abcdef

293886. defabc (***)

293886. defdef

293886. abcabc

293887. Which of the following extend the Collection interface? ?

293887. Dictionary. List

293887. Set. Dictionary.

293887. Set. List (***)

293887. Map. List

293888. Which JDK 1.1 interface is the Iterator interface intended to replace? ?

293888. Runnable

293888. Throwable

293888. List

293888. Enumeration (***)

293889. Which of the following may have duplicate elements? ?

293889. Collection (***)

293889. Enumeration

293889. Set

293889. Map

293890. Can a null value be added to a List? ?

293890. Yes. (***)

293890. Yes, but only if the List is linked.

293890. No.

293890. Yes, provided that the List is non-empty.

293891. What is the output of the following program?

<BR>

33. import java.util.*;

<BR>

44

34. class Question {

<BR>

35. public static void main(String args[]) {

<BR>

36. HashSet set = new HashSet();

<BR>

37. String s1 = "abc";

<BR>

38. String s2 = "def";

<BR>

39. String s3 = "";

<BR>

40. set.add(s1);

<BR>

41. set.add(s2);

<BR>

42. set.add(s1);

<BR>

43. set.add(s2);

<BR>

44. Iterator i = set.iterator();

<BR>

45. while(i.hasNext()){

<BR>

46. s3 += (String) i.next();

<BR>

47. }

<BR>

48. System.out.println(s3);

<BR>

49. }

<BR>

} ?

293891. abcdefabcdef

293891. defabcdefabc

293891. defabc

293891. abcdef (***)

293892. What is the output of the following program?

<BR>

51. import java.util.*;

<BR>

52. class Question {

<BR>

53. public static void main(String args[]) {

<BR>

54. TreeMap map = new TreeMap();

<BR>

45

55. map.put("one","1");

<BR>

56. map.put("two","2");

<BR>

57. map.put("three","3");

<BR>

58. displayMap(map);

<BR>

59. }

<BR>

60. static void displayMap(TreeMap map) {

<BR>

61. Collection c = map.entrySet();

<BR>

62. Iterator i = c.iterator();

<BR>

63. while(i.hasNext()){

<BR>

64. Object o = i.next();

<BR>

65. System.out.print(o.toString());

<BR>

66. }

<BR>

67. }

<BR>

} ?

293892. onetwothree

293892. 123

293892. one=1three=3two=2 (***)

293892. onethreetwo

293893. Which of the following are true? ?

293893. Component extends Container.

293893. MenuItem extends Component.

293893. MenuComponent extends Component.

293893. Container extends Component. (***)

293894. Which of the following are direct or indirect subclasses of Component? ?

293894. Frame (***)

293894. Button

293894. Toolbar

293894. CheckboxMenuItem

293895. Which of the following are direct or indirect subclasses of Container? ?

293895. ToolBar

293895. TextArea

293895. FileDialog (***)

293895. MenuBar

46

293896. Which Component method is used to access a component's immediate Container? ?

293896. getVisible()

293896. getImmediate()

293896. getContainer()

293896. getParent() (***)

293897. Which method is used to set the text of a Label object? ?

293897. setText() (***)

293897. setLabel()

293897. setLabelText()

293897. setTextLabel()

293898. Which of the following is true? ?

293898. TextArea extends TextComponent.

293898. TextArea extend TextField.

293898. TextComponent extends TextField.

293898. TextField extends TextComponent. (***)

293899. Which of the following are true? ?

293899. A Checkbox is a RadioButton that has been associated with a <BR>RadioGroup.

293899. The CheckboxGroup class is used to define radio buttons. (***)

293899. A Checkbox is a RadioButton that has been associated with a CheckboxGroup.

293899. The RadioGroup class is used to define radio buttons.

293900. Which constructor creates a TextArea with 10 rows and 20 columns? ?

293900. new TextArea(10,20) (***)

293900. new TextArea(20,10)

293900. new TextArea(200)

293900. new TextArea(new Rows(10), new Colums(20))

293901. Which of the following creates a List with 5 visible items and multiple selection enabled? ?

293901. new List(5, true) (***)

293901. new List(true, 5)

293901. new List(5, false)

293901. new List(false, 5)

293902. Which istrue about the Container class? ?

293902. The validate() method is used to cause a Container to be laid out and redisplayed. (***)

293902. The layout() method is used to cause a Container to be laid out and redisplayed.

293902. e getComponent() method is used to access a Component that is contained in a Container.

293902. The getBorder() method returns information about a container's insets.

293903. Which of the following are true? ?

293903. Window extends Frame.

293903. Applet extends Window.

293903. ScrollPane extends Panel.

293903. Panel extends Container. (***)

47

293904. Which of the following are true? ?

293904. A Dialog can have a MenuBar, a MenuItem can be added to a Menu.

293904. MenuItem extends Menu, A Menu can be added to a Menu

293904. A Menu can be added to a Menu, a MenuItem can be added to a Menu. (***)

293904. MenuItem extends Menu, A Dialog can have a MenuBar.

293905. Suppose a Panel is added to a Frame and a Button is added to the Panel. If the Frame's font is set to 12-point

TimesRoman, the Panel's font is set to 10-point TimesRoman, and the Button's font is not set, what font will be used

to display the Button's label? ?

293905. 12-point TimesRoman

293905. 11-point TimesRoman

293905. 9-point TimesRoman

293905. 10-point TimesRoman (***)

293906. A Frame's background color is set to Color.Yellow, and a Button's background color is set to Color.Blue.

Suppose the Button is added to a Panel, which is added to the Frame. What background color will be used with the

Panel? ?

293906. Color.Yellow (***)

293906. Color.Blue

293906. Color.Green

293906. Color.White

293907. Which methods will cause a Frame to be displayed? ?

293907. show() and setVisible() (***)

293907. displayFrame() and setVisible()

293907. displayFrame() and display()

293907. display() and show()

293908. Which of the following are true? ?

293908. The event-inheritance model has replaced the event-delegation model

293908. The event-inheritance model is more efficient than the event-delegation

<BR>

model

293908. The event-delegation model uses the handleEvent() method to support

<BR>

event handling

293908. The event-delegation model uses event listeners to define the methods of

<BR>

event-handling classes (***)

293909. Which of the following is the highest class in the event delegation class hierarchy? ?

293909. java.util.EventListener

293909. java.util.EventObject (***)

293909. java.awt.event.AWTEvent

293909. java.awt.AWTEvent

293910. Which of the following are NOT&nbsp;true? ?

293910. Event listeners are interfaces that define the methods that event-handling classes must implement.

293910. An event adapter is a class that provides a default implementation of an event listener.

48

293910. The event listener and adapter classes are deprecated in Java 2. (***)

293910. The WindowAdapter class is used to handle window-related events.

293911. When two or more objects are added as listeners for the same event, which listener is first invoked to handle

the event? ?

293911. The first object that was added as a listener.

293911. The last object that was added as a listener.

293911. There is no way to determine which listener will be invoked first. (***)

293911. It is impossible to have more than one listener for a given event.

293912. Which of the following components generate action events? ?

293912. Buttons (***)

293912. Labels

293912. Windows

293912. Check boxes

293913. Which of the following are NOT true? ?

293913. A TextField object may generate an ActionEvent.

293913. A TextArea object may generate an ActionEvent. (***)

293913. A MenuItem object may generate an ActionEvent.

293913. A Button object may generate an ActionEvent.

293914. Which of the following istrue? ?

293914. The MouseListener interface defines methods for handling mouse clicks. (***)

293914. The MouseMotionListener interface defines methods for handling mouse clicks.

293914. The MouseClickListener interface defines methods for mouse clicks.

293914. The ActionListener interface defines methods for handling the drag<BR>of a button.

293915. Suppose that you want to have an object EEHH handle the TextEvent of a TextArea object TTT. How

should you add EEHH as the event handler for TTT? ?

293915. TTT.addTextListener(EEHH); (***)

293915. EEHH.addTextListener(TTT);

293915. addTextListener(TTT,EEHH);

293915. addTextListener(EEHH,TTT);

293916. What is the preferred way to handle an object's events in Java 2? ?

293916. Override the object's handleEvent() method.

293916. Add one or more event listeners to handle the events. (***)

293916. Have the object override its processEvent() methods.

293916. Have the object override its dispatchEvent() methods.

293917. Which of the following are true? ?

293917. A component&nbsp;cannot handle its own events by adding itself as an event <BR>listener.

293917. A component may handle its own events by overriding its event-dispatching method. (***)

293917. A component may handle its own events only if it implements the handleEvent() method.

293917. A component may not handle its own events.

293918. How does a *.java file differ from a *.class file? ?

293918. A *.java file is bytecode.

49

293918. A *.class file is source code.

293918. A *. class file is a compiled *.java file.ass (***)

293918. A *.java file is a compiled *.class file.

293919. Which term describes a small Java program that must be run from a Web browser? ?

293919. Application

293919. Applet (***)

293919. Java Virtual Machine

293919. Method

293920. You wish to store a small amount of data and make it available for rapid access. You do not have a need for

the data to be sorted, uniqueness is not an issue and the data will remain fairly static. Which data structure might be

most suitable for this requirement? ?

293920. TreeSet

293920. HashMap

293920. an array

<BR>

(***)

293920. LinkedList

293921. What will happen when you attempt to compile

<BR>

and run this code?

<BR>

public class Mod{

<BR>

public static void main(String argv[]){

<BR>

}

<BR>

public static native void amethod();

<BR>

} ?

293921. Error at compilation: native method cannot be static

293921. Error at compilation native method must return value

293921. Compilation and execution without errorš (***)

293921. Compilation but error at run time unless you have made code containing native amethod available

293922. Which statement is true about a non-static inner class? ?

293922. It is accessible from any other class.

293922. It must be final if it is declared in a method scope.

293922. It can only be instantiated in the enclosing class.

293922. It can access private instance variables in the enclosing object. (***)

293923. Which of the following are true? ?

293923. An event listener may be removed from a component (***)

293923. The ActionListener interface has corresponding Adapter class

293923. The processing of an event listener requires a try<FONT face=Symbol>¤</FONT>catch block

293923. A component may have only one event listener attached at a time

50

293924. Which most closely matches a description of a Java Map? ?

293924. A vector of arrays for a 2D geographic representation

293924. A class for containing unique array elements

293924. An interface that ensures that implementing classes cannot contain duplicates (***)

293924. A class for containing unique vector elements

293925. What can contain objects that have a unique key field of String type, if it is required to retrieve the objects

using that <BR>key field as an index? ?

293925. Enumeration (***)

293925. Set

293925. List

293925. Collection

293926. You want to lay out a set of buttons horizontally but with more space between the first button and the rest.

<BR>

<BR>

You are going to use the GridBagLayout manager to control the way the buttons are set out. How will you modify the

way the GridBagLayout acts in order to change the spacing around the first button? ?

293926. Create an instance of the GridBagConstraints class, call the weightx() method and then pass the

GridBagConstraints instance with the component to the setConstraints method

<BR>

of the GridBagLayout class.

293926. Create an instance of the GridBagConstraints class, set the weightx field and then pass the

GridBagConstraints instance

<BR>

with the component to the setConstraints method of the

<BR>

GridBagLayout class. (***)

293926. Create an instance of the GridBagLayout class, set the

<BR>

weightx field and then call the setConstraints method of

<BR>

the GridBagLayoutClass with the component as a parameter.

293926. Create an instance of the GridBagLayout class, call the setWeightx() method and then pass the

GridBagConstraints

<BR>

instance with the component to the setConstraints method

<BR>

of the GridBagLayout class.

293927. You need to create a class that will store a unique object elements. You do not need to sort these elements

but they must be unique.

<BR>

What interface might be most suitable to meet this need? ?

293927. Set (***)

293927. List

293927. Map

51

293927. Vector

293928. How does the set collection deal with duplicate elements? ?

293928. An exception is thrown if you attempt to add an element with a duplicate value

293928. The add method returns false if you attempt to add an element with a duplicate value (***)

293928. Duplicate values will cause an error at compile time

<BR>

Question Help.

293928. A set may contain elements that return duplicate values from a call to the equals method

293929. Which of the following statements are correct? ?

293929. If multiple listeners are added to a component only events for the last listener added will be <BR>processed

293929. If multiple listeners are added to a component the events will be processed for all but with no

<BR>guarantee in the order (***)

293929. You&nbsp;cannot remove listeners&nbsp;from a component.

293929. Adding multiple listeners to a component will cause a compile time error

293930. Which of the following statements are true? ?

293930. Constructors are not inherited (***)

293930. Constructors can be overriden

293930. Any method may contain a call to this or super

293930. A parental constructor can be invoked using this

293931. You are creating an applet with a Frame that contains buttons. You are using the GridBagLayout manager

and you have added Four buttons. At the moment the buttons appear in the centre of the frame from left to right. You

want them to appear one on top of the other going down the screen. What is the most appropriate way to do this. ?

293931. Set the gridy value of the GridBagConstraint class to a value increasing from 1 to 4 (***)

293931. Set the fill value of the GridBagConstrint class to VERTICAL

293931. Set the fill value of the GridBagLayout class to GridBag.VERTICAL

293931. Set the ipady value of the GridBagConstraint class to a value increasing from 0 to 4

293932. Which of the following are collection classes ?

293932. Collection

293932. Iterator

293932. Array

293932. HashSet (***)

293933. Which of the following will compile with error: ?

293933. import java.awt.*; <BR>package Mypackage; <BR>class Myclass {}

293933. package MyPackage; <BR>import java.awt.*; <BR>class MyClass{} (***)

293933. <FONT face=Symbol>¤</FONT>*This is a comment *<FONT face=Symbol>¤</FONT> <BR>package

MyPackage; <BR>import java.awt.*; <BR>class MyClass{}

293933. package Mypackage; <BR>class Myclass {}<BR>import java.awt.*;

293934. What best describes the apprearance of an applet

<BR>

with the following code?

<BR>

52

import java.awt.*;

<BR>

public class FlowAp extends Frame{

<BR>

public static void main(String argv[]){

<BR>

FlowAp fa=new FlowAp();

<BR>

fa.setSize(400,300);

<BR>

fa.setVisible(true);

<BR>

}

<BR>

FlowAp(){

<BR>

add(new Button("One"));

<BR>

add(new Button("Two"));

<BR>

add(new Button("Three"));

<BR>

add(new Button("Four"));

<BR>

}<font face="Symbol">&#164;</font><font face="Symbol">&#164;</font>End of constructor

<BR>

}<font face="Symbol">&#164;</font><font face="Symbol">&#164;</font>End of Application ?

293934. A Frame with buttons marked One to Four placed on each edge.

293934. A Frame with buutons Makred One to four running

<BR>

from the top to bottom

293934. An Error at run time indicating you have not set a

<BR>

LayoutManager

293934. A Frame with one large button marked Four in the Centre (***)

293935. What will happen when you attempt to compile and run this code?

<BR>

<font face="Symbol">&#164;</font><font face="Symbol">&#164;</font>Demonstration of event handling

<BR>

import java.awt.event.*;

<BR>

import java.awt.*;

<BR>

public class MyWc extends Frame implements WindowListener{

<BR>

public static void main(String argv[]){

<BR>

53

MyWc mwc = new MyWc();

<BR>

}

<BR>

public void windowClosing(WindowEvent we){

<BR>

System.exit(0);

<BR>

}<font face="Symbol">&#164;</font><font face="Symbol">&#164;</font>End of windowClosing

<BR>

public void MyWc(){

<BR>

setSize(300,300);

<BR>

setVisible(true);

<BR>

}

<BR>

}<font face="Symbol">&#164;</font><font face="Symbol">&#164;</font>End of classÿÿ ?

293935. Error at compile time (***)

293935. Visible Frame created that that can be closed

293935. Compilation but no output at run time

293935. Error at compile time because of comment before import statements

293936. Under what circumstances might you use the yield method of the Thread classport ?

293936. To call from the currently running thread to allow another thread of the same priority to run (***)

293936. To call on a waiting thread to allow it to run

293936. To allow a thread of higher priority to run

293936. To call from the currently running thread with a parameter designating which thread should be allowed

<BR>

to run.

293937. What will happen when you attempt to compile and run the following code?

<BR>

<BR>

class Background implements Runnable{

<BR>

int i=0;

<BR>

public int run()

<BR>

while(true)

<BR>

i++;

<BR>

System.out.println("i="+i);

<BR>

54

} <font face="Symbol">&#164;</font><font face="Symbol">&#164;</font>End while

<BR>

}<font face="Symbol">&#164;</font><font face="Symbol">&#164;</font>End run

<BR>

}<font face="Symbol">&#164;</font><font face="Symbol">&#164;</font>End class ?

293937. It will compile and the run method will print out the increasing value of i

293937. It will compile and calling start will print out the increasing value of i

293937. Compilation will cause an error because while cannot take a parameter of true.

293937. The code will cause an error at compile time. (***)

293938. Which of the following is successfully create an instance of the Vector class and add an element? ?

293938. Vector v=new Vector(99);

<BR>

v[1]=99;

293938. Vector v=new Vector();

<BR>

v.addElement(99);

293938. Vector v=new Vector();

<BR>

v.add(99);nt(99);

293938. Vector v=new Vector(100);

<BR>

v.addElement("99"); (***)

293939. Which of the following statements about threading are true? ?

293939. You can only obtain a mutually exclusive lock on methods in a class that extends Thread or implements

<BR>

runnable

293939. You can obtain a mutually exclusive lock on any object (***)

293939. Thread scheduling algorithms are platform dependent

293939. A thread can obtain a mutex lock on a method declared with the keyword synchronized

293940. Which of the following are true ? ?

293940. The elements of a Collection class can be ordered by using the sort method of the Collection interface.

293940. You can create an ordered Collection by instantiating a class that implements the List interface. (***)

293940. The Collection interface sort method takes parameters of A or D to change the sort order, Ascending<font

face="Symbol">&#164;</font>Descending.

293940. The elements of a Collection class can be ordered by using the order method of the Collection interface

293941. Which of the following is the correct syntax for suggesting that the JVM performs garbage collection? ?

293941. System.free();

293941. System.setGarbageCollection();

293941. System.out.gc();

293941. System.gc(); (***)

293942. Which of the following are methods of the Runnable interface? ?

293942. run (***)

293942. start

293942. stop

55

293942. yield

293943. What happens when you attempt to compile and

<BR>

run these two files in the same directory?

<BR>

<font face="Symbol">&#164;</font><font face="Symbol">&#164;</font>File P1.java

<BR>

package MyPackage;

<BR>

class P1{

<BR>

void afancymethod(){

<BR>

System.out.println("What a fancy method");

<BR>

}

<BR>

}

<BR>

<font face="Symbol">&#164;</font><font face="Symbol">&#164;</font>File P2.java

<BR>

public class P2 extends P1{

<BR>

afancymethod();

<BR>

} ?

293943. Both compile and P2 outputs "What a fancy method"

<BR>

when run

293943. Neither will compile2

293943. P1 compiles cleanly but P2 has an error at compile time (***)

293943. Both compile but P2 has an error at run time

293944. Which of the following statements are true? ?

293944. At the root of the collection hierarchy is a class called Collection

293944. The collection interface contains a method called enumerator

293944. The set interface is designed for unique elements (***)

293944. The interator method returns an instance of the Vector classllection

293945. The drag-and-drop API uses the ________ API to transfer data through drag-and-drop operations. ?

293945. resizable, closable, maximizable, (***)

293945. JInternalFrame, JDesktopPane.

293945. Accessibility

293945. maximizable,

293946. A multiple document interface uses instances of class for individual windows, which are contained in a

_____________ ?

293946. resizable, closable, maximizable,

56

293946. JInternalFrame, JDesktopPane. (***)

293946. Accessibility

293946. maximizable,

293947. For JavaBeans that do not follow the JavaBean design pattern, or for JavaBeans in which the programmer

wants to customize the exposed set of properties, methods and events, the programmer can supply a _________ class

that describes to the builder tool how to present the features of the bean. ?

293947. BeanInfo Editor (***)

293947. Explorer

293947. PropertyDescriptor.

293947. Component Inspector,

293948. JavaBeans should all implement the _________ interface so they can be saved from a builder tool after being

customized by the programmer. ?

293948. PropertyEditor. (***)

293948. Component Inspector

293948. EventSetDescriptor.

293948. BeanInfo.

293949. A ________ object is used to submit a query to a database. ?

293949. Statement. (***)

293949. dataset

293949. Connection.

293949. java.sql

293950. Interface _______ helps manage the connection between the Java program and the database. ?

293950. Connection. (***)

293950. ResultSet

293950. Statement.

293950. java.sql

293951. Package _______ contains classes and interfaces for manipulating relational databases in Java. ?

293951. java.sql (***)

293951. java.connection

293951. sql.rar

293951. sql.java

293952. If an application uses ___________________________________, the database server only has to check the

syntax and prepare an execution plan once for each SQL statement. ?

293952. prepared statements (***)

293952. ResultSetMetaData

293952. connection pooling

293952. OR mapping (object to relational

293953. To improve the performance of database operations, an application can use

____________________________________ where a limited number of connections are opened and are shared by

users of the database. ?

293953. init

293953. ResultSetMetaData

57

293953. connection pooling (***)

293953. OR mapping (object to relational)

293954. A _________________________________ object contains information about a result set like the numbers

and names of the columns in the result set. ?

293954. prepared statements

293954. ResultSetMetaData (***)

293954. connection pooling

293954. OR mapping (object to relational)

293955. A method that takes a Student object and writes it to the Student table in a database implements

__________________________________________. ?

293955. OR mapping (object to relational) (***)

293955. init, destroy

293955. ResultSetMetaData

293955. connection pooling

293956. Before your application can create a Connection object, it must use the forName method of the Class class to

load ?

293956. a database driver (***)

293956. an ODBC data source

293956. JDBC

293956. a DBMS

293957. The methods of what type of object can be used to move the cursor through a result set? ?

293957. Statement (***)

293957. ResultSet

293957. URL

293957. Connection

293958. A file that stores one or more SQL statements is known as a

__________________________________________. ?

293958. SQL script (***)

293958. SQL statement

293958. result set

293958. connection

293959. After a SELECT statement, a _______________________________ is a logical table that's created

temporarily within the database. ?

293959. result set (***)

293959. dataset

293959. datareader

293959. recordset

293960. To uniquely identify each row in a table, a relational database uses a ?

293960. foreign key

293960. primary key (***)

293960. relational database management system

293960. record

58

293961. The result set retrieved by the following SELECT statement contains records that have

<BR>

SELECT Balance, Num

<BR>

FROM Accounts

<BR>

WHERE Balance <font face="Symbol">&#60;</font> 0

<BR>

?

293961. one field from the Balance table where Account Num is less than 0

293961. two fields from the Balance table where Account Num is less than 0

293961. two fields from the Accounts table where Balance is less than 0 (***)

293961. all fields from the Accounts table where Balance is less than 0

293962. Which of the following is NOT a way to insert data into a table? ?

293962. an INSERT statement

293962. a LOAD command

293962. a configuration file (***)

293962. a SQL script

293963. When you code an inner join in a SELECT statement you do not need to specify ?

293963. a join column for the second table

293963. the name of the second table

293963. a join column for the first table

293963. an ORDER BY clause (***)

293964. The scope of a bean is determined by the ?

293964. bean class

293964. object that stores the bean (***)

293964. name of the bean

293964. id of the bean

293965. The Id attribute in the useBean tag must match ?

293965. the name attribute in the getProperty tag (***)

293965. the name of the bean class

293965. the value attribute in the setProperty tag

293965. the property attribute in the getProperty tag

293966. You can include a double quote mark within the value of an attribute by ?

293966. not enclosing the attribute in quotes

293966. enclosing the attribute in double quotes

293966. coding a backslash after the double quote mark

293966. enclosing the attribute in single quotes (***)

293967. You have to create an interface in the com.mycorp package to be used only within the package. One

requirement is that classes implementing this interface must be Runnable. <BR><BR>Choose the simplest interface

declaration that will accomplish this requirement. ?

293967. interface TheInterface extends Runnable

59

293967. public interface TheInterface extends Runnable

293967. interface TheInterface implements Runnable (***)

293967. public abstract interface TheInterface extends Runnable

293968. Which of the following statements about java.util.Iterator are correct? ?

293968. Iterators are used to set the values in a collection.

293968. Iterators are used to retrieve the values in a collection. (***)

293968. An Iterator can impose a new ordering on a collection.

293968. java.lang.Iterator is an class.

293969. Which of the following statements about the hashcode() method are incorrect? Select all incorrect

statements. ?

293969. The value returned by hashcode() is used in some collection classes to help locate objects.

293969. The hashcode() method is required to return a positive int value. (***)

293969. The hashcode() method in the String class is the one inherited from StringBuilder class.

293969. Two new empty String objects will produce identical hashcodes.

293970. Which of the following statements are true? ?

293970. A correctly implemented hashCode method will always return the same value

293970. If two objects are equal according to the equals method, they&nbsp;may return the&nbsp;difference

hashCode value.

293970. If two objects are not equal according to the equals method, they must return different hashCode values.

293970. The default implementation of equals is to return the memory address of the object. (***)

293971. Which of the following statements are true? [Check all correct answers.] ?

293971. The HashMap class implements the Collection interface

293971. The HashSetMap class ensures unique elements stored as key<font face="Symbol">&#164;</font>value

pairs.

293971. The LinkedHashSet class ensures elements are unique and ordered. (***)

293971. The iterator method returns elements in the order they were added.

293972. Which of the following statements are NOT true? ?

293972. The Vector class implements the Collection interface.

293972. The elements of a class that implement the List interface are ordered.

293972. The TreeSet class stores its keys in sorted order. (***)

293972. The sort method of the Collections class takes a parameter of type List.

293973. What will happen when you attempt to compile and run the following code? <BR><BR>import java.util.*;

<BR>public class TeaSet { <BR>public static void main(String argv[]){ <BR>TreeSet ts = new TreeSet();

<BR>ts.add("a"); <BR>ts.add("z"); <BR>ts.add("c"); <BR>ts.add("a"); <BR>Iterator it = ts.iterator();

<BR>while(it.hasNext()){ <BR>System.out.println(it.next()); <BR>} <BR>} <BR>} ?

293973. Compilation and output of elements in the order they were added.

293973. Compilation and output of the elements in the order a followed by c followed by z. (***)

293973. Compilation but runtime exception due to an attempt to add a duplicate element.

293973. Compilation and output of all elements in an unspecified order.

293974. What happens when you attempt to compile and run the following code? <BR><BR>import java.util.*;

<BR>public class RapCollect { <BR>public static void main(String argv[]){ <BR>HashMap hm = new HashMap();

<BR>hm.put("one", new Integer(1)); <BR>hm.put("two", new Integer(2)); <BR>hm.put("three",new Integer(3));

60

<BR>Set set = hm.keySet(); <BR>Iterator it = set.iterator(); <BR>while (it.hasNext()){ <BR>Integer iw = it.next();

<BR>System.out.println(iw.intValue()); <BR><BR>} <BR>} <BR>} ?

293974. Compilation is fine but an error occurs at runtime.

293974. Compile-time error; fault with arguments with put method.

293974. Compile-time error; code error within the while loop. (***)

293974. Compile-time error; HashMap has no keySet method.

293975. Which of the following statements are true? ?

293975. The Map interface maps values to keys and does not allow duplicate values.

293975. The toArray method of HashMap returns the elements in the form of an array.

293975. The Set interface ensures that implementing classes do not have duplicate elements. (***)

293975. The Vector class has a getObject(int index) method that returns the element at the specified position.

293976. An object of the Hashtable class can store and retrieve object references based on associated "key" objects.

Which interface does Hashtable implement? ?

293976. SortedMap

293976. SortedSet

293976. Map (***)

293976. List

293977. Which of the following are NOT&nbsp;interfaces? ?

293977. java.util.AbstractList

293977. java.util.SortedMap

293977. java.util.Iterator

293977. java.util.TreeMap (***)

293978. Which of the following statements are true? ?

293978. The iterator method of the Map interface allows you to traverse each element of an implementing class.

293978. The HashMap class stores elements alphabetically.

293978. LinkedHashMap returns elements in the order they were added. (***)

293978. New elements can be added to an instance of LinkedHashMap by calling the add(Object key, Object value)

method.

293979. What will happen when you attempt to compile and run the following code? <BR><BR>import java.util.*;

<BR>public class Stage{ <BR>public static void main(String argv[]){ <BR>LinkedHashSet lhs = new

LinkedHashSet(); <BR>lhs.add("one"); <BR>lhs.add("two"); <BR>lhs.add("One"); <BR>lhs.add("one");

<BR>Iterator it = lhs.iterator(); <BR>while(it.hasNext()){ <BR>System.out.print(it.next()); <BR>} <BR>} <BR>} ?

293979. Compilation and output of onetwoOneone

293979. Compilation and output of onetwoOne (***)

293979. Compilation and output of oneOnetwoone

293979. Compilation and output of every element added

293980. Which of the following statements about the java.util.Vector and java.util.Hashtable classes are correct? ?

293980. A Hashtable requires string objects as keys.

293980. A Hashtable maintains object references in the order they were added.

293980. Both Vector and Hashtable use synchronized methods to avoid problems due to more than one thread trying

to access the same collection. (***)

293980. A Vector cannot&nbsp;maintain object references in the order they were added.

61

293981. You have created a TimeOut class as an extension of thread, the purpose of which is to print a "Time's Up"

message if the thread is not interrupted within 10 seconds of being started.

<BR>

<BR>

Here is the run method that you have coded:

<BR>

<BR>

1. public void run(){

<BR>

2. System.out.println("Start!");

<BR>

3. try { Thread.sleep(10000 );

<BR>

4. System.out.println("Time's Up!");

<BR>

5. }catch(InterruptedException e){

<BR>

6. System.out.println("Interrupted!");

<BR>

7. }

<BR>

8. }

<BR>

<BR>

Given that a program creates and starts a TimeOut object, which of the following statements is true?

<BR>

?

293981. Exactly 10 seconds after the start method is called, "Time's Up!" will be printed.

<BR>

293981. If "Time's Up!" is printed, you can be sure that at least 10 seconds have elapsed since "Start!" was printed.

(***)

293981. Exactly 10 seconds after "Start!" is printed, "Time's Up!" will be printed.

293981. The delay between "Start!" being printed and "Time's Up!" will be 10 seconds plus or minus one tick of the

system clock.

293982. You have written an application that can accept orders from multiple sources, each one of which runs in a

separate thread. One object in the application is allowed to record orders in a file. This object uses the recordOrder

method, which is synchronized to prevent conflict between threads.

<BR>

<BR>

While Thread A is executing recordOrder, Threads B, C, and D, in that order, attempt to execute the recordOrder

method. What happens when Thread A exits the synchronized method?

<BR>

?

62

293982. Thread B, as the first waiting thread, is allowed to execute the method.

<BR>

293982. One of the waiting threads will be allowed to execute the method, but you can't be sure which one it will be.

(***)

293982. Thread D, as the last waiting thread, is allowed to execute the method.

293982. Either A or D, but never C, will be allowed to execute.

<BR>

293983. Here is part of the code for a class that implements the Runnable interface: <BR><BR>1. public class

Whiffler extends Object <BR>implements Runnable { <BR>2. Thread myT ; <BR>3. public void start(){ <BR>4.

myT = new Thread( this ); <BR>5. } <BR>6. public void run(){ <BR>7. while( true ){ <BR>8. doStuff(); <BR>9. }

<BR>10. System.out.println("Exiting run"); <BR>11. } <BR>12. <FONT face=Symbol>¤</FONT><FONT

face=Symbol>¤</FONT> more class code follows.... <BR><BR>Assume that the rest of the class defines doStuff,

and so on, and that the class compiles without error. Also assume that a Java application creates a Whiffler object and

calls the Whiffler start method, that no other direct calls to Whiffler methods are made, and that the thread in this

object is the only one the application creates. Which of the following are correct statements? [Check all correct

answers.] ?

293983. The doStuff method will be called repeatedly.

293983. The doStuff method will execute at least one time.

293983. The doStuff method will never be executed. (***)

293983. The statement in line 8 will never be reached.

293984. You have written a class extending Thread that does time-consuming computations. In the first use of this

class in an application, the system locked up for extended periods of time. Obviously, you need to provide a chance

for other threads to run. The following is the run method that needs to be modified: <BR><BR>1. public void run(){

<BR>2. boolean runFlg = true ; <BR>3. while( runFlg ){ <BR>4. runFlg = doStuff(); <BR>5. <BR>6. } <BR>7. }

<BR><BR>Which statements could be inserted at line 5 to allow other threads a chance to run? ?

293984. yield(1000);

293984. wait( 100 );

293984. try{ sleep(100); } catch(InterruptedException e){ } (***)

293984. suspend( 100 );

293985. You are creating a class that extends Object and implements Runnable. You have already written a run

method for this class. You need a way to create a thread and have it execute the run method. Which of the following

start methods should you use? ?

293985. public void start(){ <BR>new Thread( this ).start(); <BR>} (***)

293985. public void start(){ <BR>Thread myT = new Thread(); <BR>myT.start(); <BR>}

293985. public void start(){ <BR>Thread myT = new Thread(this); <BR>myT.run(); <BR>}

293985. public void start(){ <BR>Thread myT = new Thread(new this()); <BR>myT.run(); <BR>}

293986. Which is the correct way to start a new thread? <BR><BR>Select the one correct answer. ?

293986. Create a new Thread object and call the method start(). (***)

293986. Create a new Thread object and call the method run().

293986. Create a new Thread object and call the method resume().

293986. Create a new Thread object and call the method begin().

63

293987. When extending the Thread class to provide a thread's behavior, which method should be overridden?

<BR><BR>Select the one correct answer. ?

293987. run() (***)

293987. resume()

293987. behavior()

293987. start()

293988. Which statements are true? ?

293988. Classes implementing the Runnable interface must define a method named start

293988. Calling the method run() on an object implementing Runnable will create a new thread.

293988. A program terminates when the last non-daemon thread ends. (***)

293988. The class Thread implements DoThreadable.

293989. What will be the result of attempting to compile and run the following program? <BR><BR>public class

MyClass extends Thread { <BR>public MyClass(String s) { msg = s; } <BR>String msg; <BR>public void run() {

<BR>System.out.println(msg); <BR>} <BR><BR>public static void main(String[] args) { <BR>new

MyClass("Hello"); <BR>new MyClass("World"); <BR>} <BR>} <BR><BR>Select the one correct answer ?

293989. The program will compile without errors and will print a never-ending stream of Hello and World.

293989. The program will compile without errors and will print Hello and World when run, but the order is

unpredictable.

293989. The program will compile without errors and will simply terminate without any output when run. (***)

293989. The program will compile without errors and will print Hello and World, in that order, every time the

program is run.

293990. Given the following program, which statement is&nbsp;guaranteed to be true? <BR><BR>public class

ThreadedPrint { <BR>static Thread makeThread(final String id, boolean daemon) { <BR>Thread t = new Thread(id)

{ <BR>public void run() { <BR>System.out.println(id); <BR>} <BR>}; <BR>t.setDaemon(daemon); <BR>t.start();

<BR>return t; <BR>} <BR><BR>public static void main(String[] args) { <BR>Thread a = makeThread("A", false);

<BR>Thread b = makeThread("B", true); <BR>System.out.print("End\n"); <BR>} <BR>} <BR><BR>Select the

correct answer. ?

293990. The letter A is never printed.

293990. The letter B is never printed after End.

293990. The program might print B, End and A, in that order. (***)

293990. The letter B is always printed.

293991. Which statement is true?

<BR>

<BR>

Select the one correct answer.

<BR>

?

293991. No two threads can concurrently execute synchronized methods on the same object.

<BR>

<BR>

(***)

64

293991. Inside a synchronized method, one can assume that no other threads are currently executing any other

methods in the same class.

<BR>

293991. Methods declared synchronized should not be recursive, since the object lock will not allow new invocations

of the method.

293991. Synchronized methods can only call other synchronized methods directly.

293992. Given the following program, which statement is true? <BR><BR>public class MyClass extends Thread {

<BR>static Object lock1 = new Object(); <BR>static Object lock2 = new Object(); <BR><BR>static volatile int i1,

i2, j1, j2, k1, k2; <BR><BR>public void run() { while (true) { doit(); check(); } } <BR><BR>void doit() {

<BR>synchronized(lock1) { i1++; } <BR>j1++; <BR>synchronized(lock2) { k1++; k2++; } <BR>j2++;

<BR>synchronized(lock1) { i2++; } <BR>} <BR><BR>void check() { <BR>if (i1 != i2) System.out.println("i");

<BR>if (j1 != j2) System.out.println("j"); <BR>if (k1 != k2) System.out.println("k"); <BR>} <BR><BR>public

static void main(String[] args) { <BR>new MyClass().start(); <BR>new MyClass().start(); <BR>} <BR>}

<BR><BR>Select the one correct answer ?

293992. One can be certain that none of the letters i, j, and k will ever be printed during execution.

293992. One can be certain that the letters i and k will never be printed during execution.

293992. One can be certain that the letter k will never be printed during execution

293992. One cannot be certain whether any of the letters i, j, and k will be printed during execution. (***)

293993. Which one of these events will cause a thread to die? <BR><BR>Select the one correct answer. ?

293993. Execution of the start() method ends.

293993. Execution of the run() method ends. (***)

293993. Execution of the thread's constructor ends.

293993. The method wait() is called.

293994. Which statement is&nbsp;true about the following code? <BR><BR>public class Joining { <BR>static

Thread createThread(final int i, final Thread t1) { <BR>Thread t2 = new Thread() { <BR>public void run() {

<BR>System.out.println(i+1); <BR>try { <BR>t1.join(); <BR>} catch (InterruptedException e) { <BR>}

<BR>System.out.println(i+2); <BR>} <BR>}; <BR>System.out.println(i+3); <BR>t2.start();

<BR>System.out.println(i+4); <BR>return t2; <BR>} <BR><BR>public static void main(String[] args) {

<BR>createThread(10, createThread(20, Thread.currentThread())); <BR>} <BR>} ?

293994. The number 24 is printed before the number 21.

293994. The last number printed is 12. (***)

293994. The number 11 is printed before the number 23.

293994. The number&nbsp;22 is printed before the number 14.

293995. What can be guaranteed by calling the method yield()? <BR><BR>Select the one correct answer. ?

293995. The current thread will not continue until other threads have terminated.

293995. The thread will wait until it is notified.

293995. The current thread will sleep for some time while some other threads run.

293995. None of the other answers (***)

293996. Where is the notify() method defined?

<BR>

<BR>

65

Select the one correct answer.

<BR>

?

293996. Thread

293996. Runnable

<BR>

293996. Object (***)

293996. Applet

293997. How can the priority of a thread be set?

<BR>

<BR>

Select the one correct answer

<BR>

?

293997. By using the setPriority() method in the class Thread. (***)

293997. None of the other answers

293997. By passing the priority as a parameter to the constructor of the thread.

293997. Both of the other answers

293998. Which statements are true about locks? ?

293998. Invoking wait() on an object whose lock is held by the current thread will relinquish the lock. (***)

293998. Invoking notify() on a object whose lock is held by the current thread will relinquish the lock.

293998. Multiple threads can hold the same lock at the same time.

293998. Invoking wait() on a Thread object will relinquish all locks held by the thread

293999. What will be the result of invoking the wait() method on an object without ensuring that the current thread

holds the lock of the object?

<BR>

<BR>

Select the one correct answer.

<BR>

?

293999. The code will fail to compile.

293999. The thread will be blocked until it gains the lock of the object.

<BR>

293999. Nothing special will happen.

293999. An IllegalMonitorStateException will be thrown if the wait() method is called while the current thread does

not hold the lock of the object. (***)

294000. Which code provides a correct implementation of the hashCode() method in the following program?

<BR><BR>import java.util.*; <BR>public class Measurement { <BR>int count; <BR>int accumulated; <BR>public

Measurement() {} <BR>public void record(int v) { <BR>count++; <BR>accumulated += v; <BR>} <BR>public int

average() { <BR>return accumulated<FONT face=Symbol>¤</FONT>count; <BR>} <BR>public boolean

equals(Object other) { <BR>if (this == other) <BR>return true; <BR>if (!(other instanceof Measurement))

66

<BR>return false; <BR>Measurement o = (Measurement) other; <BR>if (count != 0 <FONT

face=Symbol>&amp;</FONT><FONT face=Symbol>&amp;</FONT> o.count != 0) <BR>return average() ==

o.average(); <BR>return count == o.count; <BR>} <BR>public int hashCode() { <BR><FONT

face=Symbol>¤</FONT><FONT face=Symbol>¤</FONT> ... PROVIDE IMPLEMENTATION HERE ... <BR>}

<BR>} ?

294000. return (count <FONT face=Symbol>&lt;</FONT><FONT face=Symbol>&lt;</FONT> 16) ^ accumulated;

(***)

294000. return ~accumulated;

294000. return count == 0 ? 0 : ~average();

294000. return accumulated <FONT face=Symbol>¤</FONT> count;

294001. Which collection implementation is thread-safe? <BR><BR>Select the one correct answer. ?

294001. Vector (***)

294001. TreeSet

294001. LinkedList

294001. HashSet

294002. What code fagment as bellow can NOT be insert into the equalsImpl() method in order to provide a correct

implementation of the equals() method<BR>public class Pair { <BR>int a, b; <BR>public Pair(int a, int b) {

<BR>this.a = a; <BR>this.b = b; <BR>} <BR><BR>public boolean equals(Object o) { <BR>return (this == o) || (o

instanceof Pair) <FONT face=Symbol>&amp;</FONT><FONT face=Symbol>&amp;</FONT> equalsImpl((Pair)

o); <BR>} <BR><BR>private boolean equalsImpl(Pair o) { <BR><FONT face=Symbol>¤</FONT><FONT

face=Symbol>¤</FONT> ... PROVIDE IMPLEMENTATION HERE ... <BR>} <BR>} ?

294002. return a <FONT face=Symbol>&gt;</FONT>= o.a; (***)

294002. return a == o.a;

294002. return a == o.a <FONT face=Symbol>&amp;</FONT><FONT face=Symbol>&amp;</FONT> b == o.b;

294002. return false;

294003. List the Required Classes<font face="Symbol">&#164;</font>Interfaces That Must Be Provided for an

Enterprise JavaBeans Component

<BR>

<BR>

Which of the following is not true about EJB objects?

<BR>

?

294003. The home interface is responsible for locating or creating instances of the desired bean and returning remote

references

294003. The bean must implement one ejbCreate() method for each create() method in the home interface.

<BR>

294003. The remote interface, or the EJBObject interface, typically provides method signatures for business methods.

294003. The bean implements either the EntityBean interface or the SessionBean interface but need not implement all

the methods defined in the remote interface. (***)

294004. Distinguish Between Session and Entity Beans

<BR>

<BR>

67

Which statement is not true when contrasting the use of entity beans and JDBC for database operations?

<BR>

?

294004. Entity beans represent real data in a database.

294004. When using JDBC, you must explicitly handle the database transaction and the database connection pooling.

<BR>

294004. The bean managed entity bean functionally replaces the JDBC API. (***)

294004. The container-managed entity bean automatically retrieves the data from the persistent storage (database).

294005. Which of the following is not true about EJB session bean objects? ?

294005. A session bean can be defined without an ejbCreate() method. (***)

294005. The stateless session bean class must contain exactly one ejbCreate() method without any arguments.

<BR>

294005. Stateful beans can contain multiple ejbCreate() methods as long as they match the home interface definition.

294005. The home interface of a stateless session bean must include a single create() method without any arguments.

<BR>

<BR>

294006. Which distributed object technology is most appropriate for systems that consist entirely of Java objects? ?

294006. RMI (***)

294006. DCE

294006. CORBA

294006. DCOM

294007. Which of the following is not true when discussing application servers and web servers? ?

294007. A web server understands and supports only the HTTP protocol.

<BR>

<BR>

294007. We can configure application servers to work as web servers.

<BR>

294007. An application server supports HTTP, TCP<font face="Symbol">&#164;</font>IP, and many more

protocols.

294007. A web server does not support caching, clustering, and load balancing. (***)

294008. Which of the following is not true about RMI? ?

294008. RMI uses the Proxy design pattern.

294008. The RMI client can communicate with the server without knowing the server‟s physical location.

<BR>

294008. RMI uses object serialization to send objects between JVMs.

294008. The RMI Registry is used to generate stubs and skeletons. (***)

68

294009. The RMI compiler rmic runs on which of the following files to produce the stub and skeleton classes? ?

294009. On the remote interface class file

294009. On the remote interface Java file

<BR>

294009. On the remote service implementation class file

294009. On the remote service implementation Java file (***)

294010. An object that implements the interfaces java.rmi.Remote and java.io.Serializable is being sent as a method

parameter from one JVM to another. How would it be sent by RMI? ?

294010. RMI will serialize the object and send it.

294010. RMI will send the stub of the object. (***)

294010. RMI will send the&nbsp;raw object.

294010. RMI will send the&nbsp;description of the object.

294011.

<BR>

For a system consisting of exclusively Java objects, which distributed technology would be most appropriate for

communication?

<BR>

?

294011. CORBA

294011. JavaBeans

<BR>

294011. RMI (***)

294011. JNDI

294012. What is the parent class of JComponent? ?

294012. java.awt.JComponent

294012. java.awt.Container (***)

294012. javax.swing.Component

294012. java.awt.Frame

294013. How do Swing menus differ from AWT menus? ?

294013. Swing menus are round.

294013. Swing menus are components. (***)

294013. None of the other answers

294013. Swing menus are implemented in separate windows.

294014. Which of the following is true about Swing icons? ?

294014. They can be added to Swing labels, buttons, and menu items. (***)

294014. None of the other answers

294014. They are limited to JPEG images.

294014. They are limited to 16 colors?

294015. Which of the following is not a Swing border? ?

294015. SoftBevelBorder

294015. CompoundBorder

69

294015. EtchedBorder

294015. SoftEtchedBorder (***)

294016. How do you group a set of option buttons with a border and title? ?

294016. You add all the buttons to a JWindow.

294016. You add the buttons in various ways, but you group them programmaticall

294016. You add each button to its own JFrame and then add all those JFrames to a window

294016. You place the option buttons you want to group in a JPanel, and then you add a border to the JPanel. (***)

294017. How do you create a multiple selection mode JComboBox? ?

294017. Use a JList for multiple selection because JComboBox is only single selection. (***)

294017. With: setMode(MULTIPLE_SELECTION).

294017. With: setSelectionMode(true)

294017. With: setMode(true)

294018. How do you properly size a component immediately after creating it? ?

294018. With: addContainerListener().

294018. With: doLayout().

294018. With: addNotify(). (***)

294018. With: setComponentOrientation().

294019. How can you determine which component has the focus? ?

294019. You poll through all components in a loop until this is true: getFocus(componentName).

294019. You use getFocus() from the top window.

294019. You poll through all components in a loop with isActive.

294019. You use getFocusOwner from the top window. (***)

294020. Which of the following is not a top-level container? ?

294020. JTabbedPane (***)

294020. JDialog

294020. JFrame

294020. JApplet

294021. What of the following has all of the visible components

<BR>

in the window‟s GUI? ?

294021. The internal viewport.

294021. Intermediate-containers.

294021. The content pane. (***)

294021. Internally, Java keeps all visible components in a collection.

294022. Which Design Pattern does the JTextComponent use? ?

294022. Session Façade.

294022. Aggregate Entity.

294022. Value Object.

294022. Model-View-Controller. (***)

294023. How are computers on the Internet located? ?

294023. By their registration number

70

294023. By their Internet ID number (***)

294023. By their IP address

294023. By their locator chip

294024. What is the role of domain name servers? ?

294024. To identify well-known ports

294024. To map well-known ports to protocols

294024. To associate computer names and their IP addresses (***)

294024. None of the other answers

294025. What is the well-known port number of HTTP? ?

294025. 8000

294025. 8080

294025. 80 (***)

294025. 8

294026. Which of the following applications is best implemented using a UDP protocol? ?

294026. Internet time updates

294026. Video and audio streaming (***)

294026. File transfer

294026. Remote terminal access

294027. Which of the following are NOT&nbsp;characteristic of TCP? ?

294027. Connection-oriented

294027. Connectionless (***)

294027. Reliability

294027. Use of port numbers as addresses

294028. Which of the following communicates with a database server on behalf of a user or application? ?

294028. Database table

294028. Database client (***)

294028. Web server

294028. Web browser

294029. Which of the following describes a JDBC type 4 driver? ?

294029. Native-protocol pure Java driver (***)

294029. JDBC-Net pure Java driver

294029. JDBC-ODBC bridge plus ODBC driver

294029. Native-API partly Java driver

294030. How is the forName() method of the Class class used with JDBC? ?

294030. To establish a database connection

294030. To load a JDBC driver (***)

294030. To execute a SQL statementresses

294030. To load a result set

294031. Which java.sql class provides the getConnection() method? ?

294031. Connection

294031. ResultSet

71

294031. Driver

294031. DriverManager (***)

294032. Which java.sql class or interface is used to create a Statement object? ?

294032. DriverManager

294032. Driver

294032. Connection (***)

294032. ResultSet

294033. Which java.sql class or interface contains methods that enable you to find out the number of columns this is

returned in a ResultSet and the name or label for a given column? ?

294033. Statement

294033. MetaData

294033. CallableStatement

294033. ResultSetMetaData (***)

294034. Which java.sql class or interface is used to create the object that is necessary for calling stored procedures? ?

294034. ResultSet

294034. CallableStatement (***)

294034. PreparedStatement

294034. Statement

294035. When a thread blocks on I<font face="Symbol">&#164;</font>O, which of the following is true? ?

294035. The thread enters the ready state.

294035. The thread enters the dead state. (***)

294035. The thread enters the waiting state.

294035. No other thread can perform I<font face="Symbol">&#164;</font>O.

294036. What statements are true concerning the method notify() that is used in conjunction with wait? ?

294036. notify() should only be invoked from within a while loop .

294036. if there is more than one thread waiting on a condition, there is no way to predict which thread will be

notifed (***)

294036. notify() is defined in the Thread class

294036. it is not strictly necessary to own the lock for the object you invoke notify() for

294037. What can you write at the comment:

<BR>

<BR>

<font face="Symbol">&#164;</font><font face="Symbol">&#164;</font>A in the code below so that this program

writes the word 'running' to the standard output?

<BR>

<BR>

class RunTest implements Runnable {

<BR>

public static void main(String[] args) {

<BR>

72

RunTest rt = new RunTest();

<BR>

Thread t =new Thread(rt);

<BR>

<font face="Symbol">&#164;</font><font face="Symbol">&#164;</font>A

<BR>

}

<BR>

<BR>

public void run() {

<BR>

System.out.println("running");

<BR>

}

<BR>

void go() {

<BR>

start(1);

<BR>

}

<BR>

void start(int i) {

<BR>

}

<BR>

}

<BR>

?

294037. System.out.println("running"); (***)

294037. rt.start();

294037. rt.start(1);

294037. rt.go();

294038. What must be true for the RuriHandler class so that instances of RunHandler can be used as written in the

code below: <BR>class Test { <BR>public static void main(String[] args) { <BR>Thread t = new Thread(new

RunHandler()); <BR>t.start(); <BR>} <BR>} ?

294038. RunHandler must implement the java.lang.Runnable interface. (***)

294038. RunHandler must extend the Thread class.

294038. RunHandler must provide an init() method.

294038. RunHandler must provide a run() method declared as public and returning int.

294039. A Socket object has been created and connected to a standard Internet service on a remote network server.

Which construction would give the most suitable means for reading ASCII data one line at a time from the Socket? ?

294039. BufferedReader in = new BufferedReader(new InputStreamReader(s .getlnputStream(), "8859_i"));

294039. Datainputstream in = new Datalnputstream(s.getlnputstream());

294039. BufferedReader in = new BufferedReader(new InputStreamReader(s .getlnputStream()); (***)

294039. ByteArraylnputStream in = new ByteArraylnputstream(s.getlnputstream());

73

294040. Suppose that a database server does not support a pure JDBC driver, but it does support an ODBC driver.

How can you access the database server using JDBC?

<BR>

?

294040. Use SQL.

294040. Use JNDI.

294040. Use Java RMI.

294040. Use the JDBC-ODBC bridge driver. (***)

294041. Which of the following are contained in a Java security policy file? ?

294041. grant entries (***)

294041. trusted code

294041. digital certificates

294041. aliases and their public keys

294042. A class design requires that a particular member variable must be accessible for direct access by any

subclasses of this class, but otherwise not by classes which are not members of the same package. What should be

done to achieve this? ?

294042. The variable should be marked private and an accessor method provided

294042. The variable should be marked private

294042. The variable should have no special access modifier

294042. The variable should be marked protected (***)

294043. What can you write at the comment:

<BR>

I<font face="Symbol">&#164;</font>A in the code below so that this program writes the word 'running' to the

standard output?

<BR>

class RunTest implements Runnable {

<BR>

public static void main(String[] args) {

<BR>

RunTest rt - new RunTest();

<BR>

Thread t -new Thread(rt);

<BR>

<font face="Symbol">&#164;</font><font face="Symbol">&#164;</font>A

<BR>

}

<BR>

public void run() {

<BR>

System.out.println('running');

<BR>

}

<BR>

void go() {

<BR>

74

start(1);

<BR>

}

<BR>

void start(int i) {

<BR>

}

<BR>

}

<BR>

?

294043. System.out.println('running'); (***)

294043. rt.start();

294043. rt.start(1);

294043. rt.go();

294044. Which of the following correctly illustrate how an InputStreamReader can be created: ?

294044. new InputStreamReader(System.in); (***)

294044. new InputStreamReader(new FileReader("data"));

294044. new InputStreamReader("data");

294044. new InputStreamReader(new BufferedReader("data"));

294045. What must be true for the RunHandler class so that instances of RunHandler can be used as written in the

code below: <BR><BR>class Test { <BR>public static void main(String[] args) { <BR>Thread t = new Thread(new

RunHandler()); <BR>t.start(); <BR>} <BR>} ?

294045. RunHandler must implement the java.lang.Thread interface. RunHandler must extend the Thread class.

294045. RunHandler must implement the java.lang.Runnable interface.&nbsp; RunHandler must extend the Thread

class.

294045. RunHandler must implement the java.lang.Runnable interface. RunHandler must provide an init() method.

294045. RunHandler must provide a run() method declared as public and returning void. RunHandler must

implement the java.lang.Runnable interface. (***)

294046. What is the effect of issuing a wait() method on an object ?

294046. If a notify() method has already been sent to that object then it has no effect

294046. The object issuing the call to wait() will halt until another object sends a notify() or notifyAll() method (***)

294046. The object issuing the call to wait() will be automatically synchronized with any other objects using the

receiving object.

294046. An exception will be raised

294047. You are concerned about that your program may attempt to use more memory than is available. To avoid this

situation you want to ensure that the Java Virtual Machine will run its garbage collection just before you start a

complex routine. What can you do to be certain that garbage collection will run when you want. ?

294047. You cannot be certain when garbage collection will run (***)

294047. Use the Runtime.gc() method to force garbage collection

294047. Use the System.gc() method to force garbage collection.

294047. Ensure that all the variables you require to be garbage collected are set to null

294048. What statements are true concerning the method notify() that is used in conjunction with wait()? ?

294048. notify() should only be invoked from within a while loop.

75

294048. if there is more than one thread waiting on a condition. there is no way to predict which thread will be

notifed (***)

294048. it is not strictly necessary to own the lock for the object you invoke notify() for

294048. notify() is defined in the Thread class

294049. Analyze the following code:

<BR>

class WhatHappens implements Runnable {

<BR>

public static void main(String[] args) {

<BR>

Thread t = new Thread(this);

<BR>

t.start();

<BR>

}

<BR>

public void run() {

<BR>

System.out.println("hi");

<BR>

}

<BR>

}

<BR>

<BR>

?

294049. This program does not compile (***)

294049. This program compiles but nothing appears in the standard output

294049. This program compiles and the word "hi" appears continuously in the standard output until the user hits

control-c to stop the program.

294049. This program compiles and the word "hi' appears in the standard output, once

294050. Analyze the following code:

<BR>

class WhatHappens implements Runnable {

<BR>

public static void main(String[] args) {

<BR>

Thread t = new Thread(this);

<BR>

t.start();

<BR>

}

<BR>

public void run() {

<BR>

76

System.out.println("hi");

<BR>

}

<BR>

} ?

294050. This program does not compile (***)

294050. This program compiles but nothing appears in the standard output

294050. This program compiles and the word "hi' appears in the standard output, once

294050. This program compiles and the word "hi" appears continuously in the standard output until the user hits

control-c to stop the program

294051. What can you write at the comment:

<BR>

<BR>

<font face="Symbol">&#164;</font><font face="Symbol">&#164;</font>A in the code below so that this program

writes the word 'running' to the standard output?

<BR>

class RunTest implements Runnable {

<BR>

public static void main(String[] args) {

<BR>

&nbsp;&nbsp;&nbsp;RunTest rt = new RunTest();

<BR>

&nbsp;&nbsp;&nbsp;Thread t =new Thread(rt);

<BR>

&nbsp;&nbsp;&nbsp;<font face="Symbol">&#164;</font><font face="Symbol">&#164;</font>A

<BR>

&nbsp;&nbsp;&nbsp;}

<BR>

public void run() {

<BR>

&nbsp;&nbsp;&nbsp;System.out.println("running");

<BR>

&nbsp;&nbsp;&nbsp;}

<BR>

void go() {

<BR>

&nbsp;&nbsp;&nbsp;start(1);

<BR>

&nbsp;&nbsp;&nbsp;}

<BR>

void start(int i) {

<BR>

&nbsp;&nbsp;&nbsp;}

<BR>

} ?

294051. System.out.println("running"); (***)

294051. rt.start();

77

294051. rt.start(1);

294051. rt.go();

294052. What must be true for the RuriHandler class so that instances of RunHandler can be used as written in the

code below:

<BR>

<BR>

class Test {

<BR>

public static void main(String[] args) {

<BR>

Thread t = new Thread(new RunHandlerQ);

<BR>

t.start();

<BR>

}

<BR>

} ?

294052. RunHandler must implement the java.lang.Runnable interface. (***)

294052. RunHandler must extend the Thread class.

294052. RunHandler must provide an init() method.

294052. RunHandler must provide a run() method declared as public and returning void.

294053. Given the following class:

<BR>

<BR>

class Counter {

<BR>

public int startHere = 1;

<BR>

public int endHere = 100;

<BR>

public static void main(String[] args) {

<BR>

new Counter().go();

<BR>

}

<BR>

<BR>

void go() {

<BR>

<font face="Symbol">&#164;</font><font face="Symbol">&#164;</font>A

<BR>

Thread t = new Thread(a);

<BR>

78

t.start();

<BR>

}

<BR>

}

<BR>

<BR>

What block of code can you replace at line <font face="Symbol">&#164;</font><font

face="Symbol">&#164;</font>A above so that this program will count from startHere to endHere?

<BR>

Select all valid answers. ?

294053. Runable a = new Runable(){

<BR>

public void run() {

<BR>

for (int i = startHere; i <font face="Symbol">&#60;</font>= endHere; i++) { System.out.println(i); }

<BR>

}

<BR>

} ;

294053. a implements Runnable {

<BR>

public void run() {

<BR>

for (int i = startHere; i <font face="Symbol">&#60;</font>= endHere; i++) { System.out.println(i); }

<BR>

}

<BR>

} ;

294053. Thread a = new Thread() {

<BR>

public void run() {

<BR>

for (int i = startHere; i <font face="Symbol">&#60;</font>= endHere; i++) { System.out.println(i);}

<BR>

}

<BR>

} ; (***)

294053. mmmm

294054. Given the following class:

<BR>

class Counter {

<BR>

public static void main(String[] args) {

<BR>

Thread t = new Thread(new CounterBehaviorQ); t.startQ;

<BR>

79

}

<BR>

}

<BR>

Which of the following is a valid definition of

<BR>

CounterBehavior that would make Counter's main()

<BR>

method count from ito 100, counting once per second? ?

294054. This class is an inner class to Counter:

<BR>

class CounterBehavior {

<BR>

for (int i = 1; i <font face="Symbol">&#60;</font>= 100; i++);

<BR>

try{

<BR>

System.out.println(i);

<BR>

Thread.sleep(1 000);

<BR>

} catch (InterruptedException x) { }

<BR>

}

<BR>

}

294054. This class is an inner class to Counter:

<BR>

class CounterBehavior implements Runnable {

<BR>

public void run() {

<BR>

for (int i= 1;i<font face="Symbol">&#60;</font>= 1000;i++);

<BR>

try{

<BR>

System.out.println(i);

<BR>

Thread.sleep(1 000);

<BR>

} catch (InterruptedException x) {}

<BR>

}

<BR>

}

<BR>

}

294054. This class is a top-level class:

<BR>

80

static class CounterBehavior implements Runnable { public void run() {

<BR>

try{

<BR>

for(int i=1;i<font face="Symbol">&#60;</font>= 100; i++) {

<BR>

System.out.println(i);

<BR>

Thread.sleep(1 000);

<BR>

}

<BR>

} catch (InterruptedException x) { }

<BR>

}

<BR>

} (***)

294054. bbbbbb

294055. What statements are true concerning the method notify() that is used in conjunction with wait? ?

294055. if there is more than one thread waiting on a condition, only the thread that has been waiting the longest is

notified

294055. if there is more than one thread waiting on a condition, there is no way to predict which thread will be

notifed (***)

294055. notify() is defined in the Thread class

294055. it is not strictly necessary to own the lock for the object you invoke notify() for

294056. Given the following class:

<BR>

<BR>

class Counter {

<BR>

public int startHere = 1;

<BR>

public int endHere = 100;

<BR>

public static void main(String[] args) {

<BR>

new Counter().go();

<BR>

}

<BR>

void go() {

<BR>

<font face="Symbol">&#164;</font><font face="Symbol">&#164;</font>A

<BR>

Thread t = new Thread(a);

<BR>

81

t.start();

<BR>

}

<BR>

}

<BR>

What block of code can you replace at line A above so that this program will count from startHere to endHere? Select

all valid answers. ?

294056. Runnable a = new Runnable();

<BR>

public void run() {

<BR>

for (int i = startHere; i <font face="Symbol">&#60;</font>= endHere; i++) { System.out.println(i);

<BR>

}

<BR>

}

294056. a implements

<BR>

<BR>

Runnable {

<BR>

public void run() {

<BR>

for (int i = startHere; i <font face="Symbol">&#60;</font>= endHere; i++) { System.out.println(i);

<BR>

}

<BR>

}

294056. Thread a = new Thread() {

<BR>

public void run() {

<BR>

for (int i = startHere; i <font face="Symbol">&#60;</font>= endHere; i++) { System.out.println(i);

<BR>

}

<BR>

} (***)

294056. ghj

294057. What must be true for the RuriHandler class so that instances of RunHandler can be used as written in the

code below:

<BR>

class Test {

<BR>

public static void main(String[] args) {

<BR>

82

Thread t = new Thread(new RunHandler());

<BR>

t.start();

<BR>

}

<BR>

} ?

294057. RunHandler must implement the java.lang.Runnable interface. (***)

294057. RunHandler must extend the Thread class.

294057. RunHandler must provide an init() method.

294057. RunHandler must provide a run() method declared as public and returning void.

294058. What statements are true concerning the method notify() that is used in conjunction with wait()? ?

294058. if there is more than one thread waiting on a condition, only the thread that has been waiting the longest is

notified

294058. if there is more than one thread waiting on a condition. there is no way to predict which thread will be

notifed (***)

294058. it is not strictly necessary to own the lock for the object you invoke notify() for

294058. notify() is defined in the Thread class

294059. Analyze the following code:

<BR>

class WhatHappens implements Runnable {

<BR>

public static void main(String[] args) {

<BR>

Thread t = new Thread(this);

<BR>

t.start();

<BR>

}

<BR>

public void run() {

<BR>

System.out.println("hi");

<BR>

}

<BR>

} ?

294059. This program does not compile (***)

294059. This program compiles but nothing appears in the standard output

294059. This program compiles and the word "hi" appears continuously in the standard output until the user hits

control-c to stop the program.

294059. This program compiles and the word "hi' appears in the standard output, once

294060. Given the following class:

<BR>

class Counter {

<BR>

83

public static void main(String[] args) {

<BR>

Thread t = new Thread(new CounterBehavior());

<BR>

t.start();

<BR>

}

<BR>

}

<BR>

Which of the following is a valid definition of CounterBehavior that would make Counter's main() method count

from 1 to 100, counting once per second? ?

294060. This class is an inner class to Counter:

<BR>

class CounterBehavior {

<BR>

for (int i = 1: i <font face="Symbol">&#60;</font>= 100: i++):

<BR>

try{

<BR>

System.out.println(i);

<BR>

Thread.sleep(1 000);

<BR>

} catch (InterruptedException x) { }

<BR>

}

<BR>

}

294060. This class is an inner class to Counter:

<BR>

class CounterBehavior implements Runnable {

<BR>

public void run() {

<BR>

for (int i = 1; i <font face="Symbol">&#60;</font>= 100; i++); try{

<BR>

System.out.println(i);

<BR>

Thread.sleep(1 000);

<BR>

} catch (InterruptedException x) {}

<BR>

}

<BR>

}

<BR>

}

84

294060. This class is a top-level class:

<BR>

static class CounterBehavior implements Runnable {

<BR>

public void run() {

<BR>

try{

<BR>

for(int i=1;i<font face="Symbol">&#60;</font>= 100; i++) {

<BR>

System.out.println(i);

<BR>

Thread.sleep(1 000);

<BR>

}

<BR>

} catch (InterruptedException x) { }

<BR>

}

<BR>

} (***)

294060. jklkklkl

294061. Analyze the following code:

<BR>

<BR>

class Test extends Thread {

<BR>

public static void main(String[] args) {

<BR>

Thread t = new Thread(this);

<BR>

t.start();

<BR>

}

<BR>

<BR>

public void run() {

<BR>

System.out.println("test");

<BR>

}

<BR>

} ?

294061. The program does not compile because this cannot be referenced in a static method.

294061. The program compiles fine, but it does not print anything because t does not invoke the run() method. (***)

294061. The program compiles and runs fine and displays test on the console.

85

294061. None of the other answers

294062. When you run the following program, what will happen?

<BR>

<BR>

class Test extends Thread {

<BR>

public static void main(String[] args) {

<BR>

Test t = new Test();

<BR>

t.start();

<BR>

t.start();

<BR>

}

<BR>

<BR>

public void run() {

<BR>

System.out.println("test");

<BR>

}

<BR>

} ?

294062. Nothing is displayed.

294062. The program displays test twice. (***)

294062. The program has a runtime error because the thread t was started twice.

294062. The program displays test once.

294063. Analyze the following code:

<BR>

<BR>

class Test implements Runnable {

<BR>

public static void main(String[] args) {

<BR>

Test t = new Test();

<BR>

}

<BR>

<BR>

public Test() {

<BR>

86

Thread t = new Thread(this);

<BR>

t.start();

<BR>

}

<BR>

<BR>

public void run() {

<BR>

System.out.println("test");

<BR>

}

<BR>

} ?

294063. The program has a compilation error because t is defined in both the main() method and the constructor

Test().

294063. The program compiles fine, but it does not run because you cannot use the keyword this in the constructor.

(***)

294063. The program compiles and runs and displays test.

294063. The program compiles and runs and displays nothing.

294064. Given the following code, which set of code can be used to replace the comment so that the program

displays time to the console every second?

<BR>

<BR>

import java.applet.*;

<BR>

import java.util.*;

<BR>

<BR>

class Test extends Applet implements Runnable {

<BR>

public void init() {

<BR>

Thread t = new Thread(this);

<BR>

t.start();

<BR>

}

<BR>

<BR>

public void run() {

<BR>

for(; ;) {

<BR>

87

<font face="Symbol">&#164;</font><font face="Symbol">&#164;</font>display time every second

<BR>

System.out.println(new Date().toString());

<BR>

}

<BR>

}

<BR>

} ?

294064. try { sleep(1000); }

<BR>

catch(InterruptedException e) { }

294064. try { t.sleep(1000); }

<BR>

catch(InterruptedException e) { }

294064. try { Thread.sleep(1000); }

<BR>

catch(InterruptedException e) { } (***)

294064. try { Thread.sleep(1000); }

<BR>

catch(RuntimeException e) { }

294065. Why does the following class have a syntax error?

<BR>

<BR>

import java.applet.*;

<BR>

<BR>

class Test extends Applet implements Runnable {

<BR>

public void init() throws InterruptedException {

<BR>

Thread t = new Thread(this);

<BR>

t.sleep(1000);

<BR>

}

<BR>

<BR>

public synchronized void run() {

<BR>

}

<BR>

} ?

294065. The sleep() method is not invoked correctly; it should be invoked as Thread.sleep(1000).

294065. You cannot put the keyword synchronized in the run() method.

88

294065. The sleep() method should be put in the try-catch block. This is the only reason for the compilation failure.

(***)

294065. The init() method is defined in the Applet class, and it is overridden incorrectly because it cannot claim

exceptions in the subclass.

294066. Which of the following statements is correct to create a thread group and a new thread in the group? ?

294066. ThreadGroup tg = new ThreadGroup();

<BR>

Thread t1 = new Thread(tg, new Thread());

294066. ThreadGroup tg = new ThreadGroup();

<BR>

Thread t1 = new Thread(tg, new Thread(" "));

294066. ThreadGroup tg = new ThreadGroup(" ");

<BR>

Thread t1 = new Thread(tg, new Runnable()); (***)

294066. ThreadGroup tg = new ThreadGroup(" ");

<BR>

Thread t1 = new Thread(tg, new Thread());

294067. Given the following,

<BR>

<BR>

1. class MyThread extends Thread {

<BR>

2.

<BR>

3. public static void main(String [] args) {

<BR>

4. MyThread t = new MyThread();

<BR>

5. t.run();

<BR>

6. }

<BR>

7.

<BR>

8. public void run() {

<BR>

9. for(int i=1;i<font face="Symbol">&#60;</font>3;++i) {

<BR>

10. System.out.print(i + "..");

<BR>

11. }

<BR>

12. }

<BR>

13. }

<BR>

89

<BR>

what is the result? ?

294067. 1..2.. (***)

294067. This code will not compile due to line 5.

294067. This code will not compile due to line 4.

294067. An exception is thrown at runtime.

294068. The following block of code creates a Thread using a Runnable target:

<BR>

Runnable target = new MyRunnable();

<BR>

Thread myThread = new Thread(target);

<BR>

Which of the following classes can be used to create the target, so that the preceding code

<BR>

compiles correctly? ?

294068. public class MyRunnable extends Runnable{public void run(){}}

294068. public class MyRunnable extends Object{public void run(){}}

294068. public class MyRunnable implements Runnable{void run(){}}

294068. public class MyRunnable implements Runnable{public void run(){}} (***)

294069. Given the following,

<BR>

1. class MyThread extends Thread {

<BR>

2.

<BR>

3. public static void main(String [] args) {

<BR>

4. MyThread t = new MyThread();

<BR>

5. Thread x = new Thread(t);

<BR>

6. x.start();

<BR>

7. }

<BR>

8.

<BR>

9. public void run() {

<BR>

10. for(int i=0;i<font face="Symbol">&#60;</font>3;++i) {

<BR>

11. System.out.print(i + "..");

<BR>

12. }

<BR>

90

13. }

<BR>

14. }

<BR>

what is the result of this code? ?

294069. Compilation fails.

294069. 1..2..3..

294069. 0..1..2.. (***)

294069. 0..1..2..3..

294070. Given the following,

<BR>

class MyThread extends Thread {

<BR>

MyThread() {

<BR>

System.out.print(" MyThread");

<BR>

}

<BR>

public void run() {

<BR>

System.out.print(" bar");

<BR>

}

<BR>

public void run(String s) {

<BR>

System.out.println(" baz");

<BR>

}

<BR>

}

<BR>

public class TestThreads {

<BR>

public static void main (String [] args) {

<BR>

Thread t = new MyThread() {

<BR>

public void run() {

<BR>

System.out.println(" foo");

<BR>

}

<BR>

};

<BR>

91

t.start();

<BR>

}

<BR>

}

<BR>

<BR>

what is the result? ?

294070. foo

294070. MyThread foo (***)

294070. foo bar

294070. MyThread bar

294071. Given the following,

<BR>

public class SyncTest {

<BR>

public static void main (String [] args) {

<BR>

Thread t = new Thread() {

<BR>

Foo f = new Foo();

<BR>

public void run() {

<BR>

f.increase(20);

<BR>

}

<BR>

};

<BR>

t.start();

<BR>

}

<BR>

}

<BR>

class Foo {

<BR>

private int data = 23;

<BR>

public void increase(int amt) {

<BR>

int x = data;

<BR>

data = x + amt;

<BR>

92

}

<BR>

}

<BR>

and assuming that data must be protected from corruption, what—if anything—can you add

<BR>

to the preceding code to ensure the integrity of data? ?

294071. The existing code will not compile.

294071. The existing code will cause a runtime exception.

294071. Put in a wait() call prior to invoking the increase() method.

294071. Synchronize the increase() method (***)

294072. Given the following,

<BR>

1. public class Test {

<BR>

2. public static void main (String [] args) {

<BR>

3. final Foo f = new Foo();

<BR>

4. Thread t = new Thread(new Runnable() {

<BR>

5. public void run() {

<BR>

6. f.doStuff();

<BR>

7. }

<BR>

8. });

<BR>

9. Thread g = new Thread() {

<BR>

10. public void run() {

<BR>

11. f.doStuff();

<BR>

12. }

<BR>

13. };

<BR>

14. t.start();

<BR>

15. g.start();

<BR>

16. }

<BR>

17. }

<BR>

93

1. class Foo {

<BR>

2. int x = 5;

<BR>

3. public void doStuff() {

<BR>

4. if (x <font face="Symbol">&#60;</font> 10) {

<BR>

5. <font face="Symbol">&#164;</font><font face="Symbol">&#164;</font> nothing to do

<BR>

6. try {

<BR>

7. wait();

<BR>

8. } catch(InterruptedException ex) { }

<BR>

9. } else {

<BR>

10. System.out.println("x is " + x++);

<BR>

11. if (x <font face="Symbol">&#62;</font>= 10) {

<BR>

12. notify();

<BR>

13. }

<BR>

14. }

<BR>

15. }

<BR>

16. }

<BR>

<BR>

what is the result? ?

294072. The code will not compile because of an error on line 12 of class Foo.

294072. The code will not compile because of an error on line 7 of class Foo.

294072. The code will not compile because of some other error in class Test.

294072. An exception occurs at runtime. (***)

294073. How can a class that is run as a thread be defined? ?

294073. By subclassing the Thread class. (***)

294073. By implementing the Throwable interface.

294073. By implementing the Runnable interface.

294073. By implementing the Multithread interface.

294074. Which of the following lines of output are displayed by the following program?

<BR>

94

14. class Question {

<BR>

15. public static void main(String args[]) {

<BR>

16. MyThread t = new MyThread();

<BR>

17. t.displayOutput("t has been created.");

<BR>

18. t.start();

<BR>

19. }

<BR>

20. }

<BR>

21. class MyThread extends Thread {

<BR>

22. public void displayOutput(String s) {

<BR>

23. System.out.println(s);

<BR>

24. }

<BR>

25. public void run() {

<BR>

26. displayOutput("t is running.");

<BR>

27. }

<BR>

}8 ?

294074. t has been created.

294074. t is running. (***)

294074. The program will display different output depending on whether the

<BR>

underlying operating system supports preemptive scheduling or time

<BR>

slicing.

294074. None of the other answers. The program does not compile.

294075. Which of the following are true about the following program?\

<BR>

29. class Question {

<BR>

30. public static void main(String args[]) {

<BR>

31. MyThread t1 = new MyThread("t1");

<BR>

32. MyThread t2 = new MyThread("t2");

<BR>

95

33. t1.start();

<BR>

34. t2.start();

<BR>

35. }

<BR>

36. }

<BR>

37. class MyThread extends Thread {

<BR>

38. public void displayOutput(String s) {

<BR>

39. System.out.println(s);

<BR>

40. }

<BR>

41. public void run() {

<BR>

42. for(int i=0;i<font face="Symbol">&#60;</font>10;++i) {

<BR>

43. try {

<BR>

44. sleep((long)(3000*Math.random()));

<BR>

45. }catch(Exception ex) {

<BR>

46. }

<BR>

47. displayOutput(getName());

<BR>

48. }

<BR>

49. }

<BR>

50. public MyThread(String s) {

<BR>

51. super(s);

<BR>

52. }

<BR>

} ?

294075. The program always displays t1 10 times, followed by t2 10 times.

294075. The program always displays t1 followed by t2.

294075. The output sequence will vary from computer to computer. (***)

294075. The program displays no output.

294076. You have created a TimeOut class as an extension of thread, the purpose of which is to print a "Time's Up"

message if the thread is not interrupted within 10 seconds of being started.

<BR>

96

<BR>

Here is the run method that you have coded:

<BR>

<BR>

1. public void run(){

<BR>

2. System.out.println("Start!");

<BR>

3. try { Thread.sleep(10000 );

<BR>

4. System.out.println("Time's Up!");

<BR>

5. }catch(InterruptedException e){

<BR>

6. System.out.println("Interrupted!");

<BR>

7. }

<BR>

8. }

<BR>

<BR>

Given that a program creates and starts a TimeOut object, which of the following statements is true? ?

294076. Exactly 10 seconds after the start method is called, "Time's Up!" will be printed.

294076. If "Time's Up!" is printed, you can be sure that at least 10 seconds have elapsed since "Start!" was printed.

(***)

294076. Exactly 10 seconds after "Start!" is printed, "Time's Up!" will be printed.

294076. The delay between "Start!" being printed and "Time's Up!" will be 10 seconds plus or minus one tick of the

system clock.

294077. You have written an application that can accept orders from multiple sources, each one of which runs in a

separate thread. One object in the application is allowed to record orders in a file. This object uses the recordOrder

method, which is synchronized to prevent conflict between threads.

<BR>

<BR>

While Thread A is executing recordOrder, Threads B, C, and D, in that order, attempt to execute the recordOrder

method. What happens when Thread A exits the synchronized method? ?

294077. Thread B, as the first waiting thread, is allowed to execute the method.

294077. One of the waiting threads will be allowed to execute the method, but you can't be sure which one it will be.

(***)

294077. Thread D, as the last waiting thread, is allowed to execute the method.

294077. Either A or D, but never C, will be allowed to execute.

294078. Here is part of the code for a class that implements the Runnable interface:

<BR>

97

<BR>

1. public class Whiffler extends Object

<BR>

implements Runnable {

<BR>

2. Thread myT ;

<BR>

3. public void start(){

<BR>

4. myT = new Thread( this );

<BR>

5. }

<BR>

6. public void run(){

<BR>

7. while( true ){

<BR>

8. doStuff();

<BR>

9. }

<BR>

10. System.out.println("Exiting run");

<BR>

11. }

<BR>

12. <font face="Symbol">&#164;</font><font face="Symbol">&#164;</font> more class code follows....

<BR>

<BR>

Assume that the rest of the class defines doStuff, and so on, and that the class compiles without error. Also assume

that a Java application creates a Whiffler object and calls the Whiffler start method, that no other direct calls to

Whiffler methods are made, and that the thread in this object is the only one the application creates. Which of the

following are correct statements? [Check all correct answers.] ?

294078. The doStuff method will be called repeatedly.

294078. The doStuff method will execute at least one time.

294078. The doStuff method will never be executed. (***)

294078. The statement in line 10 will never be reached.

294079. You have written a class extending Thread that does time-consuming computations. In the first use of this

class in an application, the system locked up for extended periods of time. Obviously, you need to provide a chance

for other threads to run. The following is the run method that needs to be modified:

<BR>

<BR>

1. public void run(){

<BR>

2. boolean runFlg = true ;

<BR>

98

3. while( runFlg ){

<BR>

4. runFlg = doStuff();

<BR>

5.

<BR>

6. }

<BR>

7. }

<BR>

<BR>

Which statements could be inserted at line 5 to allow other threads a chance to run? [Check all correct answers.] ?

294079. yield(); (***)

294079. wait( 100 );

294079. try{ sleep(100); } catch(InterruptedException e){ }

294079. suspend( 100 );

294080. You are creating a class that extends Object and implements Runnable. You have already written a run

method for this class. You need a way to create a thread and have it execute the run method. Which of the following

start methods should you use? ?

294080. public void start(){

<BR>

new Thread( this ).start();

<BR>

} (***)

294080. public void start(){

<BR>

Thread myT = new Thread();

<BR>

myT.start();

<BR>

}

294080. public void start(){

<BR>

Thread myT = new Thread(this);

<BR>

myT.run();

<BR>

}

294080. xxxx

294081. What will be the result of attempting to compile and run the following program?

<BR>

<BR>

public class MyClass extends Thread {

<BR>

99

public MyClass(String s) { msg = s; }

<BR>

String msg;

<BR>

public void run() {

<BR>

System.out.println(msg);

<BR>

}

<BR>

<BR>

public static void main(String[] args) {

<BR>

new MyClass("Hello");

<BR>

new MyClass("World");

<BR>

}

<BR>

}

<BR>

<BR>

Select the one correct answer ?

294081. The program will fail to compile.

294081. The program will compile without errors and will print Hello and World when run, but the order is

unpredictable.

294081. The program will compile without errors and will simply terminate without any output when run. (***)

294081. The program will compile without errors and will print Hello and World, in that order, every time the

program is run.

294082. Given the following program, which statements are guaranteed to be true?

<BR>

<BR>

public class ThreadedPrint {

<BR>

static Thread makeThread(final String id, boolean daemon) {

<BR>

Thread t = new Thread(id) {

<BR>

public void run() {

<BR>

System.out.println(id);

<BR>

}

<BR>

100

};

<BR>

t.setDaemon(daemon);

<BR>

t.start();

<BR>

return t;

<BR>

}

<BR>

<BR>

public static void main(String[] args) {

<BR>

Thread a = makeThread("A", false);

<BR>

Thread b = makeThread("B", true);

<BR>

System.out.print("End\n");

<BR>

}

<BR>

}

<BR>

<BR>

Select the two correct answers. ?

294082. The letter A is always printed. (***)

294082. The letter B is never printed after End.

294082. The letter B is always printed.

294082. The letter A is never printed after End.

294083. Given the following program, which statement is true?

<BR>

<BR>

public class MyClass extends Thread {

<BR>

static Object lock1 = new Object();

<BR>

static Object lock2 = new Object();

<BR>

<BR>

static volatile int i1, i2, j1, j2, k1, k2;

<BR>

<BR>

101

public void run() { while (true) { doit(); check(); } }

<BR>

<BR>

void doit() {

<BR>

synchronized(lock1) { i1++; }

<BR>

j1++;

<BR>

synchronized(lock2) { k1++; k2++; }

<BR>

j2++;

<BR>

synchronized(lock1) { i2++; }

<BR>

}

<BR>

<BR>

void check() {

<BR>

if (i1 != i2) System.out.println("i");

<BR>

if (j1 != j2) System.out.println("j");

<BR>

if (k1 != k2) System.out.println("k");

<BR>

}

<BR>

<BR>

public static void main(String[] args) {

<BR>

new MyClass().start();

<BR>

new MyClass().start();

<BR>

}

<BR>

}

<BR>

<BR>

Select the one correct answer ?

294083. The program will fail to compile.

294083. One can be certain that the letters i and k will never be printed during execution.

294083. One can be certain that the letter k will never be printed during execution

294083. One cannot be certain whether any of the letters i, j, and k will be printed during execution. (***)

102

294084. Which statements are true about the following code?

<BR>

<BR>

public class Joining {

<BR>

static Thread createThread(final int i, final Thread t1) {

<BR>

Thread t2 = new Thread() {

<BR>

public void run() {

<BR>

System.out.println(i+1);

<BR>

try {

<BR>

t1.join();

<BR>

} catch (InterruptedException e) {

<BR>

}

<BR>

System.out.println(i+2);

<BR>

}

<BR>

};

<BR>

System.out.println(i+3);

<BR>

t2.start();

<BR>

System.out.println(i+4);

<BR>

return t2;

<BR>

}

<BR>

<BR>

public static void main(String[] args) {

<BR>

createThread(10, createThread(20, Thread.currentThread()));

<BR>

}

<BR>

}

<BR>

103

<BR>

Select the two correct answers. ?

294084. The first number printed is 13.

294084. The last number printed is 12. (***)

294084. The number 11 is printed before the number 23.

294084. The number 24 is printed before the number 21.

294085. Show the output of running the class Test in the following code lines:

<BR>

<BR>

interface A {

<BR>

}

<BR>

<BR>

class C {

<BR>

}

<BR>

<BR>

class B extends D implements A {

<BR>

}

<BR>

<BR>

public class Test extends Thread {

<BR>

public static void main(String[] args) {

<BR>

B b = new B();

<BR>

if (b instanceof A)

<BR>

System.out.println("b is an instance of A");

<BR>

if (b instanceof C)

<BR>

System.out.println("b is an instance of C");

<BR>

}

<BR>

}

<BR>

104

<BR>

class D extends C {

<BR>

} ?

294085. b is an instance of A followed by b is an instance of C. (***)

294085. Nothing.

294085. b is an instance of C.

294085. b is an instance of A.

294086. What will happen if you compile<font face="Symbol">&#164;</font>run this code?

<BR>

<BR>

<BR>

1: public class Q1 extends Thread

<BR>

2: {

<BR>

3: public void run()

<BR>

4: {

<BR>

5: System.out.println("Before start method");

<BR>

6: this.stop();

<BR>

7: System.out.println("After stop method");

<BR>

8: }

<BR>

9:

<BR>

10: public static void main(String[] args)

<BR>

11: {

<BR>

12: Q1 a = new Q1();

<BR>

13: a.start();

<BR>

14: }

<BR>

15: } ?

294086. Compilation error at line 7

294086. Runtime exception at line 7

294086. Prints "Before start method" only (***)

294086. Prints "Before start method" and "After stop method"

105

294087. Choose the item that is not part of Java: ?

294087. Garbage collection

294087. Interfaces

294087. True Pointers (***)

294087. Multi-threading

294088. What will happen when you attempt to compile and run the following code?

<BR>

public class Bground extends Thread{

<BR>

<BR>

public static void main(String argv[]){

<BR>

&nbsp;&nbsp;&nbsp; Bground b = new Bground();

<BR>

&nbsp;&nbsp;&nbsp;b.run();

<BR>

}

<BR>

public void start(){

<BR>

&nbsp;&nbsp;&nbsp;for (int i = 0; i <font face="Symbol">&#60;</font>10; i++){

<BR>

&nbsp;&nbsp;&nbsp;System.out.println("Value of i = " + i);

<BR>

}

<BR>

}

<BR>

<BR>

} ?

294088. A compile time error indicating that no run method is defined for the Thread class

294088. A run time error indicating that no run method is defined for the Thread class

294088. Clean compile but no output at runtime (***)

294088. Clean compile and at run time the values 0 to 9 are printed out

294089. What can cause a thread to stop executing? ?

294089. The program exits via a call to System.exit(0);

<BR>

Another thread is given a higher priority.

<BR>

A call to the thread's stop method. (***)

294089. A call to the halt method of the Thread class

<BR>

Another thread is given a higher priority.

<BR>

106

A call to the thread's stop method.

294089. The program exits via a call to System.exit(0);

<BR>

Another thread is given a higher priority.

<BR>

A call to the halt method of the Thread class

294089. The program exits via a call to System.exit(0);

<BR>

A call to the halt method of the Thread class

<BR>

A call to the thread's stop method.

294090. Under what circumstances might you use the yield method of the Thread class ?

294090. To call from the currently running thread to allow another thread of the same priority to run (***)

294090. To call on a waiting thread to allow it to run

294090. To call from the currently running thread with a parameter designating which thread should be allowed to

run

294090. To allow a thread of higher priority to run

294091. Which of the following statements about threading are NOT true ?

294091. You can only obtain a mutually exclusive lock on methods in a class that extends Thread or implements

runnable (***)

294091. You can obtain a mutually exclusive lock on any object

294091. Thread scheduling algorithms are platform dependent

294091. A thread can obtain a mutually exclusive lock on a method declared with the keyword synchronized

294092. Which of the following are NOT methods of the Thread class? ?

294092. yield()

294092. sleep(long msec)

294092. stop()

294092. go() (***)

294093. Which of the following best describes the use of the synhronized keyword? ?

294093. Allows two process to run in paralell but to communicate with each other

294093. Ensures only one thread at a time may access a class or object (***)

294093. Ensures that two or more Threads will start and end at the same time

294093. Ensures that two or more processes will start and end at the same time

294094. What will happen when you attempt to compile and run the following code

<BR>

public class Borley extends Thread{

<BR>

public static void main(String argv[]){

<BR>

&nbsp;&nbsp;&nbsp;Borley b = new Borley();

<BR>

&nbsp;&nbsp;&nbsp;b.start();

<BR>

107

&nbsp;&nbsp;&nbsp;}

<BR>

public void run(){&nbsp;&nbsp;&nbsp;

<BR>

&nbsp;&nbsp;&nbsp;System.out.println("Running");

<BR>

&nbsp;&nbsp;&nbsp;}

<BR>

} ?

294094. Compilation and run but no output

294094. Compilation and run with the output "Running" (***)

294094. Compile time error with complaint of no access to Thread package

294094. Compile time error with complaint of no Thread target

294095. Given a reference called

<BR>

t

<BR>

to to a class which extends Thread, which of the following will cause it to give up cycles to allow another thread to

execute. ?

294095. t.yield();

294095. yield() (***)

294095. yield(t);

294095. yield(100) <font face="Symbol">&#164;</font><font face="Symbol">&#164;</font>Or some other

suitable amount in milliseconds

294096. Given that a static method doIt() in a class Work represents work to be done, what block of code will NOT

succeed in starting a new thread that will do the work? <BR><BR>CODE BLOCK A: <BR>Runnable r = new

Runnable() { <BR>public void run() { <BR>Work.doIt(); <BR>} <BR>}; <BR><BR>Thread t = new Thread(r);

<BR>t.start(); <BR><BR>CODE BLOCK B: <BR>Thread t = new Thread() { <BR>public void start() {

<BR>Work.doIt(); <BR>} <BR>} <BR>t.start(); <BR><BR>CODE BLOCK C: <BR><BR>Runnable r = new

Runnable() { <BR>public void run() { <BR>Work.doIt(); <BR>} <BR>}; <BR><BR>r.start(); <BR><BR>CODE

BLOCK D: <BR><BR>Thread t = new Thread(new Work()); <BR><BR>t.start(); ?

294096. Code block A. (***)

294096. Code block B.

294096. Code block C.

294096. Code block D.

294097. Class Teacher and Student are subclass of class Person.

<BR>

<BR>

Person p;

<BR>

Teacher t;

<BR>

Student s;

<BR>

108

p,t and s are all non-null.

<BR>

if(t instanceof Person){s=(Student)t;}

<BR>

<BR>

What is the result of this sentence? ?

294097. It will construct a Student object.

294097. The expression is legal.

294097. It is illegal at compilation. (***)

294097. It is legal at compilation but possible illegal at runtime.

294098. What will happen when you attempt to compile and run this code?

<BR>

<BR>

import java.awt event.*;

<BR>

import java.awt.*;

<BR>

public class Test extends Frame implements WindowListener{

<BR>

public void WindowClosing(WindowEvent e){

<BR>

System.exit(0);

<BR>

}

<BR>

public void Test(){

<BR>

setSize(300,300);

<BR>

setVisible(true);

<BR>

}

<BR>

<BR>

} ?

294098. Error at compile time. (***)

294098. Visible Frame created that that can be closed.

294098. Compilation but no output at run time.

294098. Error at compile time because of comment before import statements.

294099. The following code is entire contents of a file called Example.java, causes precisely one error during

compilation:

<BR>

<BR>

109

1) class SubClass extends BaseClass{

<BR>

2) }

<BR>

3) class BaseClass (){

<BR>

4) String str;

<BR>

5) public BaseClass(){

<BR>

6) System.out.println("ok");}

<BR>

7) public BaseClass(String s){

<BR>

8) str=s;}}

<BR>

9) public class Example{

<BR>

10)Public void method(){

<BR>

11)subClass s=new SubClass("hello");

<BR>

12)BaseClass b=new BaseClass("world");

<BR>

13)}

<BR>

14)}

<BR>

<BR>

Which line would be cause the error? ?

294099. 11 (***)

294099. 12

294099. 9

294099. 10

294100. in the Test.Java source file, which are correct class definitions? ?

294100. public class test{

<BR>

public int x=0;

<BR>

public test(int x)

<BR>

{

<BR>

this.x=x;

<BR>

}

<BR>

110

<BR>

}

294100. public class Test{

<BR>

public int x=0;

<BR>

public Test(int x){

<BR>

this.x=x;

<BR>

}

<BR>

} (***)

294100. public class Test extends T1,T2{

<BR>

public int x=0;

<BR>

public Test(int x){

<BR>

this.x=x;

<BR>

}

<BR>

}

294100. protected class Test extends T2{

<BR>

public int x=0;

<BR>

public test(int x){

<BR>

this.x=x;

<BR>

}

<BR>

}

294101. Given the following code:

<BR>

<BR>

1) class Example{

<BR>

2) String str;

<BR>

3) public Example(){

<BR>

4) str="example";

<BR>

111

5) }

<BR>

6) public Example(String s){

<BR>

7) str=s;

<BR>

8) }

<BR>

9) }

<BR>

<BR>

10)class Demo extends Example{

<BR>

<BR>

11)}

<BR>

<BR>

12)public class Test{

<BR>

<BR>

13)public void f(){

<BR>

<BR>

14)Example ex = new Example("Good");

<BR>

<BR>

15)Demo d=new Demo("Good");

<BR>

<BR>

16)}

<BR>

<BR>

Which line will cause an error? ?

294101. line 3

294101. line 6

294101. line 15 (***)

294101. line 14

294102. Imagine there are two exception classes called Exception1 and Exception2 that descend from the Exception

class, Given these two class definitions:

<BR>

112

<BR>

class First{

<BR>

<BR>

void test() throws Exceotuib1, Exceotuib2{ ...}

<BR>

}

<BR>

<BR>

class Second extends First{

<BR>

void test(){...}

<BR>

<BR>

Create a class called Third that extends Second and defines a test() method. What exceptions can Third's test()

method throw? ?

294102. Exception 1

294102. Exception 2

294102. no checked exceptions (***)

294102. any exceptions declared in the throws clause of the Third's test()method.

294103. What is the result of executing the following code:

<BR>

<BR>

class Test{

<BR>

<BR>

public static void main(String args[]){

<BR>

Test t=new Test();

<BR>

t.test(1.0,2L,3);

<BR>

<BR>

}

<BR>

<BR>

void test(double a,double b,short c){

<BR>

System.out.println("1");

<BR>

113

}

<BR>

<BR>

void test(float a,byte b,byte c){

<BR>

System.out.println("2");

<BR>

}

<BR>

<BR>

void test(double a, double b, double c){

<BR>

System.out.println("3");

<BR>

}

<BR>

<BR>

void test(int a,long b,int e){

<BR>

System.out.println("4");

<BR>

}

<BR>

<BR>

void test(long a, long b, long c){

<BR>

System.out.println("5");

<BR>

}

<BR>

<BR>

} ?

294103. 1

294103. 2

294103. 3 (***)

294103. 4

294104. Given the following interface definition, which definitions are valid?

<BR>

<BR>

interface I {

<BR>

114

void setValue(int val);

<BR>

int getValue();

<BR>

}

<BR>

<BR>

DEFINITION A:

<BR>

(a)--class A extends I {

<BR>

int value;

<BR>

<BR>

void setValue(int val) { value =val; }

<BR>

<BR>

int getValue() { return value; }

<BR>

<BR>

}

<BR>

<BR>

DEFINITION B:

<BR>

<BR>

(b)--interface B extends I {

<BR>

void increment();

<BR>

}

<BR>

<BR>

DEFINITION C:

<BR>

<BR>

(c)--abstract class C implements I {

<BR>

int getValue() { return 0; }

<BR>

115

<BR>

abstract void increment();

<BR>

<BR>

}

<BR>

<BR>

DEFINITION D:

<BR>

<BR>

(d)--interface D implements I {

<BR>

void increment();

<BR>

}

<BR>

<BR>

?

294104. Definition A. (***)

294104. Definition B.

294104. Definition C.

294104. Definition D.

294105. Which statements concerning the following code are true?

<BR>

<BR>

class A {

<BR>

public A() {}

<BR>

public A(int i) { this(); }

<BR>

}

<BR>

<BR>

class B extends A {

<BR>

public boolean B(String msg)

<BR>

{ return false; }

<BR>

116

}

<BR>

<BR>

class C extends B {

<BR>

private C() { super(); }

<BR>

public C(String msg) { this(); }

<BR>

public C(int i) {}

<BR>

} ?

294105. The constructor in A that takes an int as an argument will never be called as a result of constructing an object

of class B or C. (***)

294105. Objects of class B cannot be constructed.

294105. At most one of the constructors of each class is called as a result of constructing an object of class C.

294105. Class C has 2 constructors.

294106. Which statements, when inserted at the indicated position in the following code, will cause a runtime

exception when attempting to run the program?

<BR>

<BR>

class A {}

<BR>

class B extends A {}

<BR>

class C extends A {}

<BR>

public class Q3ae4 {

<BR>

<BR>

public static void main(String args[]) {

<BR>

A x = new A();

<BR>

B y = new B();

<BR>

C z = new C();

<BR>

<BR>

<font face="Symbol">&#164;</font><font face="Symbol">&#164;</font> insert statement here

<BR>

}

<BR>

} ?

117

294106. x = y;

294106. z = x;

294106. y = (B) x; (***)

294106. z = (C) y;

294107. Which statements can be inserted at the Indicated position in the following code to make the program write 1

on the standard output when run?

<BR>

<BR>

public class Q4a39 {

<BR>

int a = 1;

<BR>

int b = 1;

<BR>

int c = 1;

<BR>

<BR>

class Inner {

<BR>

int a = 2;

<BR>

int get() {

<BR>

int c = 3;

<BR>

<BR>

<font face="Symbol">&#164;</font><font face="Symbol">&#164;</font> insert statement here

<BR>

<BR>

return c;

<BR>

<BR>

}

<BR>

}

<BR>

<BR>

Q4a39() {

<BR>

Inner i = new Inner();

<BR>

118

System.out.println(i.get());

<BR>

}

<BR>

<BR>

public static void main(String args[]) {

<BR>

new Q4a39();

<BR>

}

<BR>

<BR>

} ?

294107. c = b; (***)

294107. c = this.a;

294107. c = this.b;

294107. c = a;

294108. Which line contains a constructor in this class definition?

<BR>

<BR>

public class Counter { <font face="Symbol">&#164;</font><font face="Symbol">&#164;</font> (1)

<BR>

int current, step;

<BR>

<BR>

public Counter(int startValue, int stepValue) { <font face="Symbol">&#164;</font><font

face="Symbol">&#164;</font> (2)

<BR>

set(startValue);

<BR>

setStepValue(stepValue);

<BR>

}

<BR>

<BR>

public int get() { return current; } <font face="Symbol">&#164;</font><font face="Symbol">&#164;</font> (3)

<BR>

<BR>

public void set(int value) { current = value; } <font face="Symbol">&#164;</font><font

face="Symbol">&#164;</font> (4)

<BR>

119

<BR>

public void setStepValue(int stepValue) { step = stepValue; } <font face="Symbol">&#164;</font><font

face="Symbol">&#164;</font> (5)

<BR>

} ?

294108. Code marked with (1) is a constructor.

294108. Code marked with (2) is a constructor. (***)

294108. Code marked with (3) is a constructor.

294108. Code marked with (4) is a constructor.

294109. Look at the following code <BR>import java.awt.*; <BR>public class visual extends java.applet.Applet{

<BR>static Button b = new Button("TEST"); <BR>public void init(){ <BR>add(b); <BR>} <BR>public static void

main(String args[]){ <BR>Frame f = new Frame("Visual"); <BR>f.setSize(300,300); <BR>f.add(b);

<BR>f.setVisible(true); <BR>} <BR>} <BR>What will happen if above code is run as a standalone application ?

294109. Displays an empty frame

294109. Displays a frame with a button covering the entire frame (***)

294109. Displays a frame with a button large enough to accomodate its label.

294109. compile error

294110. What is the output

<BR>

{

<BR>

Float f1 = new Float("4.4e99f");

<BR>

Float f2 = new Float("-4.4e99f");

<BR>

Double d1 = new Double("4.4e99");

<BR>

System.out.println(f1);

<BR>

System.out.println(f2);

<BR>

System.out.println(d1);

<BR>

} ?

294110. Runtime error

294110. Infinity

<BR>

-Infinity

<BR>

4.4E99 (***)

294110. Infinity

<BR>

-Infinity

<BR>

Infinity

120

294110. 4.4E99

<BR>

-4.4E99

<BR>

4.4E99

294111. Which checkbox will be selected in the following code ( Assume with main and added to a Frame)

<BR>

Frame myFrame = new Frame("Test");

<BR>

CheckboxGroup cbg = new CheckboxGroup();

<BR>

Checkbox cb1 = new Checkbox("First",true,cbg);

<BR>

Checkbox cb2 = new Checkbox("Scond",true,cbg);

<BR>

Checkbox cb3 = new Checkbox("THird",true,cbg);

<BR>

myFrame.add(cb1);

<BR>

myFrame.add(cb2);

<BR>

myFrame.add(cb3); ?

294111. cb1

294111. cb2,cb1

294111. cb3 (***)

294111. cb1,cb2,cb3

294112. Which checkbox will be selected in the following code ( Assume with main and added to a Frame)

<BR>

Frame myFrame = new Frame("Test");

<BR>

CheckboxGroup cbg = new CheckboxGroup();

<BR>

Checkbox cb1 = new Checkbox("First",true,cbg);

<BR>

Checkbox cb2 = new Checkbox("Scond",true,cbg);

<BR>

Checkbox cb3 = new Checkbox("THird",false,cbg);

<BR>

cbg.setSelectedCheckbox(cb3);

<BR>

myFrame.add(cb1);

<BR>

myFrame.add(cb2);

<BR>

myFrame.add(cb3); ?

294112. cb1

294112. cb2,cb1

121

294112. cb3 (***)

294112. cb1,cb2,cb3

294113. Examine the following code which includes an inner class:

<BR>

<BR>

public final class Test4 implements A {

<BR>

class Inner {

<BR>

void test() {

<BR>

if (Test4.this.flag); {

<BR>

sample();

<BR>

}

<BR>

}

<BR>

}

<BR>

private boolean flag = false;

<BR>

public void sample() {

<BR>

System.out.println("Sample");

<BR>

}

<BR>

public Test4() {

<BR>

(new Inner()).test();

<BR>

}

<BR>

public static void main(String args []) {

<BR>

new Test4();

<BR>

}

<BR>

}

<BR>

<BR>

What is the result: ?

294113. Prints out "Sample" (***)

122

294113. Program produces no output but terminates correctly.

294113. The program will not compile

294113. Program does not terminate.

294114. Examine the following class definition:

<BR>

<BR>

public class Test {

<BR>

public static void test() {

<BR>

print();

<BR>

}

<BR>

public static void print() {

<BR>

System.out.println("Test");

<BR>

}

<BR>

public void print() {

<BR>

System.out.println("Another Test");

<BR>

}

<BR>

}

<BR>

<BR>

What is the result of compiling this class: ?

294114. A successful compilation.

294114. A warning stating that the class has no main method.

294114. An error stating that the method test() will call one or other of the print() methods.

294114. An error stating that there is a duplicated metho (***)

294115. What is the effect of adding the sixth element to a vector created in the following manner:

<BR>

<BR>

new Vector(5, 10); ?

294115. An IndexOutOfBounds exception is raised.

294115. The vector grows in size to a capacity of 10 elements

294115. Nothing, the vector will have grown when the fifth element was added

294115. The vector grows in size to a capacity of 15 elements (***)

123

294116. Given the following classes defined in separate files:

<BR>

<BR>

class Vehicle {

<BR>

public void drive() {

<BR>

System.out.println("Vehicle: drive");

<BR>

}

<BR>

}

<BR>

<BR>

class Car extends Vehicle {

<BR>

public void drive() {

<BR>

System.out.println("Car: drive");

<BR>

}

<BR>

}

<BR>

<BR>

public class Test {

<BR>

public static void main (String args []) {

<BR>

Vehicle v;

<BR>

Car c;

<BR>

v = new Vehicle();

<BR>

c = new Car();

<BR>

v.drive();

<BR>

c.drive();

<BR>

v = c;

<BR>

v.drive();

<BR>

124

}

<BR>

}

<BR>

<BR>

What will be the effect of compiling and running this class Test? ?

294116. Generates a Compiler error on the statement v= c;

294116. Generates runtime error on the statement v= c;

294116. Prints out:

<BR>

Vehicle: drive

<BR>

Car: drive

<BR>

Vehicle: drive

294116. Prints out:

<BR>

Vehicle: drive

<BR>

Car: drive

<BR>

Car: drive (***)

294117. What will happen when you attempt to compile and run the following code

<BR>

class Base{

<BR>

protected int i = 99;

<BR>

}

<BR>

public class Ab{

<BR>

private int i=1;

<BR>

public static void main(String argv[]){

<BR>

Ab a = new Ab();

<BR>

a.hallow();

<BR>

}

<BR>

&nbsp;&nbsp;&nbsp;abstract void hallow(){

<BR>

&nbsp;&nbsp;&nbsp;System.out.println("Claines "+i);

<BR>

125

&nbsp;&nbsp;&nbsp;}

<BR>

} ?

294117. Compile time error (***)

294117. Compilation and output of Claines 99

294117. Compilation and not output at runtime

294117. Compilation and output of Claines 1

345627. The _______ interfaces is used to encapsulate SQL queries used for retrieving data from the database ?

345627. Callable

345627. Statement (***)

345627. Prepared

345627. Parameter

345628. _______ are small pieces of information that are deposited on the client by the server. ?

345628. Session

345628. Cookies (***)

345628. Directives

345628. Scriptlets

345629. If the service method&nbsp; is not overridden by the user in servlet class then the service method calls the

_________ ?

345629. Sub Class Service

345629. Super Class Service (***)

345629. Both

345629. None of the options given

345630. The standard syntax of the an HTTP protocol is: ?

345630. http://host[port]/path/resource_name[#section][?query_string]

345630. http://host[:port]/path/resource_name[#section][?query_string] (***)

345630. http://host[port]/path/resource_name[?section][#query_string]

345630. http://host[:port]/path/resource_name[?section][#query_string]

345631. A JSP directive is enclosed&nbsp; within the _______ markers. ?

345631. „&lt;%@‟ and „%&gt;‟ (***)

345631. „&lt;%‟ and „%&gt;‟

345631. „&lt;%‟ and „%@&gt;‟

345631. „%@ and %‟

345632. The _______ package implements the Tag interface ?

345632. javax.servlets.jsp

345632. javax.servlets.taginterface

345632. javax.servlet.jsp.tagtext (***)

345632. javax.servlets.jsp.tagtext

345633. _______ is the process of create a copy of an object suiable for paasing to another object. ?

345633. Reflection

345633. Cookies

345633. Sockets

126

345633. Serialization (***)

345634. The _______ component is used to locate resource over the network such as EJB components, database

driver and security credentials. ?

345634. JNDI (***)

345634. JMS

345634. JavaMail

345634. EJB

345635. A JDBC application does the follwing in what order of steps?<BR>&nbsp;&nbsp;&nbsp; 1) Connects to a

JDBC data source.<BR>&nbsp;&nbsp;&nbsp; 2) Parses the results of the query.<BR>&nbsp;&nbsp;&nbsp; 3)

Executes a query.<BR>&nbsp;&nbsp;&nbsp; 4) closes the connection after the database operation. ?

345635. 1-2-3-4

345635. 4-3-2-1

345635. 1-3-2-4 (***)

345635. 2-3-4-1

345636. Which of the follwing are not true about a JavaBean? ?

345636. A bean must be concrete.

345636. It must have a default constructor

345636. It must be serializable.

345636. A bean class must be abstract. (***)

345637. Net Pure Java Driver has the follwing implementation features. ?

345637. The size of this driver is smaller than all other types. (***)

345637. The size of this driver is greater than all other types.

345637. No configuration is required

345637. Configuration is required.

345638. Each JSP goes through two phases. Select them: ?

345638. Translation request time

345638. Executable time

345638. Translation time (***)

345638. Request time.

345639. The corret syntax of a taglib directive is: ?

345639. &lt;%@taglib uri= “tagLibraryURI” prefix= “tagPrefix”%&gt; (***)

345639. &lt;%@taglib =“tagURI” prefix=“tagPrefix”&gt;

345639. &lt;%@taglib uri=“tagURI” prefix=“tagPrefix”%&gt;

345639. &lt;%@tagLib =“TagURI” prefix tagPrefix&gt;

345640. _______ class is an extension of the ServletResponse class. ?

345640. HttpRespnse

345640. HttpServlet

345640. HttpServletResponse (***)

345640. HttpServletRequest.

345641. The JDBC classes are present in the ______ package. ?

345641. java.lang

127

345641. java.jdbc

345641. java.api

345641. java.sql (***)

345642. Conn = Driver Manager.getConnection(“jdbc:odbc:Employee”,“”,“”);<BR>What does the above statement

do? ?

345642. Gets a database connection with the Employee data source. (***)

345642. Gets connectioned to the employee database.

345642. Inidicates that jdbc is to be used in the application.

345642. Retrieves data from the employee table.

345643. The standard actions NOT used of JavaBean in JavaServer Page are: ?

345643. jsp:useBean

345643. jsp:ReuseBean (***)

345643. jsp:setProperty

345643. jsp:getProperty

345644. ________ class gives user an opportunity to save data to a database or file or to do any other cleanup actions.

?

345644. HttpSession

345644. HttpSessionBindingListener

345644. HttpSessionContext (***)

345644. HttpSessionBindingEvent.

345645. Which of the following attribute represents the relative URL to the JSP that will handle exceptions ?

345645. isErrorPage = “true\false”

345645. errorPage = “&lt;error_URL&gt;” (***)

345645. isErrorPage = “URL_error”

345645. errorPage = “&lt;URL_address &gt;”

345646. Variables created within a declaration block become __________ variables. ?

345646. Session

345646. Application

345646. Instance (***)

345646. Page

345647. JSPs or servlet can manopulate cookies using the ______ class ?

345647. javax.servlets.http.Cookie

345647. javax.servlet.Cookie

345647. javax.http.Cookie (***)

345647. servlet.http.Cookie

345648. An object can be bound using the ______ method in the HTTP Request interface. ?

345648. BindAttribute(string key, Object obj)

345648. SetAttribute(string key, Object obj) (***)

345648. SetAttribute(string key)

345648. Bindattribute(string object)

128

345649. jdbc.drivers = sun.jdbc.odbc.JdbcOdbcDriver<BR>The Above statement:<BR>1. loads the JDBC-ODBC

bridge drivers<BR>2. unloads&nbsp; the JDBC-ODBC bridge drivers ?

345649. 1 is true, 2 is false. (***)

345649. 1 is false, 2 is true.

345649. 1 and 2 are true.

345649. 1 and 2 are false

345650. The ______ interface communicates with the database, either directly or thought another database specific

driver. ?

345650. DirectManager

345650. Statement

345650. Connection

345650. Driver (***)

345651. Which of the follwing are characteristics of JSP actions?<BR>i) The tags are case-sensitive<BR>ii) Action

can access, modify and create objects on the current server pages<BR>iii) Tags must not have a closing

delimiter<BR>iv) New actions cannot be built ?

345651. ii - iii

345651. iii - iv

345651. ii - iv

345651. i - ii (***)

345652. Which of the following item can exist in a web application? ?

345652. JavaServer Pages

345652. Static Documents including, XHTML, images etc.

345652. Meta information that describes the web application

345652. All of them (***)

345653. Which of these operations are provided by DML Data Manipulation Language? ?

345653. Encoding the data

345653. Creating &amp; deleting a table

345653. Creating table

345653. Inserting data and updating data (***)

345654. Which of the following action is used to provide the tag/value pairs of information, by including attributes

like &lt;jsp:include&gt; ?

345654. &lt;jsp:param&gt; (***)

345654. &lt;jsp:useBean&gt;

345654. &lt;jsp:getProperty&gt;

345654. &lt;jsp:tag&gt;

345655. Statement 1: Every bean must have a default contructor.<BR>Statement 2: In JSP, JavaBeans need not

implement the serializable interface. ?

345655. 1 is true, 2 is false

345655. 1 is false, 2 is true

345655. Both is true (***)

345655. Both is false

345656. _______ are small pieces of information that are deposited on the client by the server ?

129

345656. Session

345656. Cookies (***)

345656. Directives

345656. Scriptlets

345657. In which file do we define a servlet mapping ? ?

345657. web.xml (***)

345657. servlet.mappings

345657. servlet.xml

345657. Simple.java

345658. Servlets and JavaServer Pages have become so popular that they are now supported directly or with third-

party plug-ins by most major Web servers and application servers. ?

345658. true (***)

345658. false

345658. Cannot say

345658. none of them

345659. All servlets must implement the Servlet interface of package: ?

345659. java.servlet

345659. javax.servlet (***)

345659. servlet

345659. All are same

345660. The Web server that executes the servlet creates an _________ object and passes this to the servlet's service

method (which, in turn, passes it to doGet or doPost). ?

345660. HttpServletResponce

345660. HttpRequest

345660. ServletRequest

345660. HttpServletRequest (***)

345661. The client can access the servlet only if the servlet is installed on a ________ that can respond to servlet

requests. ?

345661. client

345661. server (***)

345661. Internet

345661. in your network

345662. Java Networking Java 1.1 natively supports which of the following protocols:<BR>1. TCP<BR>2.

UDP<BR>3. SMB ?

345662. 1 and 2 only

345662. 1 only (***)

345662. 2 and 3 only

345662. 1 and 3 only

345663. Which of the following describe ways that dynamic information can be made available to all servlet requests

sent to an application ?

345663. Make the information available from a singleton

345663. Store the information in the ServletContext

130

345663. Store the information in an HttpSession (***)

345663. Store the information in a Properties file

345664. Which of the following can be used to store client side user state information while avoiding any impact due

to the users web browser configuration ? ?

345664. Cookies

345664. URL rewriting

345664. HttpSessions (***)

345664. Hidden tags

345665. Parameters are passed as _______ pairs in a get request. ?

345665. value

345665. name/value (***)

345665. Both can be used

345665. None of these

345666. Which of the following identifies the correct method a servlet developer should use to retrieve form data

from the client provided to the doPost() method ? ?

345666. getParameter() against the HttpServletRequest object

345666. getInputStream() against the HttpServletrequest object

345666. getBytes() against the HttpServletrequest object (***)

345666. getQueryString() against the HttpServletrequest object

345667. Which of the following is NOT true about servlets ? ?

345667. They are instantiated every time a request is made.

345667. They are a mechanism used by the class loader to download applets. (***)

345667. They can be used instead of CGI scripts.

345667. They require a web browser that supports JDK 1.1

345668. If you delete a field from a class and recompile the class, but then load an object that was serialised before

the new class was compiled what will happen? ?

345668. The new object will contain all the data it used to but the new field is not accessible

345668. The old class will be reloaded.

345668. The new object will contain all the data it used to including the removed field (***)

345668. An exception will occur

345669. In Java threads. Which of the following can you do with the synchronized keyword:<BR>1. Synchronise on

an object<BR>2. Synchronise on a static method<BR>3. Synchronise around code that exists in a method of an

instance of an object. ?

345669. 1 and 2 only (***)

345669. 1 and 3 only

345669. 1 only

345669. 2 and 3 only

345670. What is the servlet ? ?

345670. Client side program

345670. Server side program (***)

345670. Both are true

345670. None of these

131

345671. Choose the statement that best describes the relationship between JSP and servlets: ?

345671. Servlets are built on JSP semantics and all servlets are compiled to JSP pages for runtime usage.

345671. JSP and servlets are unrelated technologies.

345671. Servlets and JSP are competing technologies for handling web requests. Servlets are being superseded by

JSP, which is preferred. The two technologies are not useful in combination.

345671. JSPs are built on servlet semantics and all JSPs are compiled to servlets for runtime usage. (***)

345672. Which of the following can the JSP include action include output from ? ?

345672. Another JSP

345672. Servlet

345672. Plain text file

345672. All of the above (***)

345673. What is wrong with the following code ?

<BR>&lt;%<BR>if(strPassword.equals("boss"))<BR>{<BR>&lt;jsp:forward page="Welcome.jsp"

flush="true"/&gt;<BR>}<BR>else<BR>{<BR>}<BR>%&gt; ?

345673. Unmatched bracket in for statement

345673. Flush attribute must be false

345673. Keyword 'file' should be used instead of 'page' in the &lt;jsp:forward/&gt; action

345673. Actions cannot be used within scriptlet blocks (***)

345674. What is wrong with the following code ?<BR>&lt;jsp:include page="MainMenu.jsp"

flush="true"/&gt;<BR>&lt;%<BR>Cookie c = new Cookie("UserName", "Alastair

Gulland");<BR>response.addCookie(c);<BR>%&gt; ?

345674. Cookie class can not take parameters in it's constructor

345674. The request object is used for creating cookies

345674. Although no error will be reported the use of the &lt;jsp:include/&gt; action means that the response object

can't be used to create cookies. (***)

345674. The &lt;jsp:include/&gt; action must be placed inside the script block

345675. When a JSP page is compiled, what is it turned into ? ?

345675. Applet

345675. Servlet (***)

345675. Application

345675. Mailet

345676. Which of the following is not a standard method called as part of the JSP life cycle ? ?

345676. jspInit()

345676. jspService()

345676. _jspService() (***)

345676. jspDestroy()

345677. If you want to override a JSP file's initialization method, within what type of tags must you declare the

method ? ?

345677. &lt;@ @&gt;

345677. &lt;%@ %&gt;

345677. &lt;% %&gt;

345677. &lt;%! %&gt; (***)

132

345678. What is JSP ? ?

345678. Java Server Pages (***)

345678. Java Special Pages

345678. Java Static Pages

345678. Java Showing Pages

345679. What are not the directives defined in the JSP specification? ?

345679. include

345679. page

345679. language

345679. taglib (***)

345680. The interfaces and classes of the __________________ package are used to handle and register remote

objects by name. ?

345680. java.rmi.server package

345680. java.rmi.package

345680. java.rmi.registry package (***)

345680. java.rmi.activation package

345681. The statements given below define the implementation of the Remote Interface.&nbsp; Which of these is not

true. ?

345681. Classes that implement the remote interface generally extend the „UnicastRemoteObject‟ class.

345681. The implementation class does not require a constructor. (***)

345681. The implementation class also implements all the methods present in the remote interface.

345681. The implementation class has a main() function.

345682. The command required to start the RMI registry is ____________________ ?

345682. start rmiregistry (***)

345682. run rmiregistry

345682. execute rmiregistry

345682. begin rmiregistry

345683. For listening to incoming requests the RMI registry uses port ___________. ?

345683. 1024

345683. 65535

345683. 1099 (***)

345683. 1433

345684. Marshalling is the process that converts arguments and return values into ___________________ that can be

sent over the network. ?

345684. data

345684. bits of information

345684. stream of bytes (***)

345684. bits and bytes.

345685. ___________________ is not a model for developing distributed applications. ?

345685. DCOM

345685. COM (***)

133

345685. RMI

345685. CORBA

345686. The RMI defines the difference between _______________ and _______________ objects. ?

345686. public/global

345686. remote/local (***)

345686. distributed/concentrated

345686. random/definite

345687. At present,&nbsp; ____________ is used by RMI to communicate between the ____________ transport

layer and the _________________ transport layer. ?

345687. IPX/PX, client, user

345687. Remote access, remote, network

345687. NetBEUI, proxy, host

345687. TCP/IP, client, server (***)