Java Final Review

Ace your homework & exams now with Quizwiz!

Java's Thread class is in the ____________ package. a. java.util b. java.thread c. java.lang d. javax.swing

java.lang

The main method executes in the ________ thread of execution. a. starting b. main c. local d. None of the above.

main

The sleep method of the Thread class requires one formal parameter that represents the number of: a. nanoseconds b. microseconds c. picoseconds d. milliseconds

milliseconds

When using Java's built-in monitors, every object has a(n) ________ or a(n) ________ that the monitor ensures is held by a maximum of only one thread at any time. a. monitor lock, intrinsic lock. b. built-in lock, free lock. c. mutual exlcusion lock, synchronization lock. d. None of the above.

monitor lock, intrinsic lock.

A new thread begins its life cycle by transitioning to the __________ state. a. runnable. b. waiting. c. terminated. d. new.

new

When a thread executing a synchronized statement (or method) completes or satisfies the condition on which another thread may be waiting, it can call Object method ________ or ________ to allow a waiting thread or all waiting threads to transition to the runnable state again. a. notifyThread, notifyAllThreads. b. wakeUpThread, wakeUpAllThreads. c. notify, notifyAll. d. None of the above.

notify, notifyAll

You can simulate atomicity by ensuring that ________. a. at least one thread carries out its operations on an object at a time. b. two threads carry out their operations on an object in parallel. c. only one thread carries out its operations on an object at a time. d. None of the above.

only one thread carries out its operations on an object at a time

Threads execute in a ___________ fashion. a. parallel b. serial c. complex d. none of the above

parallel

In a producer/consumer relationship, the ________ portion of an application generates data and stores it in a shared object, and the ________ portion of an application reads data from the shared object. a. consumer, producer. b. producer, consumer. c. outputter, inputter. d. None of the above.

producer, consumer

The BlockingQueue interface declares which two methods for blocked adding and blocked removing of elements from a circular buffer? a. put and take b. add and remove c. push and pop d. place and get

put and take

The programming statements used to accomplish a threads task should be included in the method: a. start() b. init() c. run() d. none of the above

run()

Which method can be used to handle uncaught runtime exception generated in run method? a. exceptionHandler() b. defaultExceptionHandler() c. setDefaultUncaughtExceptionHandler() d. catchException()

setDefaultUncaughtExceptionHandler()

If a thread calls __________, then every thread waiting for the object becomes eligible to acquire the lock. a. signalEach b. signalAll c. signal d. signalMethods

signalAll

The ArrayBlockingQueue method ________ returns the number of elements currently in the ArrayBlockingQueue? a. size b. length c. getSize d. getLength

size

What method in the Thread class is responsible for pausing a thread for a specific amount of milliseconds? a. pause() b. sleep() c. hang() d. kill()

sleep()

If your class implements Runnable then what method is invoked to start the thread? a. run() b. execute() c. start() d. main()

start()

When a __________ method or block is running on an object, the object is locked so no other such method can run on that object at the same time. a. synchronized. b. shared. c. thread. d. writeable.

synchronized

Which one of the following statements is true with regard to a producer/consumer relationship with one producer and one consumer? a. A producer can never produce faster than the consumer is consuming. b. A consumer can never consume faster than the producer is producing. c. A producer can produce more items than a consumer consumes. d. A consumer can consume more items than a producer produces.

A producer can produce more items than a consumer consumes.

How can Thread go from waiting to runnable state? a. Notify/notifyAll b. When sleep time is up c. Using resume() method when thread was suspended d. All

All

How can we create Thread a. By Extending Thread Class b. Implementing Runnable interface c. By using Executor framework - which can internally form threads d. All above

All above

What is true about threads? I. Multi-threading reduces idle time of CPU II. Thread sometimes called a lightweight process III. Thread are sub-division of Process IV. One or more Threads runs in the context of process V. Threads can execute any part of process. And same part of process can be executed by multiple Threads a. I, II, and IV b. I, III, and IV c. I, II, and III d. All above

All above

Which method can make Thread to go from runnable to waiting state? a. wait() b. sleep() c. suspend() d. All above

All above

The solution is to make each thread wait so only one thread can run the code in increment() at a time. This section of code is called a(n) __________.

CRITICAL SECTION

An ExecutorService object is created by calling a static method of which class? a. Executor. b. Executors. c. ExecutorService. d. Thread.

Executors

An alternative to deriving a thread from the Thread class is to inherit the Runnable interface

F

The Java language does not support multithreading

F

The submit method, when passed a Callable, returns an object of this type. a. Future. b. Callable. c. Runnable. d. Executor.

Future

Which of the following methods are defined in class Thread? I. start() II. wait() III. notify() IV. run() V. terminate() a. I and IV b. II and IV c. II and III d. III and IV

I and IV

What is true about threads? I. wait(), notify(), notifyAll() are methods of Thread class II. When start() method is called on thread, it enters new state III. If a field is declared volatile, in that case the Java memory model ensures that all threads see a consistent value for the variable IV. Thread need to acquire lock before calling sleep() method a. I and IV b. I and II c. III only d. IV only

III only

38. When you use the sleep() method, you must catch a(n) __________.

INTERRUPTED EXCEPTION

What is pre-emptive scheduling in threads a. In pre-emptive scheduling, the highest priority thread executes until it enters into the waiting or dead state b. In pre-emptive scheduling, the low priority thread executes until it enters into the waiting or dead state c. In pre-emptive scheduling, the medium priority thread executes until it enters into the waiting or dead state d. Anyone may happen

In pre-emptive scheduling, the highest priority thread executes until it enters into the waiting or dead state

What will happen if two threads try to read same resource without synchronization in java a. It is not allowed in java b. It does not create any race condition c. Java will automatically create race condition d. None above

It does not create any race condition

Which of the following is not true of ExecutorService? a. It is a subinterface of Executor. b. It is an object that can be run in a separate thread. c. It declares method shutdown. d. It manages a group of threads.

It is an object that can be run in a separate thread.

This class is used to help implement mutual exclusion. a. MutEx b. Condition c. Lock d. Signal

Lock

What is true about threads? I. Deadlock is a situation where threads on different object are waiting for each other to release lock holded by them on resources II. When more than one thread try to access the same resource without synchronization causes deadlock(race condition) III. java.thread.Thread consists of all inbuilt java exceptions(java.lang.Thread) a. I and III b. I only c. III only d. None above

None above

Which class or interface defines the wait(), notify(), and notifyAll() methods? a. Object b. Runnable c. Class d. Thread

Object

With timeslicing, each thread is given a limited amount of time, called a __________, to execute on a processor. a. Quantum. b. Processor burst. c. Time allocation. d. Scheduling interval.

Quantum

When multiple threads change a shared variable it is sometimes possible that the variable will end up with the wrong (and often unpredictable) value. This is called ____________.

RACE CONDITION

What state does Thread enter in when it has been created and started? a. New b. Runnable c. Waiting d. Blocked

Runnable

The preferred means of creating multithreaded Java applications is by implementing the ________ interface. An object of a class that implements this interface represents a task to perform. a. Thread. b. Runner. c. Runnable. d. None of the above.

Runnable.

Which of the following is true for a correct producer/consumer relationship with one producer, one consumer, and a 5-cell buffer? a. The producer can produce when all cells are full. b. The consumer can consume when all cells are full. c. The consumer can consume when all cells are empty. d. None of the above.

The consumer can consume when all cells are full.

Which of these is not a Thread state? a. New b. Runnable c. Sleep d. Terminated

Sleep

A thread can acquire a lock by using which reserved keyword? a. Volatile b. Synchronized c. Locked d. None

Synchronized

A thread's start method invokes the thread's run method

T

An InterruptedException is a checked exception

T

In a producer/consumer relationship with a single cell of shared memory, which of the following is true? a. The consumer must run first. b. The producer must run first. c. The producer must run first or the consumer will have to wait. d. The consumer must run first or the producer will have to wait.

The producer must run first or the consumer will have to wait.

What is difference between starting thread with run() and start() methods? a. When you call start() method, main thread internally calls run() method to start newly created Thread b. Run() calls start() method internally c. There is no difference d. None

When you call start() method, main thread internally calls run() method to start newly created Thread

Which method can be used to find whether Thread hasn't entered dead state? a. isAlive() b. isRunning() c. isNotDead() d. All

isAlive()

In a producer/consumer relationship, when a consumer finds the buffer empty or finds that the previous data has already been read, the consumer should call __________. a.lock b.signal c.sleep d.await

await

Interface ExecutorService provides the ________ method, which returns control to its caller either when all tasks executing in the ExecutorService complete or when the specified timeout elapses. a. waitForTermination. b. wait. c. awaitTermination. d. None of the above.

awaitTermination

The Callable interface declares this method. a. get b. call c. run d. execute

call

SwingWorker method ________ executes a long computation in a worker thread. a. execute. b. performCalculation. c. doInBackground. d. None of the above.

doInBackground

The ________ thread should be used to perform all tasks that manipulate GUI components, because they are not thread safe. a. event-handling. b. event-dispatch. c. GUI-handling. d. None of the above.

event-dispatch

When a thread obtains the monitor lock on an object, then determines that it cannot continue with its task on that object until some condition is satisfied, the thread can call Object method ________; this releases the monitor lock on the object, and transitions the thread waits to the waiting state. a. waitForOtherThreads b. stop c. waitForCondition d. wait

wait


Related study sets

Solving Quadratics by Factoring, Quadratic Formula, and Square roots

View Set

Programming Logic and Design, Chapters 7-13 & 15

View Set

chapter 4 state of consciousness

View Set

Social Work Study Session 6 Quiz

View Set

Chapter 6 Study Guide: Enlightenment and Revolution

View Set

13- THE CIVIL SERVICE COMMISSION

View Set

C#: Ch. 9: Using Classes and Objects

View Set

Section 7, Unit 4: Mortgage Lending Tax Impacts

View Set