- Which of the following is true about threads in Java?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 class Eduinq extends Thread { 2 public void run() { 3 System.out.println("Eduinq Thread Running"); 4 } 5 } 6 public class Test { 7 public static void main(String[] args) { 8 new Eduinq().start(); 9 } 10 } View Answer
Correct answer: A — Eduinq Thread Running
- Which of the following is true about Runnable?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 class Eduinq implements Runnable { 2 public void run() { 3 System.out.println("Eduinq Runnable Running"); 4 } 5 } 6 public class Test { 7 public static void main(String[] args) { 8 Thread t = new Thread(new Eduinq()); 9 t.start(); 10 } 11 } View Answer
Correct answer: A — Eduinq Runnable Running
- Which of the following is true about thread states?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 public class Test { 2 public static void main(String[] args) throws InterruptedException { 3 Thread t = new Thread(() -> System.out.println("Eduinq Thread")); 4 t.start(); 5 t.join(); 6 System.out.println("Main Done"); 7 } 8 } View Answer
Correct answer: A — Eduinq Thread followed by Main Done
- Which of the following is true about synchronization?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 class Eduinq { 2 synchronized void printEduinq() { 3 System.out.println("Eduinq Synchronized"); 4 } 5 } 6 public class Test { 7 public static void main(String[] args) { 8 Eduinq e = new Eduinq(); 9 new Thread(() -> e.printEduinq()).start(); 10 } 11 } View Answer
Correct answer: A — Eduinq Synchronized
- Which of the following is true about ReentrantLock?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.util.concurrent.locks.*; 2 class Eduinq { 3 private final Lock lock = new ReentrantLock(); 4 void show() { 5 lock.lock(); 6 try { 7 System.out.println("Eduinq Lock"); 8 } finally { 9 lock.unlock(); 10 } 11 } 12 } 13 public class Test { 14 public static void main(String[] args) { 15 new Eduinq().show(); 16 } 17 } View Answer
Correct answer: A — Eduinq Lock
- Which of the following is true about ExecutorService?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.util.concurrent.*; 2 public class Test { 3 public static void main(String[] args) { 4 ExecutorService service = Executors.newFixedThreadPool(1); 5 service.execute(() -> System.out.println("Eduinq Executor")); 6 service.shutdown(); 7 } 8 } View Answer
Correct answer: A — Eduinq Executor
- Which of the following is true about Future?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.util.concurrent.*; 2 public class Test { 3 public static void main(String[] args) throws Exception { 4 ExecutorService service = Executors.newSingleThreadExecutor(); 5 Future<String> f = service.submit(() -> "Eduinq Future"); 6 System.out.println(f.get()); 7 service.shutdown(); 8 } 9 } View Answer
Correct answer: A — Eduinq Future
- Which of the following is true about AtomicInteger?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.util.concurrent.atomic.*; 2 public class Test { 3 public static void main(String[] args) { 4 AtomicInteger ai = new AtomicInteger(5); 5 ai.incrementAndGet(); 6 System.out.println(ai.get()); 7 } 8 } View Answer
Correct answer: B — 6
- Which of the following is true about CountDownLatch?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.util.concurrent.*; 2 public class Test { 3 public static void main(String[] args) throws Exception { 4 CountDownLatch latch = new CountDownLatch(1); 5 new Thread(() -> { 6 System.out.println("Eduinq Worker"); 7 latch.countDown(); 8 }).start(); 9 latch.await(); 10 System.out.println("Main Done"); 11 } 12 } View Answer
Correct answer: A — Eduinq Worker followed by Main Done
- Which of the following is true about CyclicBarrier?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.util.concurrent.*; 2 public class Test { 3 public static void main(String[] args) throws Exception { 4 CyclicBarrier barrier = new CyclicBarrier(2, () -> System.out.println("Eduinq Barrier Action")); 5 new Thread(() -> { 6 try { barrier.await(); } catch(Exception e) {} 7 }).start(); 8 barrier.await(); 9 } 10 } View Answer
Correct answer: A — Eduinq Barrier Action
- Which of the following is true about Semaphore?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.util.concurrent.*; 2 public class Test { 3 public static void main(String[] args) throws Exception { 4 Semaphore sem = new Semaphore(1); 5 sem.acquire(); 6 System.out.println("Eduinq Semaphore"); 7 sem.release(); 8 } 9 } View Answer
Correct answer: A — Eduinq Semaphore
- Which of the following is true about ThreadLocal?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 public class Test { 2 public static void main(String[] args) { 3 ThreadLocal<String> tl = new ThreadLocal<>(); 4 tl.set("Eduinq Local"); 5 System.out.println(tl.get()); 6 } 7 } View Answer
Correct answer: A — Eduinq Local
- Which of the following is true about volatile keyword?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 class Eduinq { 2 volatile int count = 0; 3 } 4 public class Test { 5 public static void main(String[] args) { 6 Eduinq e = new Eduinq(); 7 e.count++; 8 System.out.println(e.count); 9 } 10 } View Answer
Correct answer: A — 1
- Which of the following is true about synchronized blocks?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 class Eduinq { 2 void show() { 3 synchronized(this) { 4 System.out.println("Eduinq Block Sync"); 5 } 6 } 7 } 8 public class Test { 9 public static void main(String[] args) { 10 new Eduinq().show(); 11 } 12 } View Answer
Correct answer: A — Eduinq Block Sync
- Which of the following is true about ThreadPoolExecutor?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.util.concurrent.*; 2 public class Test { 3 public static void main(String[] args) { 4 ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(2); 5 executor.execute(() -> System.out.println("Eduinq Task")); 6 executor.shutdown(); 7 } 8 } View Answer
Correct answer: A — Eduinq Task
- Which of the following is true about ScheduledExecutorService?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.util.concurrent.*; 2 public class Test { 3 public static void main(String[] args) throws Exception { 4 ScheduledExecutorService service = Executors.newScheduledThreadPool(1); 5 service.schedule(() -> System.out.println("Eduinq Scheduled"), 1, TimeUnit.SECONDS); 6 service.shutdown(); 7 } 8 } View Answer
Correct answer: A — Eduinq Scheduled (after 1 second)
- Which of the following is true about Phaser?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.util.concurrent.*; 2 public class Test { 3 public static void main(String[] args) { 4 Phaser phaser = new Phaser(1); 5 phaser.register(); 6 new Thread(() -> { 7 System.out.println("Eduinq Phase"); 8 phaser.arriveAndDeregister(); 9 }).start(); 10 phaser.arriveAndAwaitAdvance(); 11 System.out.println("Main Done"); 12 } 13 } View Answer
Correct answer: A — Eduinq Phase followed by Main Done
- Which of the following is true about ReadWriteLock?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.util.concurrent.locks.*; 2 public class Test { 3 public static void main(String[] args) { 4 ReadWriteLock rw = new ReentrantReadWriteLock(); 5 rw.readLock().lock(); 6 System.out.println("Eduinq Read Lock"); 7 rw.readLock().unlock(); 8 } 9 } View Answer
Correct answer: A — Eduinq Read Lock
- Which of the following is true about ConcurrentHashMap concurrency level?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.util.concurrent.*; 2 public class Test { 3 public static void main(String[] args) { 4 ConcurrentHashMap<Integer,String> map = new ConcurrentHashMap<>(); 5 map.put(1,"Eduinq"); 6 System.out.println(map.get(1)); 7 } 8 } View Answer
Correct answer: A — Eduinq
- Which of the following is true about BlockingQueue?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.util.concurrent.*; 2 public class Test { 3 public static void main(String[] args) throws Exception { 4 BlockingQueue<String> q = new ArrayBlockingQueue<>(2); 5 q.put("Eduinq"); 6 System.out.println(q.take()); 7 } 8 } View Answer
Correct answer: A — Eduinq
- Which of the following is true about Exchanger?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.util.concurrent.*; 2 public class Test { 3 public static void main(String[] args) throws Exception { 4 Exchanger<String> ex = new Exchanger<>(); 5 new Thread(() -> { 6 try { 7 System.out.println("Thread got: " + ex.exchange("Eduinq")); 8 } catch(Exception e) {} 9 }).start(); 10 System.out.println("Main got: " + ex.exchange("Portal")); 11 } 12 } View Answer
Correct answer: A — Thread got: Portal, Main got: Eduinq
- Which of the following is true about ForkJoinPool?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.util.concurrent.*; 2 public class Test { 3 public static void main(String[] args) { 4 ForkJoinPool pool = new ForkJoinPool(); 5 pool.submit(() -> System.out.println("Eduinq ForkJoin")); 6 pool.shutdown(); 7 } 8 } View Answer
Correct answer: A — Eduinq ForkJoin
- Which of the following is true about CompletableFuture?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.util.concurrent.*; 2 public class Test { 3 public static void main(String[] args) throws Exception { 4 CompletableFuture<String> cf = CompletableFuture.supplyAsync(() -> "Eduinq Async"); 5 System.out.println(cf.get()); 6 } 7 } View Answer
Correct answer: A — Eduinq Async
- Which of the following is true about CompletableFuture.thenApply()?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.util.concurrent.*; 2 public class Test { 3 public static void main(String[] args) throws Exception { 4 CompletableFuture<String> cf = CompletableFuture.supplyAsync(() -> "Eduinq") 5 .thenApply(s -> s + " Portal"); 6 System.out.println(cf.get()); 7 } 8 } View Answer
Correct answer: A — Eduinq Portal
- Which of the following is true about CompletableFuture.thenCombine()?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 import java.util.concurrent.*; 2 public class Test { 3 public static void main(String[] args) throws Exception { 4 CompletableFuture<String> cf1 = CompletableFuture.supplyAsync(() -> "Eduinq"); 5 CompletableFuture<String> cf2 = CompletableFuture.supplyAsync(() -> "Portal"); 6 CompletableFuture<String> combined = cf1.thenCombine(cf2, (a,b) -> a + " " + b); 7 System.out.println(combined.get()); 8 } 9 } View Answer
Correct answer: A — Eduinq Portal