JAVA-Multithreading
Thread priority in Java is? a) Integer b) Float c) double d) long
a
What is synchronization in reference to a thread? a) It's a process of handling situations when two or more threads need access to a shared resource. b) Its a process by which many thread are able to access same shared resource simultaneously. c) Its a process by which a method is able to access many different threads simultaneously. d) Its a method that allow to many threads to access any information require.
a
What is synchronization in reference to a thread? a) Its a process of handling situations when two or more threads need access to a shared resource. b) Its a process by which many thread are able to access same shared resource simultaneously. c) Its a process by which a method is able to access many different threads simultaneously. d) Its a method that allow to many threads to access any information the require.
a
What is the name of the thread in output of this program? class multithreaded_programing { public static void main(String args[]) { Thread t = Thread.currentThread(); System.out.println(t); } a) main b) Thread c) System d) None of the mentioned
a
What is the name of the thread in output of this program? class multithreaded_programing { public static void main(String args[]) { Thread t = Thread.currentThread(); System.out.println(t.isAlive()); } } a) 0 b) 1 c) true d) false
a
What is the output of this program? 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
a
What is the output of this program? class exception_handling { public static void main(String args[]) { try { int a = 1; int b = 10 / a; try { if (a == 1) a = a / a - a; if (a == 2) { int c[] = {1}; c[8] = 9; } } finally { System.out.print("A"); } } catch (Exception e) { System.out.println("B"); } } } a) A b) B c) AB d) BA
a
Which function of pre defined class Thread is used to check weather current thread being checked is still running? a) isAlive() b) Join() c) isRunning() d) Alive()
a
Which of these exceptions handles the divide by zero error? a) ArithmeticException b) MathException c) IllegalAccessException d) IllegarException
a
Which of these interface is implemented by Thread class? a) Runnable b) Connections c) Set d) MapConnections
a
Which of these is a protocol for breaking and sending packets to an address across a network? a) TCIP/IP b) DNS c) Socket d) Proxy Server
a
Which of these method is used to tell the calling thread to give up monitor and go to sleep until some other thread enters the same monitor? a) wait() b) notify() c) notifyAll() d) sleep()
a
Which of these method of Thread class is used to Suspend a thread for a period of time? a) sleep() b) terminate() c) suspend() d) stop()
a
How many ports of TCP/IP are reserved for specific protocols? a) 10 b) 1024 c) 2048 d) 512
b
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) Its a process in which many different process are able to access same information. d) Its a process in which a single process can access information from many sources.
b
What is the output of this program? class exception_handling { public static void main(String args[]) { try { int a = args.length; int b = 10 / a; System.out.print(a); } catch (ArithmeticException e) { System.out.println("1"); } } } a) 0 b) 1 c) Compilation Error d) Runtime Error
b
What is the output of this program? class newthread extends Thread { Thread t; String name; newthread(String threadname) { name = threadname; t = new Thread(this,name); t.start(); } public void run() { } } class multithreaded_programing { public static void main(String args[]) { newthread obj1 = new newthread("one"); newthread obj2 = new newthread("two"); try { System.out.print(obj1.t.equals(obj2.t)); } catch(Exception e) { System.out.print("Main thread interrupted"); } } } a) true b) false c) Main thread interrupted d) None of the mentioned
b
What is the output of this program? class newthread extends Thread { Thread t; String name; newthread(String threadname) { name = threadname; t = new Thread(this,name); t.start(); } public void run() { } } class multithreaded_programing { public static void main(String args[]) { newthread obj1 = new newthread("one"); newthread obj2 = new newthread("two"); try { Thread.sleep(1000); System.out.print(obj1.t.isAlive()); } catch(InterruptedException e) { System.out.print("Main thread interrupted"); } } } a) true b) false c) Main thread interrupted d) None of the mentioned
b
What is the output of this program? class newthread extends Thread { newthread() { super("My Thread"); start(); } public void run() { System.out.println(this); } } 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
b
What is the output of this program? class newthread implements Runnable { Thread t; newthread() { t = new Thread(this,"My Thread"); t.start(); } public void run() { System.out.println(t); } } 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
b
What is the output of this program? import java.net.*; class networking { public static void main(String[] args) throws UnknownHostException { InetAddress obj1 = InetAddress.getByName("cisco.com"); System.out.print(obj1.getHostName()); } } a) cisco b) cisco.com c) www.cisco.com d) None of the mentioned
b
What is the priority of the thread in output of this 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
b
Which of these clause will be executed even if no exceptions are found? a) throws b) finally c) throw d) catch
b
Which of these method can be used to make the main thread to be executed last among all the threads? a) stop() b) sleep() c) join() d) call()
b
Which of these method is used to begin the execution of a thread? a) run() b) start() c) runThread() d) startThread()
b
Which of these method is used to implement Runnable interface? a) stop() b) run() c) runThread() d) stopThread()
b
Which of these method wakes up the first thread that called wait()? a) wake() b) notify() c) start() d) notifyAll()
b
A single try block must be followed by which of these? a) finally b) catch c) finally & catch d) None of the mentioned
c
How many bits are in a single IP address? a) 8 b) 16 c) 32 d) 64
c
What is the default value of priority variable MIN_PRIORITY AND MAX_PRIORITY? a) 0 & 256 b) 0 & 1 c) 1 & 10 d) 1 & 256
c
What is the name of the thread in output of this program? class multithreaded_programing { public static void main(String args[]) { Thread t = Thread.currentThread(); System.out.println(t.isAlive()); } } a) 0 b) 1 c) true d) false
c
What is the output of this program? class exception_handling { public static void main(String args[]) { try { int a = args.length; int b = 10 / a; System.out.print(a); try { if (a == 1) a = a / a - a; if (a == 2) { int c = {1}; c[8] = 9; } } catch (ArrayIndexOutOfBoundException e) { System.out.println("TypeA"); } catch (ArithmeticException e) { System.out.println("TypeB"); } } } a) TypeA b) TypeB c) Compilation Error d) Runtime Error
c
What is the output of this program? class exception_handling { static void throwexception() throws ArithmeticException { System.out.print("0"); throw new ArithmeticException ("Exception"); } public static void main(String args[]) { try { throwexception(); } catch (ArithmeticException e) { System.out.println("A"); } } } a) A b) 0 c) 0A d) Exception
c
What is the output of this program? class newthread extends Thread { Thread t; String name; newthread(String threadname) { name = threadname; t = new Thread(this,name); t.start(); } public void run() { } } class multithreaded_programing { public static void main(String args[]) { newthread obj1 = new newthread("one"); newthread obj2 = new newthread("two"); try { obj1.t.wait(); System.out.print(obj1.t.isAlive()); } catch(Exception e) { System.out.print("Main thread interrupted"); } } } a) true b) false c) Main thread interrupted d) None of the mentioned
c
What is the output of this program? class newthread extends Thread { Thread t; newthread() { t = new Thread(this,"New Thread"); t.start(); } public void run() { System.out.println(t.isAlive()); } } class multithreaded_programing { public static void main(String args[]) { new newthread(); } } a) 0 b) 1 c) true d) false
c
What is the output of this program? class newthread implements Runnable { Thread t; newthread() { t = new Thread(this,"My Thread"); t.start(); } } 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
c
What is the output of this program? import java.net.*; class networking { public static void main(String[] args) throws UnknownHostException { InetAddress obj1 = InetAddress.getByName("sanfoundary.com"); InetAddress obj2 = InetAddress.getByName("sanfoundary.com"); boolean x = obj1.equals(obj2); System.out.print(x); } } a) 0 b) 1 c) true d) false
c
What is the priority of the thread in output of this program? class multithreaded_programing { public static void main(String args[]) { Thread t = Thread.currentThread(); t.setName("New Thread"); System.out.println(t.getName()); } } a) main b) Thread c) New Thread d) Thread[New Thread,5,main]
c
Which of these are types of multitasking? a) Process based b) Thread based c) Process and Thread based d) None of the mentioned
c
Which of these class is used to encapsulate IP address and DNS? a) DatagramPacket b) URL c) InetAddress d) ContentHandler
c
Which of these class is used to make a thread? a) String b) System c) Thread d) Runnable
c
Which of these method is used to explicitly set the priority of a thread? a) set() b) make() c) setPriority() d) makePriority()
c
Which of these method is used to find out that a thread is still running or not? a) run() b) Alive() c) isAlive() d) checkRun()
c
Which of these method of Thread class is used to find out the priority given to a thread? a) get() b) ThreadPriority() c) getPriority() d) getThreadPriority()
c
Which of these method waits for the thread to treminate? a) sleep() b) isAlive() c) join() d) stop()
c
Which of these package contains classes and interfaces for networking? a) java.io b) java.util c) java.net d) java.network
c
Which of these packages contain all the Java's built in exceptions? a) java.io b) java.util c) java.lang d) java.net
c
What is the name of the thread in output of this program? class multithreaded_programing { public static void main(String args[]) { Thread t = Thread.currentThread(); System.out.println(t.getPriority()); } } a) 0 b) 1 c) 4 d) 5
d
What is the output of this program? class exception_handling { public static void main(String args[]) { try { throw new NullPointerException ("Hello"); System.out.print("A"); } catch(ArithmeticException e) { System.out.print("B"); } } } a) A b) B c) Compilation Error d) Runtime Error
d
What is the output of this program? class multithreaded_programing { public static void main(String args[]) { Thread t = Thread.currentThread(); System.out.println(t); } } a) Thread[5,main] b) Thread[main,5] c) Thread[main,0] d) Thread[main,5,main]
d
What is the output of this program? class multithreaded_programing { public static void main(String args[]) { Thread t = Thread.currentThread(); t.setName("New Thread"); System.out.println(t); } } a) Thread[5,main] b) Thread[New Thread,5] c) Thread[main,5,main] d) Thread[New Thread,5,main]
d
What is the output of this program? class newthread extends Thread { Thread t1,t2; newthread() { t1 = new Thread(this,"Thread_1"); t2 = new Thread(this,"Thread_2"); t1.start(); t2.start(); } public void run() { t2.setPriority(Thread.MAX_PRIORITY); System.out.print(t1.equals(t2)); } } class multithreaded_programing { public static void main(String args[]) { new newthread(); } } a) true b) false c) truetrue d) falsefalse
d
What is the output of this program? class newthread extends Thread { Thread t; newthread() { t = new Thread(this,"My Thread"); t.start(); } public void run() { try { t.join() System.out.println(t.getName()); } catch(Exception e) { System.out.print("Exception"); } } } class multithreaded_programing { public static void main(String args[]) { new newthread(); } } a) My Thread b) Thread[My Thread,5,main] c) Exception d) Runtime Error
d
What is the output of this program? class newthread extends Thread { Thread t; newthread() { t1 = new Thread(this,"Thread_1"); t2 = new Thread(this,"Thread_2"); t1.start(); t2.start(); } public void run() { t2.setPriority(Thread.MAX_PRIORITY); System.out.print(t1.equals(t2)); } } class multithreaded_programing { public static void main(String args[]) { new newthread(); } } a) true b) false c) truetrue d) falsefalse
d
What is the output of this program? class newthread implements Runnable { Thread t; newthread() { t = new Thread(this,"New Thread"); t.start(); } public void run() { t.setPriority(Thread.MAX_PRIORITY); System.out.println(t); } } class multithreaded_programing { public static void main(String args[]) { new newthread(); } } a) Thread[New Thread,0,main] b) Thread[New Thread,1,main] c) Thread[New Thread,5,main] d) Thread[New Thread,10,main]
d
What is the output of this program? class newthread implements Runnable { Thread t; newthread() { t1 = new Thread(this,"Thread_1"); t2 = new Thread(this,"Thread_2"); t1.start(); t2.start(); } public void run() { t2.setPriority(Thread.MAX_PRIORITY); System.out.print(t1.equals(t2)); } } class multithreaded_programing { public static void main(String args[]) { new newthread(); } } a) true b) false c) truetrue d) falsefalse
d
What is the output of this program? import java.net.*; class networking { public static void main(String[] args) throws UnknownHostException { InetAddress obj1 = InetAddress.getByName("cisco.com"); InetAddress obj2 = InetAddress.getByName("sanfoundary.com"); boolean x = obj1.equals(obj2); System.out.print(x); } } a) 0 b) 1 c) true d) false
d
What will happen if two thread of same priority are called to be processed simultaneously? a) Any one 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.
d
Which of these exceptions will occur if we try to access the index of an array beyond its length? a) ArithmeticException b) ArrayException c) ArrayIndexException d) ArrayIndexOutOfBoundsException
d
Which of these is a full form of DNS? a) Data Network Service b) Data Name Service c) Domain Network Service d) Domian Name Service
d
Which of these keywords are used to implement synchronization? a) sunchronize b) syn c) synch d) synchronized
d
Which of these method is used to avoid polling in Java? a) wait() b) notify() c) notifyAll() d) All of the mentioned
d
Which of these method wakes up all the threads? a) wakeAll() b) notify() c) start() d) notifyAll()
d
Which of these statement is incorrect? a) A thread can be formed by implementing Runnable interface only. b) A thread can be formed by a class that extends Thread class. c) start() method is used to begin execution of the thread. d) run() method is used to begin execution of a thread before start() method in special cases.
d
Which of these statements is incorrect? a) By multithreading CPU's idle time is minimized, and we can take maximum use of it. b) By multitasking CPU's idle time is minimized, and we can take maximum use of it. c) Two thread in Java can have same priority d) A thread can exist only in two states, running and blocked.
d
hat is the output of this program? import java.io.*; class streams { public static void main(String[] args) { try { FileOutputStream fos = new FileOutputStream("serial"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeFloat(3.5); oos.flush(); oos.close(); } catch(Exception e) { System.out.println("Serialization" + e); System.exit(0); } try { FileInputStream fis = new FileInputStream("serial"); ObjectInputStream ois = new ObjectInputStream(fis); ois.close(); System.out.println(ois.available()); } catch (Exception e) { System.out.print("deserialization"); System.exit(0); } } } a) 1 b) 2 c) 3 d) 4
d