wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JUNIT & MULTI THREADING

Total questions: 202

Worksheet time: 2hrs 20mins

Name
Class
Date
1.

Which of the following describes Testing correctly?

a)

A - Testing is the process of checking the functionality of the application whether it is working as per requirements.

b)

B - Testing is the testing of single entity (class or method).

c)

C - Both of the above.

d)

D - None of the above.

2.

Which of the following class contains methods to collect the results of executing a test case?

a)

A - Assert

b)

B - TestCase

c)

C - TestResult

d)

D - TestSuite

3.

Is it necessary to write the test case for every logic?

a)

Yes

b)

No

4.

If the JUnit method's return type is 'string', what will happen?

a)

the execution will Pass

b)

the execution will fail.

c)

the execution will Not Excute

d)

syntax error

5.

Is it necessary to write the test class to test every class?

a)

Yes

b)

NO

6.

Which method is used to verify the actual and expected results in Junits?

a)

equals()

b)

isEqual()

c)

==

d)

assert()

7.

JUnits are used for which type of testing?

a)

Blackbox Testing

b)

Unit Testing

c)

System Testing

d)

Integration Testing

8.

Assert contains a set of assert methods.

a)

A - true

b)

B - false

9.

Automated Test cases are executed by using automation tool so less tester are required in automation testing.

a)

A - true

b)

B - false

10.

what is integration testing??

a)

Testing the each module individually

b)

Tetsing two or more modules after combining

11.

Is there any direct way to test "Private Method"?

a)

Yes

b)

No

12.

Is JUnit only report the first failure in a single test ?

a)

Yes

b)

No

13.

What is the most basic type of developer level test?

a)

Integration Test

b)

Universal Test

c)

Unit Test

d)

Basic Test

14.

Which of the following is not a desirable quality of "a unit test"?

a)

Tests one property at one time

b)

Fast

c)

I/O or File Operations

d)

Covering a small portion of code

15.

What is the significance of writing a failing test?

a)

We should not. We should focus on writing a test that passes

b)

A failing test shows that some code change is required in our program. If it is not failing, no change required.

c)

A failing test shows that the previous developer didn't do a good job.

d)

A failing test gives you an opportunity to enhance code coverage

16.

What is a test?

a)

A measure to check if the code meets the defined specifications

b)

A measure to check if the code is visually beautiful

c)

A measure to check if the code contains security vulnerabilities?

d)

A measure to increase code coverage

17.

I need to test if a service method is fine or not. What type of test do I need to write?

a)

Unit Test

b)

Integration Test

c)

Selenium Test

d)

Black Box Test

18.

Which of the following describes Testing correctly?

a)

A - Testing is the process of checking the functionality of the application whether it is working as per requirements.

b)

B - Testing is the testing of single entity (class or method).

c)

C - Both of the above.

d)

D - None of the above.

19.

Which of the following class contains methods to collect the results of executing a test case?

a)

A - Assert

b)

B - TestCase

c)

C - TestResult

d)

D - TestSuite

20.

Which of the following annotation causes that method run once after all tests have finished?

a)

A - @Test

b)

B - @After

c)

C - @BeforeClass

d)

D - @AfterClass

21.

Which of the following method of Assert class checks that an object is null?

a)

A - void assert(Object object, boolean toCheckAsNull)

b)

B - void assertCheck(Object object, boolean toCheckAsNull)

c)

C - void assertNull(Object object)

d)

D - void assertChecks(Object object, boolean toCheckAsNull)

22.

Which of the following method of TestResult class gets the number of detected failures?

a)

A - int error()

b)

B - int errorCount()

c)

C - int failureCount()

d)

D - int failure()

23.

@RunWith and @Suite annotation are used to run the suite test.

a)

A - false

b)

B - true

24.

Automated Test cases are executed by using automation tool so less tester are required in automation testing.

a)

A - true

b)

B - false

25.

Assert contains a set of assert methods.

a)

A - true

b)

B - false

26.

Which of the following method of Assert class checks that a condition is true?

a)

A. void assert(boolean condition)

b)

B. void assertTrue(boolean condition)correct

c)

C. void assertCheck(boolean condition)

d)

D. void assertChecks(boolean condition)

27.

Which of the following method of TestSuite class adds the tests from the given class to the suite?

a)

A. void addTest(Class testClass)wrong

b)

B. void addTestSuite(Class testClass)correct

c)

C. void addTest(TestCase testClass)

d)

D. void addTestCase(TestCase testClass)

28.

JUnits are used for which type of testing?

a)

Blackbox Testing

b)

Unit Testing

c)

System Testing

d)

Integration Testing

29.

Which of the below is an incorrect annotation with respect to JUnits?

a)

@Junit

b)

@AfterEach

c)

@Test

d)

@BeforeClass

30.

Which method is used to verify the actual and expected results in Junits?

a)

equals()

b)

isEqual()

c)

==

d)

assert()

31.

What does assertSame() method use for assertion?

a)

equals() method

b)

isEqual() method

c)

==

d)

compare() method

32.

Which of the following describes Testing correctly?

a)

A - Testing is the process of checking the functionality of the application whether it is working as per requirements.

b)

B - Testing is the testing of single entity (class or method).

c)

C - Both of the above.

d)

D - None of the above.

33.

Which of the following class contains methods to collect the results of executing a test case?

a)

A - Assert

b)

B - TestCase

c)

C - TestResult

d)

D - TestSuite

34.

Which of the following annotation causes that method run once after all tests have finished?

a)

A - @Test

b)

B - @After

c)

C - @BeforeClass

d)

D - @AfterClass

35.

Which of the following method of Assert class checks that an object is null?

a)

A - void assert(Object object, boolean toCheckAsNull)

b)

B - void assertCheck(Object object, boolean toCheckAsNull)

c)

C - void assertNull(Object object)

d)

D - void assertChecks(Object object, boolean toCheckAsNull)

36.

@RunWith and @Suite annotation are used to run the suite test.

a)

A - false

b)

B - true

37.

Automated Test cases are executed by using automation tool so less tester are required in automation testing.

a)

A - true

b)

B - false

38.

Assert contains a set of assert methods.

a)

A - true

b)

B - false

39.

Which of the following method of Assert class checks that a condition is true?

a)

A. void assert(boolean condition)

b)

B. void assertTrue(boolean condition)correct

c)

C. void assertCheck(boolean condition)

d)

D. void assertChecks(boolean condition)

40.

Which of the following method of TestSuite class adds the tests from the given class to the suite?

a)

A. void addTest(Class testClass)wrong

b)

B. void addTestSuite(Class testClass)correct

c)

C. void addTest(TestCase testClass)

d)

D. void addTestCase(TestCase testClass)

41.

JUnits are used for which type of testing?

a)

Blackbox Testing

b)

Unit Testing

c)

System Testing

d)

Integration Testing

42.

Which of the below is an incorrect annotation with respect to JUnits?

a)

@Junit

b)

@AfterEach

c)

@Test

d)

@BeforeClass

43.

Which method is used to verify the actual and expected results in Junits?

a)

equals()

b)

isEqual()

c)

==

d)

assert()

44.

What does assertSame() method use for assertion?

a)

equals() method

b)

isEqual() method

c)

==

d)

compare() method

45.

What is the use of Junit

a)

To increase code coverage

b)

To test unit of code thoroughly

c)

To integrate with other units of code

46.

Is it necessary to write the test case for every logic?

a)

Yes

b)

No

47.

Is there any direct way to test "Private Method"?

a)

Yes

b)

No

48.

Is JUnit only report the first failure in a single test ?

a)

Yes

b)

No

49.

What is the most basic type of developer level test?

a)

Integration Test

b)

Universal Test

c)

Unit Test

d)

Basic Test

50.
The best way to avoid problems is to write the program before writing the algorithm.
a)
True
b)
False
51.

which of the following are framework of testings (testing frameworks)

a)

JUNIT

b)

JUNIT and WordPress

c)

Selenium

d)

Selenium and REST

52.

Assert.assertEquals(calculadoraSimple.suma("1", "2"), 5);

a)

Assert OK

b)

Assert Failure

c)

Assert Exception

53.

Assert.assertEquals(calculadoraSimple.suma(null, "2"), 5);

a)

Assert OK

b)

Assert Failure

c)

Assert Exception

54.

Assert.assertNotEquals(calculadoraSimple.suma("5", "2"), 3);

a)

Assert OK

b)

Assert Failure

c)

Assert Exception

55.

@Test(expected = RuntimeException.class)

...

Assert.assertEquals(calculadora.suma(null, "2"), 3);

a)

Assert OK

b)

Assert Failure

c)

Assert Exception

56.

MAVEN needs

a)

web.xml

b)

manifest.yml

c)

pom.xml

d)

all of them

57.

JUnit is used for what type of software testing for the Java language?

a)

Functional Testing

b)

System Testing

c)

Unit Testing

d)

Integration Testing

58.

Which annotation implies that a method is a JUnit test case?

a)

@org.junit.Test

b)

@org.Test

c)

@testcase

d)

@junit

59.

JUnit test files are written in files with which file extension?

a)

.unit

b)

.java

c)

.test

d)

.junit

60.

Which methods cannot be tested by the JUnit test class?

a)

protected methods

b)

methods with void return type

c)

private methods

d)

public methods

61.

JUnit test methods must compulsorily return what value?

a)

void

b)

Object

c)

String

d)

int

62.

To use JUnit in a project we need to add which JAR files on our test classpath?

a)

java-junit.jar

b)

junit.jar and hamcrest-core.jar

c)

hamcrest-core.jar

d)

junit.jar

63.

Which of the following method of Assert class checks that a condition is false?

a)

void assert(boolean condition)

b)

void assertFalse(boolean condition)

c)

void assertCheck(boolean condition)

d)

void assertChecks(boolean condition)

64.

Which of the following class is used to bundle unit test cases and run them together?

a)

JUnitCore

b)

TestCase

c)

TestSuite

d)

TestResult

65.

Which of the following describes Testing correctly?

a)

Testing is the process of checking the functionality of the application whether it is working as per requirements.

b)

Testing is the testing of single entity (class or method).

c)

Both of the above.

d)

None of the above.

66.

Which of the following method of Assert class checks that a condition is true?

a)

void assert(boolean condition)

b)

void assertTrue(boolean condition)

c)

void assertCheck(boolean condition)

d)

void assertChecks(boolean condition)

67.
How to parameterize a JUnit?
a)
a) Create a Java test class
b)
b) Add annotations to the test method
c)
c) Generate a test runner class
d)
d) Write parameterized assertions
68.
Does JUnit support parameterized tests?
a)
a) No, JUnit doesn't support parameterized tests
b)
b) Yes, JUnit supports parameterized tests
c)
c) Parameterized tests are deprecated in JUnit
d)
d) Parameterized tests are only supported in JUnit 4
69.
How do you write parameterized tests?
a)
a) Use the @Parameterized annotation
b)
b) Configure the test class display name
c)
c) Add a new test method with String parameter
d)
d) Use the @ParameterizedTest annotation
70.
What is the difference between JUnit theory and parameterized?
a)
a) Theories test individual inputs, parameterized tests test inputs as a whole
b)
b) Theories are deprecated, parameterized tests are preferred
c)
c) Theories require annotations, parameterized tests don't
d)
d) Theories are only available in JUnit 3, parameterized tests in JUnit 4
71.
How to parameterize a method in Java?
a)
a) Specify parameters after the method name
b)
b) Add annotations to the method
c)
c) Use a separate parameterization file
d)
d) Use a generic method
72.
What is a parameterized test case?
a)
a) A test case with dynamic input values
b)
b) A test case that clones and replicates itself
c)
c) A test case with multiple assertions
d)
d) A test case with different sets of parameters
73.
What is the advantage of parameterized tests?
a)
a) Reduced test execution time
b)
b) Ability to handle edge case scenarios efficiently
c)
c) Increased code coverage
d)
d) Automatic generation of test data
74.
What are parameterized types?
a)
a) Generic types with actual type arguments
b)
b) Types that receive parameters during runtime
c)
c) Types with dynamically assigned parameters
d)
d) Types with multiple inheritance
75.
What are parameterized methods?
a)
a) Methods with multiple return values
b)
b) Methods that take parameters as inputs
c)
c) Methods with dynamic behavior based on parameters
d)
d) Methods that can be overridden with different parameters
76.
What is the use of parameterized?
a)
a) Assigning values to instance variables
b)
b) Passing parameters to test methods
c)
c) Controlling the execution flow of tests
d)
d) Customizing the behavior of test cases
77.
What is the difference between JUnit 3 and JUnit 4?
a)
a) JUnit 4 supports parameterized tests, JUnit 3 doesn't
b)
b) JUnit 3 requires Java 5 or higher, JUnit 4 doesn't
c)
c) JUnit 4 uses annotations and generics, JUnit 3 doesn't
d)
d) JUnit 3 has better backward compatibility than JUnit 4
78.
What is dynamic vs parameterized test?
a)
a) Dynamic tests have no lifecycle, parameterized tests do
b)
b) Dynamic tests support cloning, parameterized tests don't
c)
c) Dynamic tests are deprecated, parameterized tests are preferred
d)
d) Dynamic tests execute faster than parameterized tests
79.

Execution of a java thread begins on which method call?

a)

Run ()

b)

Start ()

c)

Execute ()

d)

Launch ()

80.

How many ways a thread can be created in Java multithreading?

a)

1

b)

2

c)

5

d)

10

81.

Which method is used to make main thread to wait for all child threads

a)

Join ()

b)

Sleep ()

c)

Wait ()

d)

Stop ()

82.

Which will contain the body of the thread in Java?

a)

Start()

b)

Run()

c)

Main()

d)

Execute()

83.

The life cycle of a thread in java is controlled by

a)

JRE

b)

JDK

c)

JVM

d)

None

84.

Which method is used to get current running thread object?

a)

runningThread()

b)

currentThread()

c)

runnableThread()

d)

None

85.

Synchronized static methods acquire lock on

a)

Class

b)

Object

c)

Interface

d)

None

86.

Thread priority in Java is?

a)

Integer

b)

Float

c)

Double

d)

Long

87.

In JAVA multi threading, a thread can be created by_______

a)

Extending class

b)

Implementing Runnable Interface

c)

both

d)

none

88.

Which statements is/are correct

a)

On calling Thread start ( ) method a new thread is created

b)

Thread start( ) method call run( ) method internally

c)

Thread run( ) method can also be called directly to create thread

d)

both a & b

89.

Q) What is maximum thread priority in Java

a)

10

b)

12

c)

5

d)

8

90.

Q) Number of threads in below java program is

public class ThreadExtended extends Thread {


public void run() {

System.out.println("\nThread is running now\n");

}


public static void main(String[] args) {


ThreadExtended threadE = new ThreadExtended();


threadE.start();

}

}

a)

0

b)

1

c)

2

d)

3

91.

Q) Execution of a java thread begins on which method call?

a)

Start ()

b)

Run ()

c)

Execute ()

d)

Launch ()

92.

Q) Which method is used to check if a thread is running?

a)

isAlive()

b)

run ()

c)

alive ()

d)

keepAlive()

93.

Q) Min and Max priority of a thread in Java multithreading are

a)

1, 10

b)

0,10

c)

0,255

d)

1,256

94.
What is sometimes also called a lightweight process?
a)
Thread
b)
Process
c)
JVM
95.
Which of these is not a Thread state?
a)
New
b)
Runnable
c)
sleep
d)
terminated
96.

Data________ focus on distributing subsets of the same data across multiple computing cores and perform the same operation on each core

a)

sequencing

b)

synchronization

c)

parallelism

d)

kernel threads

97.

___________distributing task across multiple computing cores

a)

data parallelism

b)

implicit threading

c)

task parallelism

d)

identifying task

98.

Daemon thread runs in

a)

BackGround

b)

Foreground

c)

Both

d)

none

99.

class MyThread implements Runnable {

public void run() {

System.out.println(Thread.currentThread().getName());

}

}

public class ThreadTest {

public static void main(String arg[]) {

Thread thread = new Thread(new MyThread());

thread.run();

thread.run();

thread.start();

}

}

a)

main

main

Thread-0

b)

Thread-0

main

Thread-1

c)

main

Thread-0

Thread-1

d)

Thread-0

Thread-1

Thread-2

100.

class MyThread extends Thread {


public MyThread(String name) {

this.setName(name);

}


public void run() {

try {

sleep(100);

} catch (InterruptedException e) {

e.printStackTrace();

}

play();

}


private void play() {

System.out.print(getName());

System.out.print(getName());

}

}


public class ThreadTest {

public static void main(String args[]) throws InterruptedException {

Thread tableThread = new MyThread("Table");

Thread tennisThread = new MyThread("Tennis");

tableThread.start();

tennisThread.start();

}

}

a)

a) This program will throw an IllegalStateException.

b)

b) This program will always print the following: Tennis Tennis Table Table.

c)

c) This program will always print the following: Table Table Tennis Tennis.

d)

d) The output of this program cannot be predicted; it depends on thread scheduling.

101.

class Worker extends Thread {

public void run() {

System.out.println(Thread.currentThread().getName());

}

}


public class Master {

public static void main(String[] args) throws InterruptedException {

Thread.currentThread().setName("Master ");

Thread worker = new Worker();

worker.setName("Worker ");

worker.start();

Thread.currentThread().join();

System.out.println(Thread.currentThread().getName());

}

}

a)

a) When executed, the program prints the following: “Worker Master ”.

b)

b) When executed, the program prints “Worker ”, and after that the program hangs (i.e., does not terminate).

c)

c) When executed, the program prints “Worker ” and then terminates.

d)

d) When executed, the program throws IllegalMonitorStateException.

e)

e) The program does not compile and fails with multiple compiler errors.

102.

What code is missing?

public class MyRunnable implements Runnable

{

public void run()

{

// some code here

}

}

a)

new Thread(MyRunnable).run();

b)

new Runnable(MyRunnable).start();

c)

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

d)

new MyRunnable().start();

103.

Which of the following line of code is suitable to start a thread?

class Demo implements Runnable

{

public void run() {

System.out.println(“Thread is in Running state”);

}


public static void main(String args[])

{

/* Missing code? */

}

}

a)

Demo obj = new Demo();

Thread tobj = new Thread(obj);

tobj.start();

b)

Thread t = new Thread(X);

t.start();

c)

Thread t = new Thread(Demo);

d)

Thread t = new Thread();

Demo.run();

104.

class ThreadDemo extends Thread

{

public static void main(String [] args)

{

ThreadDemo t = new ThreadDemo();

t.start();

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

t.start();

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

}

public void run()

{

System.out.print("Thread ");

}

}

a)

An exception occurs at runtime.

b)

Compilation fails.

c)

. It prints "Thread one. Thread two.".

d)

The output cannot be determined.

105.

1. public class Test extends Thread{

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

3. Test t = new Test();

4. t.run();

5. t.start();

6. }

7. public void run(){

8. System.out.println("run-test");

9. }

10. }

a)

A. run-test run-test

b)

B. run-test

c)

C. Compilation fails due to an error on line 4

d)

D. Compilation fails due to an error on line 7

106.

class A implements Runnable{

public void run(){

try{

for(int i=0;i<4;i++){

Thread.sleep(100);

System.out.println(Thread.currentThread().getName());

}

}catch(InterruptedException e){

}

}

}


public class Test{

public static void main(String argv[]) throws Exception{

A a = new A();

Thread t = new Thread(a, "A");

Thread t1 = new Thread(a, "B");

t.start();

t.join();

t1.start();

}

}

a)

Compilation succeed but Runtime Exception

b)

A B A B A B A B

c)

Output order is not guaranteed

d)

A A A A B B B B

107.

How many ways a thread can be created in Java multithreading?

a)

1

b)

2

c)

5

d)

10

108.

Which will contain the body of the thread in Java?

a)

Start()

b)

Run()

c)

Main()

d)

Execute()

109.

The life cycle of a thread in java is controlled by

a)

JRE

b)

JDK

c)

JVM

d)

None

110.

Which method is used to get current running thread object?

a)

runningThread()

b)

currentThread()

c)

runnableThread()

d)

None

111.

In JAVA multi threading, a thread can be created by_______

a)

Extending class

b)

Implementing Runnable Interface

c)

both

d)

none

112.

Q) What is maximum thread priority in Java

a)

10

b)

12

c)

5

d)

8

113.

Q) Execution of a java thread begins on which method call?

a)

Start ()

b)

Run ()

c)

Execute ()

d)

Launch ()

114.
What is sometimes also called a lightweight process?
a)
Thread
b)
Process
c)
JVM
115.
Which of these is not a Thread state?
a)
New
b)
Runnable
c)
sleep
d)
terminated
116.

Thread is _____________process that can run independently

a)

heavyweight

b)

lightweight

c)

compaction

d)

compression

117.

What is multithreaded programming

a)

It’s a process in which two different processes run simultaneously

b)

It’s a process in which two or more parts of same process run simultaneously

c)

It’s a process in which many different process are able to access same information

d)

It’s a process in which a single process can access information from many sources

118.

Which of these are types of multitasking?

a)

Process based

b)

Thread based

c)

Process and Thread based

d)

None of the mentioned

119.

Q) How many ways a thread can be created in Java multithreading?

a)

1

b)

2

c)

3

d)

4

120.

Q) Default value of a java thread is

a)

0

b)

1

c)

5

d)

10

121.

Q) If a priority of a java thread is 3 then the default priority of its child thread will be

a)

0

b)

1

c)

5

d)

3

122.

Threads are belongs to the following package

a)

import java.lang.*

b)

import java.util.*

c)

import java.io.*

d)

import java.Thread.*

123.

Choose THREE(3) benefits of multithreaded processing

a)

scalability

b)

resource sharing

c)

privacy

d)

responsiveness

124.

The order of execution if threads is managed by:

a)

Java Compiler

b)

Default Scheduler

c)

Thread Manager

d)

Thread Scheduler

125.

1. The capability to control the access of multiple threads to any shared resource is called_____________

a)

Synchronization

b)

Multitasking

c)

multithreading

d)

None

126.

What are the approaches under mutual exclusion?

a)

Synchronized method

b)

Synchronized block

c)

Static synchronization

d)

All the above

127.

wait(), notify() and notifyAll() belongs to which class?

a)

Thread

b)

Object

c)

FileInputStream

d)

Exception

128.

How many ways a thread can be created in Java multithreading?

a)

1

b)

2

c)

5

d)

10

129.

Which method is used to make main thread to wait for all child threads

a)

Join ()

b)

Sleep ()

c)

Wait ()

d)

Stop ()

130.

Which will contain the body of the thread in Java?

a)

Start()

b)

Run()

c)

Main()

d)

Execute()

131.

The life cycle of a thread in java is controlled by

a)

JRE

b)

JDK

c)

JVM

d)

None

132.

Which method is used to get current running thread object?

a)

runningThread()

b)

currentThread()

c)

runnableThread()

d)

None

133.

Synchronized static methods acquire lock on

a)

Class

b)

Object

c)

Interface

d)

None

134.

Thread priority in Java is?

a)

Integer

b)

Float

c)

Double

d)

Long

135.

In JAVA multi threading, a thread can be created by_______

a)

Extending class

b)

Implementing Runnable Interface

c)

both

d)

none

136.

Which statements is/are correct

a)

On calling Thread start ( ) method a new thread is created

b)

Thread start( ) method call run( ) method internally

c)

Thread run( ) method can also be called directly to create thread

d)

both a & b

137.

Q) What is maximum thread priority in Java

a)

10

b)

12

c)

5

d)

8

138.

Q) Number of threads in below java program is

public class ThreadExtended extends Thread {


public void run() {

System.out.println("\nThread is running now\n");

}


public static void main(String[] args) {


ThreadExtended threadE = new ThreadExtended();


threadE.start();

}

}

a)

0

b)

1

c)

2

d)

3

139.

Q) Execution of a java thread begins on which method call?

a)

Start ()

b)

Run ()

c)

Execute ()

d)

Launch ()

140.

Q) Which method is used to check if a thread is running?

a)

isAlive()

b)

run ()

c)

alive ()

d)

keepAlive()

141.

Q) Min and Max priority of a thread in Java multithreading are

a)

1, 10

b)

0,10

c)

0,255

d)

1,256

142.
What is sometimes also called a lightweight process?
a)
Thread
b)
Process
c)
JVM
143.
Which of these is not a Thread state?
a)
New
b)
Runnable
c)
sleep
d)
terminated
144.

___________distributing task across multiple computing cores

a)

data parallelism

b)

implicit threading

c)

task parallelism

d)

identifying task

145.

Execution of a java thread begins on which method call?

a)

Run ()

b)

Start ()

c)

Execute ()

d)

Launch ()

146.

Choose THREE(3) benefits of multithreaded processing

a)

scalability

b)

resource sharing

c)

privacy

d)

responsiveness

147.

Thread is _____________process that can run independently

a)

heavyweight

b)

lightweight

c)

compaction

d)

compression

148.

a)

java.lang.RuntimeException: Problem

b)

run.

java.lang.RuntimeException: Problem

c)

End of method.

java.lang.RuntimeException: Problem

d)

End of method.

run.

java.lang.RuntimeException: Problem

e)

run.

java.lang.RuntimeException: Problem

End of method.

149.

a)

The code will deadlock.

b)

The code may run with no output.

c)

An exception is thrown at runtime.

d)

The code may run with output "0 6".

e)

The code may run with output "0 2 4 6".

150.

a)

synchronize the log method

b)

replace StringBuilder with StringBuffer

c)

replace StringBuilder with just a String object and use the string concatenation (+=) within the log method

d)

No change is necessary, the current MyLogger code is already thread-safe.

151.

a)

"done "

b)

"finally "

c)

"done finally "

d)

Compilation fails.

e)

No output is produced.

152.

Which are true? (Choose all that apply.)

a)

A. Compilation fails.

b)

The program’s minimum execution time is about 8 seconds.

c)

The program’s minimum execution time is about 9 seconds.

d)

The program’s minimum execution time is about 12 seconds.

e)

The program’s minimum execution time is about 16 seconds.

153.

Which method can be used to find whether lock is held by current thread?

a)

findLockHold()

b)

isLockHeld()

c)

holdsLock()

d)

lockHold()

154.

a)

Bang will execute for a second or two.

b)

Bang will execute for at least 10 minutes.

c)

Thread t1 will almost certainly be the last thread to finish.

d)

Thread t1 will almost certainly be the first thread to finish.

e)

It’s difficult to predict which thread will be the last to finish.

155.

a)

i L

b)

i N

c)

S L

d)

S N

e)

Compilation fails.

156.

What is the result? (Choose all that apply.)

a)

5

b)

7

c)

Compilation fails due to an error on line 8.

d)

Compilation fails due to an error on line 9.

e)

Compilation fails due to an error on line 13.

157.
a)

0

b)

01

c)

02

d)

03

158.

1. The capability to control the access of multiple threads to any shared resource is called_____________

a)

Synchronization

b)

Multitasking

c)

multithreading

d)

None

159.

_______________ and __________________ are the types of synchronization.

a)

Process synchronization and thread synchronization

b)

multitasking and multithreading

c)

Interthread communication and mutual exclusion

d)

None

160.

What are the approaches under mutual exclusion?

a)

Synchronized method

b)

Synchronized block

c)

Static synchronization

d)

All the above

161.

Identify the correct mutual exclusion approach:

synchronized(this)

{

….

….

}

a)

Synchronized method

b)

Synchronized block

c)

Static Synchronization

d)

None

162.

_____________tells calling thread to give up monitor and go to sleep until some other thread enters the same monitor and call notify.

a)

wait()

b)

notify()

c)

notifyAll()

d)

start()

163.

______________wakes up a thread that called wait() on same object.

a)

start()

b)

run()

c)

notify()

d)

sleep()

164.

Which is the static method?

a)

wait()

b)

sleep()

c)

Both

d)

None

165.

wait(), notify() and notifyAll() belongs to which class?

a)

Thread

b)

Object

c)

FileInputStream

d)

Exception

166.

Daemon thread is a _________priority thread.

a)

low

b)

high

c)

Normal

d)

None

167.

_______________is the return type of isDaemon()

a)

String

b)

int

c)

boolean

d)

float

168.

sleep() method belongs to which class?

a)

Object

b)

Thread

c)

Exception

d)

InputStream

169.

How many ways a thread can be created in Java multithreading?

a)

1

b)

2

c)

5

d)

10

170.

Which will contain the body of the thread in Java?

a)

Start()

b)

Run()

c)

Main()

d)

Execute()

171.

Which method is used to get current running thread object?

a)

runningThread()

b)

currentThread()

c)

runnableThread()

d)

None

172.

Thread priority in Java is?

a)

Integer

b)

Float

c)

Double

d)

Long

173.

In JAVA multi threading, a thread can be created by_______

a)

Extending class

b)

Implementing Runnable Interface

c)

both

d)

none

174.

Q) What is maximum thread priority in Java

a)

10

b)

12

c)

5

d)

8

175.

Q) Number of threads in below java program is

public class ThreadExtended extends Thread {


public void run() {

System.out.println("\nThread is running now\n");

}


public static void main(String[] args) {


ThreadExtended threadE = new ThreadExtended();


threadE.start();

}

}

a)

0

b)

1

c)

2

d)

3

176.

What will happen if two thread of the same priority are called to be processed simultaneously?

a)

Anyone will be executed first lexographically

b)

Both of them will be executed simultaneously

c)

None of them will be executed

d)

It is dependent on the operating system

177.

What is the priority of the thread in the following Java Program?

class multithreaded_programing

{

public static void main(String args[])

{

Thread t = Thread.currentThread(); System.out.println(t);

} }

a)

4

b)

5

c)

0

d)

1

178.

What will be the output of the program?

class Test implements Runnable {

public

void run()

{

System.out.println("Run");

}

} class Myclass {

public

static void main(String[] args)

{

Thread t1 = new Thread();

t1.start();

System.out.println("Main");

}

}

a)

Run

b)

Main

c)

Compile Time Error

d)

Run Main

179.

class newthread implements Runnable {

Thread t; newthread() {

t = new Thread(this,"My Thread");

t.start(); }

public void run() { System.out.println(t.getName()); } }

class multithreaded_programing {

public static void main(String args[]) {

new newthread(); }

}

a)

My Thread

b)

Thread[My Thread,5,main]

c)

Compilation Error

d)

Runtime Error

180.

Which of this method is used to find out that a thread is still running or not?

a)

a) run()

b)

b) Alive()

c)

c) isAlive()

d)

d) checkRun()

181.

Execution of a java thread begins on which method call?

a)

Run ()

b)

Start ()

c)

Execute ()

d)

Launch ()

182.

Daemon thread runs in

a)

BackGround

b)

Foreground

c)

Both

d)

none

183.
  1. What is true about threads?

a)
  1. Threads consumes CPU in best possible manner

b)
  1. Threads enables multi processing.

c)
  1. Multi threading reduces idle time of CPU

d)
  1. All

184.
  1. A thread can acquire a lock by using which reserved keyword?


a)
  1. volatile

b)
  1. synchronized

c)
  1. locked

d)

none

185.
  1. How many threads can a process contain?


a)

1

b)

2

c)

multiple

d)

none

186.
  1. What is sometimes also called a lightweight process?


a)
  1. Thread

b)
  1. Process

c)

JVM

d)

Method

187.
  1. What are valid points about thread


a)
  1. Thread are subdivision of Process.

b)
  1. One or more Threads runs in the context of process.

c)
  1. Threads can execute any part of process. And same part of process can be executed by multiple Threads.

d)
  1. All

188.
  1. What are valid point about processes


a)
  1. Processes have their own copy of the data segment of the parent process

b)
  1. Threads have direct access to the data segment of its process

c)
  1. Processes have their own address

d)
  1. All of these

189.
  1. Which is thread safe?

a)
  1. StringBuffer

b)
  1. StringBuilder

c)

All

d)

None

190.
  1. How can we create Thread?

a)
  1. By Extending Thread class

b)
  1. Implementing Runnable interface

c)
  1. By using Executor framework - which can internally form threads

d)

All

191.
  1. Which of these is not a Thread state?


a)
  1. New

b)
  1. Runnable

c)
  1. sleep

d)
  1. terminated

192.
  1. synchronized instance methods acquire lock on?


a)
  1. object

b)
  1. class

c)

All

d)

None

193.
  1. What state does Thread enter in when it has been created and started?


a)
  1. New

b)
  1. Runnable

c)
  1. Running

d)
  1. Waiting

194.
  1. Which method can be used to find whether Thread hasn't entered dead state?


a)
  1. isAlive()

b)
  1. isRunning()

c)
  1. isNotDead

d)

All

195.
  1. What is valid about threads?

a)
  1. Threads have their own heap allocated area.

b)
  1. Threads have their own stack.

c)
  1. Threads doesn't have own stack.

d)
  1. None

196.
  1. How can you ensure all threads that started from main must end in order in which they started and also main should end in last?


a)
  1. join() method

b)
  1. sleep() method

c)
  1. wait() method

d)
  1. run() method

197.
  1. Which of these is valid about threads in java?


a)
  1. Thread behaviour is unpredictable

b)
  1. execution of Threads depends on Thread scheduler

c)
  1. Same threading program may produce different output in subsequent executions even on same platform

d)
  1. All

198.
  1. Which method restarts the thread?

a)
  1. start()

b)
  1. restart()

c)
  1. restartThread()

d)

none

199.
  1. What is true about acquiring object lock before calling wait(), notify() and notifyAll()?


a)
  1. it’s mandatory to acquire object lock before calling wait(), notify() and notifyAll() methods on object

b)
  1. f we call wait(), notify() and notifyAll() methods without acquiring object lock i.e. from outside synchronize block then java.lang.IllegalMonitorStateException is thrown at runtime.

c)
  1. wait(), notify() and notifyAll() methods are always called from Synchronized block only

d)

all

200.
  1. What is difference between starting thread with run() and start() method?


a)
  1. There is no difference

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

c)
  1. run() calls start() method internally

d)

none

201.
  1. What are valid statements for suspend() and resume() method?


a)
  1. Suspend() method is deadlock prone.

b)
  1. If the target thread holds a lock on object when it is suspended, no thread can lock this object until the target thread is resumed.

c)
  1. If the thread that would resume the target thread attempts to lock this monitor prior to calling resume, it results in deadlock formation.

d)

all

202.
  1. How can Thread go from waiting to runnable state?


a)
  1. notify/notifAll

b)
  1. When sleep time is up

c)
  1. Using resume() method when thread was suspended

d)

all

Similar Resources on Wayground