Font size
WorksheetsJUNIT & MULTI THREADING
Total questions: 202
Worksheet time: 2hrs 20mins
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.
Which of the following class contains methods to collect the results of executing a test case?
A - Assert
B - TestCase
C - TestResult
D - TestSuite
Is it necessary to write the test case for every logic?
Yes
No
If the JUnit method's return type is 'string', what will happen?
the execution will Pass
the execution will fail.
the execution will Not Excute
syntax error
Is it necessary to write the test class to test every class?
Yes
NO
Which method is used to verify the actual and expected results in Junits?
equals()
isEqual()
==
assert()
JUnits are used for which type of testing?
Blackbox Testing
Unit Testing
System Testing
Integration Testing
Assert contains a set of assert methods.
A - true
B - false
Automated Test cases are executed by using automation tool so less tester are required in automation testing.
A - true
B - false
what is integration testing??
Testing the each module individually
Tetsing two or more modules after combining
Is there any direct way to test "Private Method"?
Yes
No
Is JUnit only report the first failure in a single test ?
Yes
No
What is the most basic type of developer level test?
Integration Test
Universal Test
Unit Test
Basic Test
Which of the following is not a desirable quality of "a unit test"?
Tests one property at one time
Fast
I/O or File Operations
Covering a small portion of code
What is the significance of writing a failing test?
We should not. We should focus on writing a test that passes
A failing test shows that some code change is required in our program. If it is not failing, no change required.
A failing test shows that the previous developer didn't do a good job.
A failing test gives you an opportunity to enhance code coverage
What is a test?
A measure to check if the code meets the defined specifications
A measure to check if the code is visually beautiful
A measure to check if the code contains security vulnerabilities?
A measure to increase code coverage
I need to test if a service method is fine or not. What type of test do I need to write?
Unit Test
Integration Test
Selenium Test
Black Box Test
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.
Which of the following class contains methods to collect the results of executing a test case?
A - Assert
B - TestCase
C - TestResult
D - TestSuite
Which of the following annotation causes that method run once after all tests have finished?
A - @Test
B - @After
C - @BeforeClass
D - @AfterClass
Which of the following method of Assert class checks that an object is null?
A - void assert(Object object, boolean toCheckAsNull)
B - void assertCheck(Object object, boolean toCheckAsNull)
C - void assertNull(Object object)
D - void assertChecks(Object object, boolean toCheckAsNull)
Which of the following method of TestResult class gets the number of detected failures?
A - int error()
B - int errorCount()
C - int failureCount()
D - int failure()
@RunWith and @Suite annotation are used to run the suite test.
A - false
B - true
Automated Test cases are executed by using automation tool so less tester are required in automation testing.
A - true
B - false
Assert contains a set of assert methods.
A - true
B - false
Which of the following method of Assert class checks that a condition is true?
A. void assert(boolean condition)
B. void assertTrue(boolean condition)correct
C. void assertCheck(boolean condition)
D. void assertChecks(boolean condition)
Which of the following method of TestSuite class adds the tests from the given class to the suite?
A. void addTest(Class testClass)wrong
B. void addTestSuite(Class testClass)correct
C. void addTest(TestCase testClass)
D. void addTestCase(TestCase testClass)
JUnits are used for which type of testing?
Blackbox Testing
Unit Testing
System Testing
Integration Testing
Which of the below is an incorrect annotation with respect to JUnits?
@Junit
@AfterEach
@Test
@BeforeClass
Which method is used to verify the actual and expected results in Junits?
equals()
isEqual()
==
assert()
What does assertSame() method use for assertion?
equals() method
isEqual() method
==
compare() method
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.
Which of the following class contains methods to collect the results of executing a test case?
A - Assert
B - TestCase
C - TestResult
D - TestSuite
Which of the following annotation causes that method run once after all tests have finished?
A - @Test
B - @After
C - @BeforeClass
D - @AfterClass
Which of the following method of Assert class checks that an object is null?
A - void assert(Object object, boolean toCheckAsNull)
B - void assertCheck(Object object, boolean toCheckAsNull)
C - void assertNull(Object object)
D - void assertChecks(Object object, boolean toCheckAsNull)
@RunWith and @Suite annotation are used to run the suite test.
A - false
B - true
Automated Test cases are executed by using automation tool so less tester are required in automation testing.
A - true
B - false
Assert contains a set of assert methods.
A - true
B - false
Which of the following method of Assert class checks that a condition is true?
A. void assert(boolean condition)
B. void assertTrue(boolean condition)correct
C. void assertCheck(boolean condition)
D. void assertChecks(boolean condition)
Which of the following method of TestSuite class adds the tests from the given class to the suite?
A. void addTest(Class testClass)wrong
B. void addTestSuite(Class testClass)correct
C. void addTest(TestCase testClass)
D. void addTestCase(TestCase testClass)
JUnits are used for which type of testing?
Blackbox Testing
Unit Testing
System Testing
Integration Testing
Which of the below is an incorrect annotation with respect to JUnits?
@Junit
@AfterEach
@Test
@BeforeClass
Which method is used to verify the actual and expected results in Junits?
equals()
isEqual()
==
assert()
What does assertSame() method use for assertion?
equals() method
isEqual() method
==
compare() method
What is the use of Junit
To increase code coverage
To test unit of code thoroughly
To integrate with other units of code
Is it necessary to write the test case for every logic?
Yes
No
Is there any direct way to test "Private Method"?
Yes
No
Is JUnit only report the first failure in a single test ?
Yes
No
What is the most basic type of developer level test?
Integration Test
Universal Test
Unit Test
Basic Test
which of the following are framework of testings (testing frameworks)
JUNIT
JUNIT and WordPress
Selenium
Selenium and REST
Assert.assertEquals(calculadoraSimple.suma("1", "2"), 5);
Assert OK
Assert Failure
Assert Exception
Assert.assertEquals(calculadoraSimple.suma(null, "2"), 5);
Assert OK
Assert Failure
Assert Exception
Assert.assertNotEquals(calculadoraSimple.suma("5", "2"), 3);
Assert OK
Assert Failure
Assert Exception
@Test(expected = RuntimeException.class)
...
Assert.assertEquals(calculadora.suma(null, "2"), 3);
Assert OK
Assert Failure
Assert Exception
MAVEN needs
web.xml
manifest.yml
pom.xml
all of them
JUnit is used for what type of software testing for the Java language?
Functional Testing
System Testing
Unit Testing
Integration Testing
Which annotation implies that a method is a JUnit test case?
@org.junit.Test
@org.Test
@testcase
@junit
JUnit test files are written in files with which file extension?
.unit
.java
.test
.junit
Which methods cannot be tested by the JUnit test class?
protected methods
methods with void return type
private methods
public methods
JUnit test methods must compulsorily return what value?
void
Object
String
int
To use JUnit in a project we need to add which JAR files on our test classpath?
java-junit.jar
junit.jar and hamcrest-core.jar
hamcrest-core.jar
junit.jar
Which of the following method of Assert class checks that a condition is false?
void assert(boolean condition)
void assertFalse(boolean condition)
void assertCheck(boolean condition)
void assertChecks(boolean condition)
Which of the following class is used to bundle unit test cases and run them together?
JUnitCore
TestCase
TestSuite
TestResult
Which of the following describes Testing correctly?
Testing is the process of checking the functionality of the application whether it is working as per requirements.
Testing is the testing of single entity (class or method).
Both of the above.
None of the above.
Which of the following method of Assert class checks that a condition is true?
void assert(boolean condition)
void assertTrue(boolean condition)
void assertCheck(boolean condition)
void assertChecks(boolean condition)
Execution of a java thread begins on which method call?
Run ()
Start ()
Execute ()
Launch ()
How many ways a thread can be created in Java multithreading?
1
2
5
10
Which method is used to make main thread to wait for all child threads
Join ()
Sleep ()
Wait ()
Stop ()
Which will contain the body of the thread in Java?
Start()
Run()
Main()
Execute()
The life cycle of a thread in java is controlled by
JRE
JDK
JVM
None
Which method is used to get current running thread object?
runningThread()
currentThread()
runnableThread()
None
Synchronized static methods acquire lock on
Class
Object
Interface
None
Thread priority in Java is?
Integer
Float
Double
Long
In JAVA multi threading, a thread can be created by_______
Extending class
Implementing Runnable Interface
both
none
Which statements is/are correct
On calling Thread start ( ) method a new thread is created
Thread start( ) method call run( ) method internally
Thread run( ) method can also be called directly to create thread
both a & b
Q) What is maximum thread priority in Java
10
12
5
8
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();
}
}
0
1
2
3
Q) Execution of a java thread begins on which method call?
Start ()
Run ()
Execute ()
Launch ()
Q) Which method is used to check if a thread is running?
isAlive()
run ()
alive ()
keepAlive()
Q) Min and Max priority of a thread in Java multithreading are
1, 10
0,10
0,255
1,256
Data________ focus on distributing subsets of the same data across multiple computing cores and perform the same operation on each core
sequencing
synchronization
parallelism
kernel threads
___________distributing task across multiple computing cores
data parallelism
implicit threading
task parallelism
identifying task
Daemon thread runs in
BackGround
Foreground
Both
none
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();
}
}
main
main
Thread-0
Thread-0
main
Thread-1
main
Thread-0
Thread-1
Thread-0
Thread-1
Thread-2
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) This program will throw an IllegalStateException.
b) This program will always print the following: Tennis Tennis Table Table.
c) This program will always print the following: Table Table Tennis Tennis.
d) The output of this program cannot be predicted; it depends on thread scheduling.
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) When executed, the program prints the following: “Worker Master ”.
b) When executed, the program prints “Worker ”, and after that the program hangs (i.e., does not terminate).
c) When executed, the program prints “Worker ” and then terminates.
d) When executed, the program throws IllegalMonitorStateException.
e) The program does not compile and fails with multiple compiler errors.
What code is missing?
public class MyRunnable implements Runnable
{
public void run()
{
// some code here
}
}
new Thread(MyRunnable).run();
new Runnable(MyRunnable).start();
new Thread(new MyRunnable()).start();
new MyRunnable().start();
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? */
}
}
Demo obj = new Demo();
Thread tobj = new Thread(obj);
tobj.start();
Thread t = new Thread(X);
t.start();
Thread t = new Thread(Demo);
Thread t = new Thread();
Demo.run();
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 ");
}
}
An exception occurs at runtime.
Compilation fails.
. It prints "Thread one. Thread two.".
The output cannot be determined.
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. run-test run-test
B. run-test
C. Compilation fails due to an error on line 4
D. Compilation fails due to an error on line 7
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();
}
}
Compilation succeed but Runtime Exception
A B A B A B A B
Output order is not guaranteed
A A A A B B B B
How many ways a thread can be created in Java multithreading?
1
2
5
10
Which will contain the body of the thread in Java?
Start()
Run()
Main()
Execute()
The life cycle of a thread in java is controlled by
JRE
JDK
JVM
None
Which method is used to get current running thread object?
runningThread()
currentThread()
runnableThread()
None
In JAVA multi threading, a thread can be created by_______
Extending class
Implementing Runnable Interface
both
none
Q) What is maximum thread priority in Java
10
12
5
8
Q) Execution of a java thread begins on which method call?
Start ()
Run ()
Execute ()
Launch ()
Thread is _____________process that can run independently
heavyweight
lightweight
compaction
compression
What is multithreaded programming
It’s a process in which two different processes run simultaneously
It’s a process in which two or more parts of same process run simultaneously
It’s a process in which many different process are able to access same information
It’s a process in which a single process can access information from many sources
Which of these are types of multitasking?
Process based
Thread based
Process and Thread based
None of the mentioned
Q) How many ways a thread can be created in Java multithreading?
1
2
3
4
Q) Default value of a java thread is
0
1
5
10
Q) If a priority of a java thread is 3 then the default priority of its child thread will be
0
1
5
3
Threads are belongs to the following package
import java.lang.*
import java.util.*
import java.io.*
import java.Thread.*
Choose THREE(3) benefits of multithreaded processing
scalability
resource sharing
privacy
responsiveness
The order of execution if threads is managed by:
Java Compiler
Default Scheduler
Thread Manager
Thread Scheduler
1. The capability to control the access of multiple threads to any shared resource is called_____________
Synchronization
Multitasking
multithreading
None
What are the approaches under mutual exclusion?
Synchronized method
Synchronized block
Static synchronization
All the above
wait(), notify() and notifyAll() belongs to which class?
Thread
Object
FileInputStream
Exception
How many ways a thread can be created in Java multithreading?
1
2
5
10
Which method is used to make main thread to wait for all child threads
Join ()
Sleep ()
Wait ()
Stop ()
Which will contain the body of the thread in Java?
Start()
Run()
Main()
Execute()
The life cycle of a thread in java is controlled by
JRE
JDK
JVM
None
Which method is used to get current running thread object?
runningThread()
currentThread()
runnableThread()
None
Synchronized static methods acquire lock on
Class
Object
Interface
None
Thread priority in Java is?
Integer
Float
Double
Long
In JAVA multi threading, a thread can be created by_______
Extending class
Implementing Runnable Interface
both
none
Which statements is/are correct
On calling Thread start ( ) method a new thread is created
Thread start( ) method call run( ) method internally
Thread run( ) method can also be called directly to create thread
both a & b
Q) What is maximum thread priority in Java
10
12
5
8
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();
}
}
0
1
2
3
Q) Execution of a java thread begins on which method call?
Start ()
Run ()
Execute ()
Launch ()
Q) Which method is used to check if a thread is running?
isAlive()
run ()
alive ()
keepAlive()
Q) Min and Max priority of a thread in Java multithreading are
1, 10
0,10
0,255
1,256
___________distributing task across multiple computing cores
data parallelism
implicit threading
task parallelism
identifying task
Execution of a java thread begins on which method call?
Run ()
Start ()
Execute ()
Launch ()
Choose THREE(3) benefits of multithreaded processing
scalability
resource sharing
privacy
responsiveness
Thread is _____________process that can run independently
heavyweight
lightweight
compaction
compression
java.lang.RuntimeException: Problem
run.
java.lang.RuntimeException: Problem
End of method.
java.lang.RuntimeException: Problem
End of method.
run.
java.lang.RuntimeException: Problem
run.
java.lang.RuntimeException: Problem
End of method.
The code will deadlock.
The code may run with no output.
An exception is thrown at runtime.
The code may run with output "0 6".
The code may run with output "0 2 4 6".
synchronize the log method
replace StringBuilder with StringBuffer
replace StringBuilder with just a String object and use the string concatenation (+=) within the log method
No change is necessary, the current MyLogger code is already thread-safe.
"done "
"finally "
"done finally "
Compilation fails.
No output is produced.
Which are true? (Choose all that apply.)
A. Compilation fails.
The program’s minimum execution time is about 8 seconds.
The program’s minimum execution time is about 9 seconds.
The program’s minimum execution time is about 12 seconds.
The program’s minimum execution time is about 16 seconds.
Which method can be used to find whether lock is held by current thread?
findLockHold()
isLockHeld()
holdsLock()
lockHold()
Bang will execute for a second or two.
Bang will execute for at least 10 minutes.
Thread t1 will almost certainly be the last thread to finish.
Thread t1 will almost certainly be the first thread to finish.
It’s difficult to predict which thread will be the last to finish.
i L
i N
S L
S N
Compilation fails.
What is the result? (Choose all that apply.)
5
7
Compilation fails due to an error on line 8.
Compilation fails due to an error on line 9.
Compilation fails due to an error on line 13.
0
01
02
03
1. The capability to control the access of multiple threads to any shared resource is called_____________
Synchronization
Multitasking
multithreading
None
_______________ and __________________ are the types of synchronization.
Process synchronization and thread synchronization
multitasking and multithreading
Interthread communication and mutual exclusion
None
What are the approaches under mutual exclusion?
Synchronized method
Synchronized block
Static synchronization
All the above
Identify the correct mutual exclusion approach:
synchronized(this)
{
….
….
}
Synchronized method
Synchronized block
Static Synchronization
None
_____________tells calling thread to give up monitor and go to sleep until some other thread enters the same monitor and call notify.
wait()
notify()
notifyAll()
start()
______________wakes up a thread that called wait() on same object.
start()
run()
notify()
sleep()
Which is the static method?
wait()
sleep()
Both
None
wait(), notify() and notifyAll() belongs to which class?
Thread
Object
FileInputStream
Exception
Daemon thread is a _________priority thread.
low
high
Normal
None
_______________is the return type of isDaemon()
String
int
boolean
float
sleep() method belongs to which class?
Object
Thread
Exception
InputStream
How many ways a thread can be created in Java multithreading?
1
2
5
10
Which will contain the body of the thread in Java?
Start()
Run()
Main()
Execute()
Which method is used to get current running thread object?
runningThread()
currentThread()
runnableThread()
None
Thread priority in Java is?
Integer
Float
Double
Long
In JAVA multi threading, a thread can be created by_______
Extending class
Implementing Runnable Interface
both
none
Q) What is maximum thread priority in Java
10
12
5
8
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();
}
}
0
1
2
3
What will happen if two thread of the same priority are called to be processed simultaneously?
Anyone will be executed first lexographically
Both of them will be executed simultaneously
None of them will be executed
It is dependent on the operating system
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);
} }
4
5
0
1
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");
}
}
Run
Main
Compile Time Error
Run Main
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(); }
}
My Thread
Thread[My Thread,5,main]
Compilation Error
Runtime Error
Which of this method is used to find out that a thread is still running or not?
a) run()
b) Alive()
c) isAlive()
d) checkRun()
Execution of a java thread begins on which method call?
Run ()
Start ()
Execute ()
Launch ()
Daemon thread runs in
BackGround
Foreground
Both
none
What is true about threads?
Threads consumes CPU in best possible manner
Threads enables multi processing.
Multi threading reduces idle time of CPU
All
A thread can acquire a lock by using which reserved keyword?
volatile
synchronized
locked
none
How many threads can a process contain?
1
2
multiple
none
What is sometimes also called a lightweight process?
Thread
Process
JVM
Method
What are valid points about thread
Thread are subdivision of Process.
One or more Threads runs in the context of process.
Threads can execute any part of process. And same part of process can be executed by multiple Threads.
All
What are valid point about processes
Processes have their own copy of the data segment of the parent process
Threads have direct access to the data segment of its process
Processes have their own address
All of these
Which is thread safe?
StringBuffer
StringBuilder
All
None
How can we create Thread?
By Extending Thread class
Implementing Runnable interface
By using Executor framework - which can internally form threads
All
Which of these is not a Thread state?
New
Runnable
sleep
terminated
synchronized instance methods acquire lock on?
object
class
All
None
What state does Thread enter in when it has been created and started?
New
Runnable
Running
Waiting
Which method can be used to find whether Thread hasn't entered dead state?
isAlive()
isRunning()
isNotDead
All
What is valid about threads?
Threads have their own heap allocated area.
Threads have their own stack.
Threads doesn't have own stack.
None
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?
join() method
sleep() method
wait() method
run() method
Which of these is valid about threads in java?
Thread behaviour is unpredictable
execution of Threads depends on Thread scheduler
Same threading program may produce different output in subsequent executions even on same platform
All
Which method restarts the thread?
start()
restart()
restartThread()
none
What is true about acquiring object lock before calling wait(), notify() and notifyAll()?
it’s mandatory to acquire object lock before calling wait(), notify() and notifyAll() methods on object
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.
wait(), notify() and notifyAll() methods are always called from Synchronized block only
all
What is difference between starting thread with run() and start() method?
There is no difference
When you call start() method, main thread internally calls run() method to start newly created Thread
run() calls start() method internally
none
What are valid statements for suspend() and resume() method?
Suspend() method is deadlock prone.
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.
If the thread that would resume the target thread attempts to lock this monitor prior to calling resume, it results in deadlock formation.
all
How can Thread go from waiting to runnable state?
notify/notifAll
When sleep time is up
Using resume() method when thread was suspended
all
