SlideShare a Scribd company logo
1 of 44
Quiz
Fun way to learn more
Java Concurrency
Question
You’ve written an application for processing tasks. In this application,
you’ve separated the critical or urgent tasks from the ones that are not
critical or urgent. You’ve assigned high priority to critical or urgent tasks.
In this application, you find that the tasks that are not critical or urgent
are the ones that keep waiting for an unusually long time. Since critical or
urgent tasks are high priority, they run most of the time. Which one of
the following multi-threading problems correctly describes this situation?
A. Deadlock
B. Starvation
C. Livelock
D. Race condition
Answer
You’ve written an application for processing tasks. In this application,
you’ve separated the critical or urgent tasks from the ones that are not
critical or urgent. You’ve assigned high priority to critical or urgent tasks.
In this application, you find that the tasks that are not critical or urgent are
the ones that keep waiting for an unusually long time. Since critical or
urgent tasks are high priority, they run most of the time. Which one of the
following multi-threading problems correctly describes this situation?
A. Deadlock
B. Starvation
C. Livelock
D. Race condition
Explanation
B . Starvation
The situation in which low-priority threads keep waiting
for a long time to acquire the lock and execute the code
in critical sections is known as starvation.
Starvation
Starvation describes a situation where a thread is unable to gain regular access to shared
resources and is unable to make progress. This happens when shared resources are made
unavailable for long periods by "greedy" threads.
Livelock
A thread often acts in response to the action of another thread. If the other thread's
action is also a response to the action of another thread, then livelock may result. As with
deadlock, livelocked threads are unable to make further progress. However, the threads
are not blocked — they are simply too busy responding to each other to resume work.
This is comparable to two people attempting to pass each other in a corridor: Alphonse
moves to his left to let Gaston pass, while Gaston moves to his right to let Alphonse pass.
Seeing that they are still blocking each other, Alphone moves to his right, while Gaston
moves to his left. They're still blocking each other, so...
Source: docs.oracle.com
Question
Which of the following two definitions of Sync (when
compiled in separate files) will compile without errors?
A. class Sync {
public synchronized void foo() {}
}
B. abstract class Sync {
public synchronized void foo() {}
}
C. abstract class Sync {
public abstract synchronized void foo();
}
D. interface Sync {
public synchronized void foo();
}
Answer
Which of the following two definitions of Sync (when
compiled in separate files) will compile without errors?
A. class Sync {
public synchronized void foo() {}
}
B. abstract class Sync {
public synchronized void foo() {}
}
C. abstract class Sync {
public abstract synchronized void foo();
}
D. interface Sync {
public synchronized void foo();
}
Explanation
Abstract methods (in abstract classes or interfaces)
cannot be declared synchronized , hence the options C
and D are incorrect.
Question
Which one of the following options correctly makes use of
Callable that will compile without any errors?
A. import java.util.concurrent.Callable;
class CallableTask implements Callable {
public int call() {
System.out.println("In Callable.call()");
return 0;
}
}
B. import java.util.concurrent.Callable;
class CallableTask extends Callable {
public Integer call() {
System.out.println("In Callable.call()");
return 0;
}
}
C. import java.util.concurrent.Callable;
class CallableTask implements
Callable<Integer> {
public Integer call() {
System.out.println("In Callable.call()");
return 0;
}
}
D. import java.util.concurrent.Callable;
class CallableTask implements
Callable<Integer> {
public void call(Integer i) {
System.out.println("In Callable.call(i)");
}
}
Answer
Which one of the following options correctly makes use of
Callable that will compile without any errors?
A. import java.util.concurrent.Callable;
class CallableTask implements Callable {
public int call() {
System.out.println("In Callable.call()");
return 0;
}
}
B. import java.util.concurrent.Callable;
class CallableTask extends Callable {
public Integer call() {
System.out.println("In Callable.call()");
return 0;
}
}
C. import java.util.concurrent.Callable;
class CallableTask implements
Callable<Integer> {
public Integer call() {
System.out.println("In Callable.call()");
return 0;
}
}
D. import java.util.concurrent.Callable;
class CallableTask implements
Callable<Integer> {
public void call(Integer i) {
System.out.println("In Callable.call(i)");
}
}
Explanation
C. The Callable interface is defined as follows:
public interface Callable<V> {
V call() throws Exception;
}
In option A), the call() method has the return type int , which
is incompatible with the return type expected for overriding
the call method and so will not compile.
In option B), the extends keyword is used, which will result in
a compiler (since Callable is an interface, the implements
keyword should be used).
In option D), the return type of call() is void and the call()
method also takes a parameter of type Integer . Hence, the
method declared in the interface Integer call() remains
unimplemented in the CallableTask class, so the program will
not compile.
Question
Here is a class named PingPong that extends the Thread class. Which of the
following PingPong class implementations correctly prints “ping” from the
worker thread and then prints “pong” from the main thread?
A. public static void main(String []args) {
Thread pingPong = new PingPong();
System.out.print("pong");
}
}
B. public static void main(String []args) {
Thread pingPong = new PingPong();
pingPong.run();
System.out.print("pong");
}}
C. public static void main(String []args) {
Thread pingPong = new PingPong();
pingPong.start();
System.out.println("pong");
}}
D. public static void main(String []args)
throws InterruptedException{
Thread pingPong = new PingPong();
pingPong.start();
pingPong.join();
System.out.println("pong");
}}
class PingPong extends Thread {
public void run() {
System.out.println("ping ");
}
Answer
Here is a class named PingPong that extends the Thread class. Which of the
following PingPong class implementations correctly prints “ping” from the
worker thread and then prints “pong” from the main thread?
A. public static void main(String []args) {
Thread pingPong = new PingPong();
System.out.print("pong");
}
}
B. public static void main(String []args) {
Thread pingPong = new PingPong();
pingPong.run();
System.out.print("pong");
}}
C. public static void main(String []args) {
Thread pingPong = new PingPong();
pingPong.start();
System.out.println("pong");
}}
D. public static void main(String []args)
throws InterruptedException{
Thread pingPong = new PingPong();
pingPong.start();
pingPong.join();
System.out.println("pong");
}}
class PingPong extends Thread {
public void run() {
System.out.println("ping ");
}
Explanation
D .
The main thread creates the worker thread and waits for it to
complete (which prints “ping”). After that it prints “pong”. So,
this implementation correctly prints “ping pong”.
Why are the other options wrong?
A. The main() method creates the worker thread, but doesn’t start it.
So, the code given in this option only prints “pong”.
B. The program always prints “ping pong”, but it is misleading. The
code in this option directly calls the run() method instead of calling
the start() method. So, this is a single threaded program: both “ping”
and “pong” are printed from the main thread.
C. The main thread and the worker thread execute independently
without any coordination. (Note that it does not have a call to join()
in the main method.) So, depending on which thread is scheduled
first, you can get “ping pong” or “pong ping” printed.
Question
Choose the correct option based on this program:
class COWArrayListTest {
public static void main(String []args) {
ArrayList<Integer> aList =
new CopyOnWriteArrayList<Integer>(); // LINE A
aList.addAll(Arrays.asList(10, 20, 30, 40));
System.out.println(aList);
}
}
A. When executed the program prints the following: [10, 20, 30, 40].
B. When executed the program prints the following:
CopyOnWriteArrayList.class .
C. The program does not compile and results in a compiler error in line
marked with comment LINE A .
D. When executed the program throws a runtime exception
ConcurrentModificationException .
Answer
Choose the correct option based on this program:
class COWArrayListTest {
public static void main(String []args) {
ArrayList<Integer> aList =
new CopyOnWriteArrayList<Integer>(); // LINE A
aList.addAll(Arrays.asList(10, 20, 30, 40));
System.out.println(aList);
}
}
A. When executed the program prints the following: [10, 20, 30, 40].
B. When executed the program prints the following:
CopyOnWriteArrayList.class .
C. The program does not compile and results in a compiler error in line
marked with comment LINE A .
D. When executed the program throws a runtime exception
ConcurrentModificationException .
Explanation
C . The program does not compile and results in a
compiler error in the line marked with comment LINE
A.
The class CopyOnWriteArrayList does not inherit from
ArrayList , so an attempt to assign a
CopyOnWriteArrayList to an ArrayList reference will
result in a compiler error. Note that the ArrayList
suffix in the class named CopyOnWriteArrayList could
be misleading as these two classes do not share anIS-
A relationship.
Question
What will this code segment print?
public static void main(String []args) {
List<Integer> ints = Arrays.asList(1, 2, 3, 4, 5);
System.out.println(ints.parallelStream()
.filter(i -> (i % 2) == 0).sequential()
.isParallel());
}
A. Prints 2 4
B. Prints false
C. Prints true
D. Cannot predict output
Answer
What will this code segment print?
public static void main(String []args) {
List<Integer> ints = Arrays.asList(1, 2, 3, 4, 5);
System.out.println(ints.parallelStream()
.filter(i -> (i % 2) == 0).sequential()
.isParallel());
}
A. Prints 2 4
B. Prints false
C. Prints true
D. Cannot predict output
Explanation
B. Prints false
Though the created stream is a parallel stream, the
call to the sequential() method has made the stream
sequential. Hence, the call isParallel() prints false .
Question
Which one of the following methods return a Future object?
A. The overloaded replace() methods declared in the ConcurrentMap
interface
B. The newThread() method declared in the ThreadFactory interface
C. The overloaded submit() methods declared in the ExecutorService
interface
D. The call() method declared in the Callable interface
Answer
Which one of the following methods return a Future object?
A. The overloaded replace() methods declared in the ConcurrentMap
interface
B. The newThread() method declared in the ThreadFactory interface
C. The overloaded submit() methods declared in the ExecutorService
interface
D. The call() method declared in the Callable interface
Explanation
C . The overloaded submit() methods declared in
ExecutorService interface. The ExecutorService interface
extends the Executor interface and provides services such as
termination of threads and production of Future objects. Some
tasks may take considerable execution time
to complete. So, when you submit a task to the executor
service, you get a Future object.
A. The overloaded replace() methods declared in the ConcurrentMap
interface remove an element from the map and return the success
status (a Boolean value) or the removed value.
B. The new Thread() is the only method declared in the
ThreadFactory interface and it returns a Thread object as the return
value
D. The call() method declared in Callable interface returns the result
of the task it executed.
Question
In your application, there is a producer component that keeps adding
new items to a fixed-size queue; the consumer component fetches
items from that queue. If the queue is full, the producer has to wait
for items to be fetched; if the queue is empty, the consumer has to
wait for items to be added.
Which one of the following utilities is suitable for synchronizing the
common queue for concurrent use by a producer and consumer?
A. ForkJoinPool
B. Future
C. Semaphore
D. TimeUnit
Answer
In your application, there is a producer component that keeps adding
new items to a fixed-size queue; the consumer component fetches
items from that queue. If the queue is full, the producer has to wait for
items to be fetched; if the queue is empty, the consumer has to wait
for items to be added.
Which one of the following utilities is suitable for synchronizing the
common queue for concurrent use by a producer and consumer?
A. ForkJoinPool
B. Future
C. Semaphore
D. TimeUnit
Explanation
C. Semaphore
The question is a classic producer–consumer problem that can be
solved by using semaphores. The objects of the synchronizer class
java.util.concurrent.Semaphore can be used to guard the common
queue so that the producer and consumer can synchronize their
access to the queue. Of the given options, semaphore is the only
synchronizer ; other options are unrelated to providing
synchronized access to a queue.
A. ForkJoinPool provides help in running a ForkJoinTask in the context of
the Fork/Join framework.
B. Future represents the result of an asynchronous computation whose
result will be “available in the future once the computation is complete.”
D. TimeUnit is an enumeration that provides support for different time
units such as milliseconds, seconds, and days.
Question
What will this code segment print?
class StringConcatenator {
public static String result = "";
public static void concatStr(String str) {
result = result + " " + str;
}
}
class StringSplitAndConcatenate {
public static void main(String []args) {
String words[] = "the quick brown fox jumps over the lazy dog".split(" ");
Arrays.stream(words).parallel().forEach(StringConcatenator::concatStr);
System.out.println(StringConcatenator.result);
}
}
A. over jumps lazy dog the brown fox quick the
B. the quick brown fox jumps over the lazy dog
C. Prints each word in new line
D. Cannot predict output
Answer
What will this code segment print?
class StringConcatenator {
public static String result = "";
public static void concatStr(String str) {
result = result + " " + str;
}
}
class StringSplitAndConcatenate {
public static void main(String []args) {
String words[] = "the quick brown fox jumps over the lazy dog".split(" ");
Arrays.stream(words).parallel().forEach(StringConcatenator::concatStr);
System.out.println(StringConcatenator.result);
}
}
A. over jumps lazy dog the brown fox quick the
B. the quick brown fox jumps over the lazy dog
C. Prints each word in new line
D. Cannot predict output
Explanation
D. Cannot predict output
When the stream is parallel, the task is split into
multiple sub-tasks and different threads execute it.
The calls to forEach(StringConcatenator::concatStr)
now access the globally accessible variable result
in StringConcatenator class. Hence it results in garbled
output.
Question
What is the expected output of this program when invoked as follows:
java -ea AtomicIntegerTest
static AtomicInteger ai = new AtomicInteger(10);
public static void main(String []args) {
ai.incrementAndGet();
ai.getAndDecrement();
ai.compareAndSet(10, 11);
assert (ai.intValue() % 2) == 0;
System.out.println(ai);
}
A. Prints 10 11
B. Prints 10
C. It crashes throwing an AssertionError
D. Prints 9
Answer
What is the expected output of this program when invoked as follows:
java -ea AtomicIntegerTest
static AtomicInteger ai = new AtomicInteger(10);
public static void main(String []args) {
ai.incrementAndGet();
ai.getAndDecrement();
ai.compareAndSet(10, 11);
assert (ai.intValue() % 2) == 0;
System.out.println(ai);
}
A. Prints 10 11
B. Prints 10
C. It crashes throwing an AssertionError
D. Prints 9
Explanation
C. It crashes throwing an AssertionError .
The initial value of AtomicInteger is 10. Its value is
incremented by 1 after calling incrementAndGet ().
After that, its value is decremented by 1 after calling
getAndDecrement ( ).
The method compareAndSet (10, 11) checks if the
current value is 10, and if so sets the atomic integer
variable to value 11.
Since the assert statement checks if the atomic
integer value % 2 is zero (that is, checks if it is an even
number), the assert fails and the program results in an
AssertionError .
Question
Consider that you are developing an cards game where a person starts the
game and waits for the other players to join. Minimum 4 players are
required to start the game and as soon as all the players are available the
game has to get started. For developing such kind of game application which
of the following synchronization technique would be ideal:
A. Semaphore
B. Exchanger
C. Runnable
D. Cyclic Barrier
Answer
Consider that you are developing an cards game where a person starts the
game and waits for the other players to join. Minimum 4 players are
required to start the game and as soon as all the players are available the
game has to get started. For developing such kind of game application which
of the following synchronization technique would be ideal:
A. Semaphore
B. Exchanger
C. Runnable
D. Cyclic Barrier
Explanation
D. CyclicBarrier
CyclicBarrier helps provide a synchronization point
where threads may need to wait at a predefined
execution point until all other threads reach that
point.
A. A Semaphore controls access to shared resources.
A semaphore maintains a counter to specify number
of resources that the semaphore controls
B. The Exchanger class is meant for exchanging data
between two threads. This class is useful when two
threads need to synchronize between each other and
continuously
exchange data.
C. Runnable is an interface used in creating threads
Question
Consider the following program and choose the correct option describing its
behavior
class PingPong extends Thread {
public void run() {
System.out.print("ping ");
throw new IllegalStateException();
}
public static void main(String []args) throws InterruptedException {
Thread pingPong = new PingPong();
pingPong.start();
System.out.print("pong");
}
}
A. This program results in a compiler error.
B. Prints the ping pong and exception in any order
C. This program throws a runtime error.
D. Prints pong ping
Answer
Consider the following program and choose the correct option describing its
behavior
class PingPong extends Thread {
public void run() {
System.out.print("ping ");
throw new IllegalStateException();
}
public static void main(String []args) throws InterruptedException {
Thread pingPong = new PingPong();
pingPong.start();
System.out.print("pong");
}
}
A. This program results in a compiler error.
B. Prints the ping pong and exception in any order
C. This program throws a runtime error.
D. Prints pong ping
Explanation
B. Prints the ping pong and exception in any order
The programs executes fine and the exact output
cannot be predicted as the main thread and the
worker thread execute independently without any
coordination.
Question
Consider the following program and choose the correct option describing its behavior
public static void main(String[] args) {
ExecutorService executor;
try(executor = Executors.newFixedThreadPool(5)){
Runnable worker = new Runnable() {
public void run() {
System.out.print("Hello");
} };
executor.execute(worker);
executor.shutdown();
System.out.println("Execution completed");
}
}
A. This program results in a compiler error.
B. Prints Execution completed and Hello in next line
C. Prints Hello
D. Prints Execution completed
Answer
Consider the following program and choose the correct option describing its behavior
public static void main(String[] args) {
ExecutorService executor;
try(executor = Executors.newFixedThreadPool(5)){
Runnable worker = new Runnable() {
public void run() {
System.out.print("Hello");
} };
executor.execute(worker);
executor.shutdown();
System.out.println("Execution completed");
}
}
A. This program results in a compiler error.
B. Prints Execution completed and Hello in next line
C. Prints Hello
D. Prints Execution completed
Explanation
A. This program results in a compiler error
Try-with-resources statement cannot be used here as,
ExecutorServices does not implement
java.lang.AutoCloseable interface
Upcoming Workshops/Bootcamps
• SOLID Principles and Design Patterns – Aug 27th
• Microsoft Azure Bootcamp – Aug 27th
• Modern Software Architecture – Sep 10th
Please visit CodeOps.tech for more details such as
agenda/cost/trainer and registration.
OCP Java: http://ocpjava.wordpress.com
Tech talks
 Tech talks are for knowledge sharing - so there is no cost
associated with it
 We usually share the presentation & supporting material to
the participants after the tech talk
 Duration of the tech talk would be for 1 hour and will be
given at your office premises
 Topics on which we offer tech talks can be found here Tech
Talk Topics
 We also offer free workshop on Introduction to Docker
which will be a hands-on session
Meetups
• Core-Java-Meetup-Bangalore
• Software-Craftsmanship-Bangalore – 20th July @Ginserv
• Container-Developers-Meetup - 20th Aug @Avaya
• CloudOps-Meetup-Bangalore - 20th Aug @Avaya
• JavaScript-Meetup-Bangalore - 20th Aug
• Technical-Writers-Meetup-Bangalore – 25th Sep
• Software Architects Bangalore – 1st Oct @Prowareness
• Bangalore-SDN-IoT-NetworkVirtualization-Enthusiasts
Founders Achievements
www.codeops.tech slideshare.net/codeops
reachus@codeops.tech linkedin.com/codeops
 Has 14+ years of corporate experience and worked in
various roles and conducted many corporate trainings
 Authored/co-authored many articles, research papers,
and books that got internationally published and
respected in the community
 Have Software Engineering Certified Instructor (SECI)
and Professional Software Engineering Master (PSEM)
certifications from IEEE

More Related Content

What's hot

Threads V4
Threads  V4Threads  V4
Threads V4Sunil OS
 
Packages,static,this keyword in java
Packages,static,this keyword in javaPackages,static,this keyword in java
Packages,static,this keyword in javaVishnu Suresh
 
Super and final in java
Super and final in javaSuper and final in java
Super and final in javaanshu_atri
 
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...Simplilearn
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in javaPratik Soares
 
Exception Handling
Exception HandlingException Handling
Exception HandlingSunil OS
 
Serialization & De-serialization in Java
Serialization & De-serialization in JavaSerialization & De-serialization in Java
Serialization & De-serialization in JavaInnovationM
 
JUnit & Mockito, first steps
JUnit & Mockito, first stepsJUnit & Mockito, first steps
JUnit & Mockito, first stepsRenato Primavera
 
05 junit
05 junit05 junit
05 junitmha4
 
Exceptionhandling
ExceptionhandlingExceptionhandling
ExceptionhandlingNuha Noor
 
Classes and Nested Classes in Java
Classes and Nested Classes in JavaClasses and Nested Classes in Java
Classes and Nested Classes in JavaRavi_Kant_Sahu
 

What's hot (20)

Threads V4
Threads  V4Threads  V4
Threads V4
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
Packages,static,this keyword in java
Packages,static,this keyword in javaPackages,static,this keyword in java
Packages,static,this keyword in java
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Introduction to OOP(in java) BY Govind Singh
Introduction to OOP(in java)  BY Govind SinghIntroduction to OOP(in java)  BY Govind Singh
Introduction to OOP(in java) BY Govind Singh
 
Super and final in java
Super and final in javaSuper and final in java
Super and final in java
 
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
OOP V3.1
OOP V3.1OOP V3.1
OOP V3.1
 
Serialization & De-serialization in Java
Serialization & De-serialization in JavaSerialization & De-serialization in Java
Serialization & De-serialization in Java
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
 
JUnit & Mockito, first steps
JUnit & Mockito, first stepsJUnit & Mockito, first steps
JUnit & Mockito, first steps
 
JUnit 4
JUnit 4JUnit 4
JUnit 4
 
05 junit
05 junit05 junit
05 junit
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
 
Inheritance
InheritanceInheritance
Inheritance
 
Java Unit Testing
Java Unit TestingJava Unit Testing
Java Unit Testing
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 
Classes and Nested Classes in Java
Classes and Nested Classes in JavaClasses and Nested Classes in Java
Classes and Nested Classes in Java
 

Viewers also liked

Modern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIModern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIGanesh Samarthyam
 
DevOps Fundamentals: A perspective on DevOps Culture
DevOps Fundamentals: A perspective on DevOps Culture DevOps Fundamentals: A perspective on DevOps Culture
DevOps Fundamentals: A perspective on DevOps Culture CodeOps Technologies LLP
 
Choosing Between Cross Platform of Native Development
Choosing	Between Cross Platform of Native DevelopmentChoosing	Between Cross Platform of Native Development
Choosing Between Cross Platform of Native DevelopmentCodeOps Technologies LLP
 
Advanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesAdvanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesGanesh Samarthyam
 
Refactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech TalkRefactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech TalkCodeOps Technologies LLP
 
Solid Principles Of Design (Design Series 01)
Solid Principles Of Design (Design Series 01)Solid Principles Of Design (Design Series 01)
Solid Principles Of Design (Design Series 01)Heartin Jacob
 
Zero downtime release through DevOps Continuous Delivery
Zero downtime release through DevOps Continuous DeliveryZero downtime release through DevOps Continuous Delivery
Zero downtime release through DevOps Continuous DeliveryMurughan Palaniachari
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Ganesh Samarthyam
 
Book Preview: Oracle Certified Professional Java (OCP Java) SE 8 Programmer E...
Book Preview: Oracle Certified Professional Java (OCP Java) SE 8 Programmer E...Book Preview: Oracle Certified Professional Java (OCP Java) SE 8 Programmer E...
Book Preview: Oracle Certified Professional Java (OCP Java) SE 8 Programmer E...Hari kiran G
 

Viewers also liked (20)

Java Generics - by Example
Java Generics - by ExampleJava Generics - by Example
Java Generics - by Example
 
Java 8 concurrency abstractions
Java 8 concurrency abstractionsJava 8 concurrency abstractions
Java 8 concurrency abstractions
 
Sailing with Java 8 Streams
Sailing with Java 8 StreamsSailing with Java 8 Streams
Sailing with Java 8 Streams
 
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time APIModern Programming in Java 8 - Lambdas, Streams and Date Time API
Modern Programming in Java 8 - Lambdas, Streams and Date Time API
 
7 best quotes on dev ops
7 best quotes on dev ops7 best quotes on dev ops
7 best quotes on dev ops
 
DevOps Fundamentals: A perspective on DevOps Culture
DevOps Fundamentals: A perspective on DevOps Culture DevOps Fundamentals: A perspective on DevOps Culture
DevOps Fundamentals: A perspective on DevOps Culture
 
Choosing Between Cross Platform of Native Development
Choosing	Between Cross Platform of Native DevelopmentChoosing	Between Cross Platform of Native Development
Choosing Between Cross Platform of Native Development
 
Better java with design
Better java with designBetter java with design
Better java with design
 
Introduction to chef
Introduction to chefIntroduction to chef
Introduction to chef
 
DevOps - A Gentle Introduction
DevOps - A Gentle IntroductionDevOps - A Gentle Introduction
DevOps - A Gentle Introduction
 
Advanced Debugging Using Java Bytecodes
Advanced Debugging Using Java BytecodesAdvanced Debugging Using Java Bytecodes
Advanced Debugging Using Java Bytecodes
 
Software Architecture - Quiz Questions
Software Architecture - Quiz QuestionsSoftware Architecture - Quiz Questions
Software Architecture - Quiz Questions
 
Refactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech TalkRefactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech Talk
 
Java Concurrency by Example
Java Concurrency by ExampleJava Concurrency by Example
Java Concurrency by Example
 
Solid Principles Of Design (Design Series 01)
Solid Principles Of Design (Design Series 01)Solid Principles Of Design (Design Series 01)
Solid Principles Of Design (Design Series 01)
 
Zero downtime release through DevOps Continuous Delivery
Zero downtime release through DevOps Continuous DeliveryZero downtime release through DevOps Continuous Delivery
Zero downtime release through DevOps Continuous Delivery
 
DevOps Toolchain v1.0
DevOps Toolchain v1.0DevOps Toolchain v1.0
DevOps Toolchain v1.0
 
DevOps game marshmallow challenge
DevOps game marshmallow challengeDevOps game marshmallow challenge
DevOps game marshmallow challenge
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams
 
Book Preview: Oracle Certified Professional Java (OCP Java) SE 8 Programmer E...
Book Preview: Oracle Certified Professional Java (OCP Java) SE 8 Programmer E...Book Preview: Oracle Certified Professional Java (OCP Java) SE 8 Programmer E...
Book Preview: Oracle Certified Professional Java (OCP Java) SE 8 Programmer E...
 

Similar to Java concurrency questions and answers

OCJP Samples Questions: Exceptions and assertions
OCJP Samples Questions: Exceptions and assertionsOCJP Samples Questions: Exceptions and assertions
OCJP Samples Questions: Exceptions and assertionsHari kiran G
 
Java language fundamentals
Java language fundamentalsJava language fundamentals
Java language fundamentalsKapish Joshi
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfmayorothenguyenhob69
 
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...Udayan Khattry
 
Java Generics
Java GenericsJava Generics
Java Genericsjeslie
 
1z0 804 exam-java se 7 programmer ii
1z0 804 exam-java se 7 programmer ii1z0 804 exam-java se 7 programmer ii
1z0 804 exam-java se 7 programmer iiIsabella789
 
Language fundamentals ocjp
Language fundamentals ocjpLanguage fundamentals ocjp
Language fundamentals ocjpBhavishya sharma
 
Introduction of Object Oriented Programming Language using Java. .pptx
Introduction of Object Oriented Programming Language using Java. .pptxIntroduction of Object Oriented Programming Language using Java. .pptx
Introduction of Object Oriented Programming Language using Java. .pptxPoonam60376
 
Java Programs
Java ProgramsJava Programs
Java Programsvvpadhu
 
Indus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answersIndus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answersSushant Choudhary
 

Similar to Java concurrency questions and answers (20)

OCJP Samples Questions: Exceptions and assertions
OCJP Samples Questions: Exceptions and assertionsOCJP Samples Questions: Exceptions and assertions
OCJP Samples Questions: Exceptions and assertions
 
1
11
1
 
Java Inheritance
Java InheritanceJava Inheritance
Java Inheritance
 
Java language fundamentals
Java language fundamentalsJava language fundamentals
Java language fundamentals
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
 
Java Quiz - Meetup
Java Quiz - MeetupJava Quiz - Meetup
Java Quiz - Meetup
 
Java programs
Java programsJava programs
Java programs
 
Java Generics
Java GenericsJava Generics
Java Generics
 
1z0 804 exam-java se 7 programmer ii
1z0 804 exam-java se 7 programmer ii1z0 804 exam-java se 7 programmer ii
1z0 804 exam-java se 7 programmer ii
 
Language fundamentals ocjp
Language fundamentals ocjpLanguage fundamentals ocjp
Language fundamentals ocjp
 
Core java
Core javaCore java
Core java
 
Introduction of Object Oriented Programming Language using Java. .pptx
Introduction of Object Oriented Programming Language using Java. .pptxIntroduction of Object Oriented Programming Language using Java. .pptx
Introduction of Object Oriented Programming Language using Java. .pptx
 
Java Programs
Java ProgramsJava Programs
Java Programs
 
Scjp6.0
Scjp6.0Scjp6.0
Scjp6.0
 
E5
E5E5
E5
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
Core java Essentials
Core java EssentialsCore java Essentials
Core java Essentials
 
02 - Prepcode
02 - Prepcode02 - Prepcode
02 - Prepcode
 
Indus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answersIndus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answers
 

More from CodeOps Technologies LLP

AWS Serverless Event-driven Architecture - in lastminute.com meetup
AWS Serverless Event-driven Architecture - in lastminute.com meetupAWS Serverless Event-driven Architecture - in lastminute.com meetup
AWS Serverless Event-driven Architecture - in lastminute.com meetupCodeOps Technologies LLP
 
BUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONS
BUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONSBUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONS
BUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONSCodeOps Technologies LLP
 
APPLYING DEVOPS STRATEGIES ON SCALE USING AZURE DEVOPS SERVICES
APPLYING DEVOPS STRATEGIES ON SCALE USING AZURE DEVOPS SERVICESAPPLYING DEVOPS STRATEGIES ON SCALE USING AZURE DEVOPS SERVICES
APPLYING DEVOPS STRATEGIES ON SCALE USING AZURE DEVOPS SERVICESCodeOps Technologies LLP
 
BUILD, TEST & DEPLOY .NET CORE APPS IN AZURE DEVOPS
BUILD, TEST & DEPLOY .NET CORE APPS IN AZURE DEVOPSBUILD, TEST & DEPLOY .NET CORE APPS IN AZURE DEVOPS
BUILD, TEST & DEPLOY .NET CORE APPS IN AZURE DEVOPSCodeOps Technologies LLP
 
CREATE RELIABLE AND LOW-CODE APPLICATION IN SERVERLESS MANNER
CREATE RELIABLE AND LOW-CODE APPLICATION IN SERVERLESS MANNERCREATE RELIABLE AND LOW-CODE APPLICATION IN SERVERLESS MANNER
CREATE RELIABLE AND LOW-CODE APPLICATION IN SERVERLESS MANNERCodeOps Technologies LLP
 
CREATING REAL TIME DASHBOARD WITH BLAZOR, AZURE FUNCTION COSMOS DB AN AZURE S...
CREATING REAL TIME DASHBOARD WITH BLAZOR, AZURE FUNCTION COSMOS DB AN AZURE S...CREATING REAL TIME DASHBOARD WITH BLAZOR, AZURE FUNCTION COSMOS DB AN AZURE S...
CREATING REAL TIME DASHBOARD WITH BLAZOR, AZURE FUNCTION COSMOS DB AN AZURE S...CodeOps Technologies LLP
 
WRITE SCALABLE COMMUNICATION APPLICATION WITH POWER OF SERVERLESS
WRITE SCALABLE COMMUNICATION APPLICATION WITH POWER OF SERVERLESSWRITE SCALABLE COMMUNICATION APPLICATION WITH POWER OF SERVERLESS
WRITE SCALABLE COMMUNICATION APPLICATION WITH POWER OF SERVERLESSCodeOps Technologies LLP
 
Training And Serving ML Model Using Kubeflow by Jayesh Sharma
Training And Serving ML Model Using Kubeflow by Jayesh SharmaTraining And Serving ML Model Using Kubeflow by Jayesh Sharma
Training And Serving ML Model Using Kubeflow by Jayesh SharmaCodeOps Technologies LLP
 
Deploy Microservices To Kubernetes Without Secrets by Reenu Saluja
Deploy Microservices To Kubernetes Without Secrets by Reenu SalujaDeploy Microservices To Kubernetes Without Secrets by Reenu Saluja
Deploy Microservices To Kubernetes Without Secrets by Reenu SalujaCodeOps Technologies LLP
 
Leverage Azure Tech stack for any Kubernetes cluster via Azure Arc by Saiyam ...
Leverage Azure Tech stack for any Kubernetes cluster via Azure Arc by Saiyam ...Leverage Azure Tech stack for any Kubernetes cluster via Azure Arc by Saiyam ...
Leverage Azure Tech stack for any Kubernetes cluster via Azure Arc by Saiyam ...CodeOps Technologies LLP
 
YAML Tips For Kubernetes by Neependra Khare
YAML Tips For Kubernetes by Neependra KhareYAML Tips For Kubernetes by Neependra Khare
YAML Tips For Kubernetes by Neependra KhareCodeOps Technologies LLP
 
Must Know Azure Kubernetes Best Practices And Features For Better Resiliency ...
Must Know Azure Kubernetes Best Practices And Features For Better Resiliency ...Must Know Azure Kubernetes Best Practices And Features For Better Resiliency ...
Must Know Azure Kubernetes Best Practices And Features For Better Resiliency ...CodeOps Technologies LLP
 
Monitor Azure Kubernetes Cluster With Prometheus by Mamta Jha
Monitor Azure Kubernetes Cluster With Prometheus by Mamta JhaMonitor Azure Kubernetes Cluster With Prometheus by Mamta Jha
Monitor Azure Kubernetes Cluster With Prometheus by Mamta JhaCodeOps Technologies LLP
 
Functional Programming in Java 8 - Lambdas and Streams
Functional Programming in Java 8 - Lambdas and StreamsFunctional Programming in Java 8 - Lambdas and Streams
Functional Programming in Java 8 - Lambdas and StreamsCodeOps Technologies LLP
 
Distributed Tracing: New DevOps Foundation
Distributed Tracing: New DevOps FoundationDistributed Tracing: New DevOps Foundation
Distributed Tracing: New DevOps FoundationCodeOps Technologies LLP
 
"Distributed Tracing: New DevOps Foundation" by Jayesh Ahire
"Distributed Tracing: New DevOps Foundation" by Jayesh Ahire  "Distributed Tracing: New DevOps Foundation" by Jayesh Ahire
"Distributed Tracing: New DevOps Foundation" by Jayesh Ahire CodeOps Technologies LLP
 

More from CodeOps Technologies LLP (20)

AWS Serverless Event-driven Architecture - in lastminute.com meetup
AWS Serverless Event-driven Architecture - in lastminute.com meetupAWS Serverless Event-driven Architecture - in lastminute.com meetup
AWS Serverless Event-driven Architecture - in lastminute.com meetup
 
Understanding azure batch service
Understanding azure batch serviceUnderstanding azure batch service
Understanding azure batch service
 
DEVOPS AND MACHINE LEARNING
DEVOPS AND MACHINE LEARNINGDEVOPS AND MACHINE LEARNING
DEVOPS AND MACHINE LEARNING
 
SERVERLESS MIDDLEWARE IN AZURE FUNCTIONS
SERVERLESS MIDDLEWARE IN AZURE FUNCTIONSSERVERLESS MIDDLEWARE IN AZURE FUNCTIONS
SERVERLESS MIDDLEWARE IN AZURE FUNCTIONS
 
BUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONS
BUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONSBUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONS
BUILDING SERVERLESS SOLUTIONS WITH AZURE FUNCTIONS
 
APPLYING DEVOPS STRATEGIES ON SCALE USING AZURE DEVOPS SERVICES
APPLYING DEVOPS STRATEGIES ON SCALE USING AZURE DEVOPS SERVICESAPPLYING DEVOPS STRATEGIES ON SCALE USING AZURE DEVOPS SERVICES
APPLYING DEVOPS STRATEGIES ON SCALE USING AZURE DEVOPS SERVICES
 
BUILD, TEST & DEPLOY .NET CORE APPS IN AZURE DEVOPS
BUILD, TEST & DEPLOY .NET CORE APPS IN AZURE DEVOPSBUILD, TEST & DEPLOY .NET CORE APPS IN AZURE DEVOPS
BUILD, TEST & DEPLOY .NET CORE APPS IN AZURE DEVOPS
 
CREATE RELIABLE AND LOW-CODE APPLICATION IN SERVERLESS MANNER
CREATE RELIABLE AND LOW-CODE APPLICATION IN SERVERLESS MANNERCREATE RELIABLE AND LOW-CODE APPLICATION IN SERVERLESS MANNER
CREATE RELIABLE AND LOW-CODE APPLICATION IN SERVERLESS MANNER
 
CREATING REAL TIME DASHBOARD WITH BLAZOR, AZURE FUNCTION COSMOS DB AN AZURE S...
CREATING REAL TIME DASHBOARD WITH BLAZOR, AZURE FUNCTION COSMOS DB AN AZURE S...CREATING REAL TIME DASHBOARD WITH BLAZOR, AZURE FUNCTION COSMOS DB AN AZURE S...
CREATING REAL TIME DASHBOARD WITH BLAZOR, AZURE FUNCTION COSMOS DB AN AZURE S...
 
WRITE SCALABLE COMMUNICATION APPLICATION WITH POWER OF SERVERLESS
WRITE SCALABLE COMMUNICATION APPLICATION WITH POWER OF SERVERLESSWRITE SCALABLE COMMUNICATION APPLICATION WITH POWER OF SERVERLESS
WRITE SCALABLE COMMUNICATION APPLICATION WITH POWER OF SERVERLESS
 
Training And Serving ML Model Using Kubeflow by Jayesh Sharma
Training And Serving ML Model Using Kubeflow by Jayesh SharmaTraining And Serving ML Model Using Kubeflow by Jayesh Sharma
Training And Serving ML Model Using Kubeflow by Jayesh Sharma
 
Deploy Microservices To Kubernetes Without Secrets by Reenu Saluja
Deploy Microservices To Kubernetes Without Secrets by Reenu SalujaDeploy Microservices To Kubernetes Without Secrets by Reenu Saluja
Deploy Microservices To Kubernetes Without Secrets by Reenu Saluja
 
Leverage Azure Tech stack for any Kubernetes cluster via Azure Arc by Saiyam ...
Leverage Azure Tech stack for any Kubernetes cluster via Azure Arc by Saiyam ...Leverage Azure Tech stack for any Kubernetes cluster via Azure Arc by Saiyam ...
Leverage Azure Tech stack for any Kubernetes cluster via Azure Arc by Saiyam ...
 
YAML Tips For Kubernetes by Neependra Khare
YAML Tips For Kubernetes by Neependra KhareYAML Tips For Kubernetes by Neependra Khare
YAML Tips For Kubernetes by Neependra Khare
 
Must Know Azure Kubernetes Best Practices And Features For Better Resiliency ...
Must Know Azure Kubernetes Best Practices And Features For Better Resiliency ...Must Know Azure Kubernetes Best Practices And Features For Better Resiliency ...
Must Know Azure Kubernetes Best Practices And Features For Better Resiliency ...
 
Monitor Azure Kubernetes Cluster With Prometheus by Mamta Jha
Monitor Azure Kubernetes Cluster With Prometheus by Mamta JhaMonitor Azure Kubernetes Cluster With Prometheus by Mamta Jha
Monitor Azure Kubernetes Cluster With Prometheus by Mamta Jha
 
Jet brains space intro presentation
Jet brains space intro presentationJet brains space intro presentation
Jet brains space intro presentation
 
Functional Programming in Java 8 - Lambdas and Streams
Functional Programming in Java 8 - Lambdas and StreamsFunctional Programming in Java 8 - Lambdas and Streams
Functional Programming in Java 8 - Lambdas and Streams
 
Distributed Tracing: New DevOps Foundation
Distributed Tracing: New DevOps FoundationDistributed Tracing: New DevOps Foundation
Distributed Tracing: New DevOps Foundation
 
"Distributed Tracing: New DevOps Foundation" by Jayesh Ahire
"Distributed Tracing: New DevOps Foundation" by Jayesh Ahire  "Distributed Tracing: New DevOps Foundation" by Jayesh Ahire
"Distributed Tracing: New DevOps Foundation" by Jayesh Ahire
 

Recently uploaded

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 

Recently uploaded (20)

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 

Java concurrency questions and answers

  • 1. Quiz Fun way to learn more Java Concurrency
  • 2. Question You’ve written an application for processing tasks. In this application, you’ve separated the critical or urgent tasks from the ones that are not critical or urgent. You’ve assigned high priority to critical or urgent tasks. In this application, you find that the tasks that are not critical or urgent are the ones that keep waiting for an unusually long time. Since critical or urgent tasks are high priority, they run most of the time. Which one of the following multi-threading problems correctly describes this situation? A. Deadlock B. Starvation C. Livelock D. Race condition
  • 3. Answer You’ve written an application for processing tasks. In this application, you’ve separated the critical or urgent tasks from the ones that are not critical or urgent. You’ve assigned high priority to critical or urgent tasks. In this application, you find that the tasks that are not critical or urgent are the ones that keep waiting for an unusually long time. Since critical or urgent tasks are high priority, they run most of the time. Which one of the following multi-threading problems correctly describes this situation? A. Deadlock B. Starvation C. Livelock D. Race condition
  • 4. Explanation B . Starvation The situation in which low-priority threads keep waiting for a long time to acquire the lock and execute the code in critical sections is known as starvation. Starvation Starvation describes a situation where a thread is unable to gain regular access to shared resources and is unable to make progress. This happens when shared resources are made unavailable for long periods by "greedy" threads. Livelock A thread often acts in response to the action of another thread. If the other thread's action is also a response to the action of another thread, then livelock may result. As with deadlock, livelocked threads are unable to make further progress. However, the threads are not blocked — they are simply too busy responding to each other to resume work. This is comparable to two people attempting to pass each other in a corridor: Alphonse moves to his left to let Gaston pass, while Gaston moves to his right to let Alphonse pass. Seeing that they are still blocking each other, Alphone moves to his right, while Gaston moves to his left. They're still blocking each other, so... Source: docs.oracle.com
  • 5. Question Which of the following two definitions of Sync (when compiled in separate files) will compile without errors? A. class Sync { public synchronized void foo() {} } B. abstract class Sync { public synchronized void foo() {} } C. abstract class Sync { public abstract synchronized void foo(); } D. interface Sync { public synchronized void foo(); }
  • 6. Answer Which of the following two definitions of Sync (when compiled in separate files) will compile without errors? A. class Sync { public synchronized void foo() {} } B. abstract class Sync { public synchronized void foo() {} } C. abstract class Sync { public abstract synchronized void foo(); } D. interface Sync { public synchronized void foo(); }
  • 7. Explanation Abstract methods (in abstract classes or interfaces) cannot be declared synchronized , hence the options C and D are incorrect.
  • 8. Question Which one of the following options correctly makes use of Callable that will compile without any errors? A. import java.util.concurrent.Callable; class CallableTask implements Callable { public int call() { System.out.println("In Callable.call()"); return 0; } } B. import java.util.concurrent.Callable; class CallableTask extends Callable { public Integer call() { System.out.println("In Callable.call()"); return 0; } } C. import java.util.concurrent.Callable; class CallableTask implements Callable<Integer> { public Integer call() { System.out.println("In Callable.call()"); return 0; } } D. import java.util.concurrent.Callable; class CallableTask implements Callable<Integer> { public void call(Integer i) { System.out.println("In Callable.call(i)"); } }
  • 9. Answer Which one of the following options correctly makes use of Callable that will compile without any errors? A. import java.util.concurrent.Callable; class CallableTask implements Callable { public int call() { System.out.println("In Callable.call()"); return 0; } } B. import java.util.concurrent.Callable; class CallableTask extends Callable { public Integer call() { System.out.println("In Callable.call()"); return 0; } } C. import java.util.concurrent.Callable; class CallableTask implements Callable<Integer> { public Integer call() { System.out.println("In Callable.call()"); return 0; } } D. import java.util.concurrent.Callable; class CallableTask implements Callable<Integer> { public void call(Integer i) { System.out.println("In Callable.call(i)"); } }
  • 10. Explanation C. The Callable interface is defined as follows: public interface Callable<V> { V call() throws Exception; } In option A), the call() method has the return type int , which is incompatible with the return type expected for overriding the call method and so will not compile. In option B), the extends keyword is used, which will result in a compiler (since Callable is an interface, the implements keyword should be used). In option D), the return type of call() is void and the call() method also takes a parameter of type Integer . Hence, the method declared in the interface Integer call() remains unimplemented in the CallableTask class, so the program will not compile.
  • 11. Question Here is a class named PingPong that extends the Thread class. Which of the following PingPong class implementations correctly prints “ping” from the worker thread and then prints “pong” from the main thread? A. public static void main(String []args) { Thread pingPong = new PingPong(); System.out.print("pong"); } } B. public static void main(String []args) { Thread pingPong = new PingPong(); pingPong.run(); System.out.print("pong"); }} C. public static void main(String []args) { Thread pingPong = new PingPong(); pingPong.start(); System.out.println("pong"); }} D. public static void main(String []args) throws InterruptedException{ Thread pingPong = new PingPong(); pingPong.start(); pingPong.join(); System.out.println("pong"); }} class PingPong extends Thread { public void run() { System.out.println("ping "); }
  • 12. Answer Here is a class named PingPong that extends the Thread class. Which of the following PingPong class implementations correctly prints “ping” from the worker thread and then prints “pong” from the main thread? A. public static void main(String []args) { Thread pingPong = new PingPong(); System.out.print("pong"); } } B. public static void main(String []args) { Thread pingPong = new PingPong(); pingPong.run(); System.out.print("pong"); }} C. public static void main(String []args) { Thread pingPong = new PingPong(); pingPong.start(); System.out.println("pong"); }} D. public static void main(String []args) throws InterruptedException{ Thread pingPong = new PingPong(); pingPong.start(); pingPong.join(); System.out.println("pong"); }} class PingPong extends Thread { public void run() { System.out.println("ping "); }
  • 13. Explanation D . The main thread creates the worker thread and waits for it to complete (which prints “ping”). After that it prints “pong”. So, this implementation correctly prints “ping pong”. Why are the other options wrong? A. The main() method creates the worker thread, but doesn’t start it. So, the code given in this option only prints “pong”. B. The program always prints “ping pong”, but it is misleading. The code in this option directly calls the run() method instead of calling the start() method. So, this is a single threaded program: both “ping” and “pong” are printed from the main thread. C. The main thread and the worker thread execute independently without any coordination. (Note that it does not have a call to join() in the main method.) So, depending on which thread is scheduled first, you can get “ping pong” or “pong ping” printed.
  • 14. Question Choose the correct option based on this program: class COWArrayListTest { public static void main(String []args) { ArrayList<Integer> aList = new CopyOnWriteArrayList<Integer>(); // LINE A aList.addAll(Arrays.asList(10, 20, 30, 40)); System.out.println(aList); } } A. When executed the program prints the following: [10, 20, 30, 40]. B. When executed the program prints the following: CopyOnWriteArrayList.class . C. The program does not compile and results in a compiler error in line marked with comment LINE A . D. When executed the program throws a runtime exception ConcurrentModificationException .
  • 15. Answer Choose the correct option based on this program: class COWArrayListTest { public static void main(String []args) { ArrayList<Integer> aList = new CopyOnWriteArrayList<Integer>(); // LINE A aList.addAll(Arrays.asList(10, 20, 30, 40)); System.out.println(aList); } } A. When executed the program prints the following: [10, 20, 30, 40]. B. When executed the program prints the following: CopyOnWriteArrayList.class . C. The program does not compile and results in a compiler error in line marked with comment LINE A . D. When executed the program throws a runtime exception ConcurrentModificationException .
  • 16. Explanation C . The program does not compile and results in a compiler error in the line marked with comment LINE A. The class CopyOnWriteArrayList does not inherit from ArrayList , so an attempt to assign a CopyOnWriteArrayList to an ArrayList reference will result in a compiler error. Note that the ArrayList suffix in the class named CopyOnWriteArrayList could be misleading as these two classes do not share anIS- A relationship.
  • 17. Question What will this code segment print? public static void main(String []args) { List<Integer> ints = Arrays.asList(1, 2, 3, 4, 5); System.out.println(ints.parallelStream() .filter(i -> (i % 2) == 0).sequential() .isParallel()); } A. Prints 2 4 B. Prints false C. Prints true D. Cannot predict output
  • 18. Answer What will this code segment print? public static void main(String []args) { List<Integer> ints = Arrays.asList(1, 2, 3, 4, 5); System.out.println(ints.parallelStream() .filter(i -> (i % 2) == 0).sequential() .isParallel()); } A. Prints 2 4 B. Prints false C. Prints true D. Cannot predict output
  • 19. Explanation B. Prints false Though the created stream is a parallel stream, the call to the sequential() method has made the stream sequential. Hence, the call isParallel() prints false .
  • 20. Question Which one of the following methods return a Future object? A. The overloaded replace() methods declared in the ConcurrentMap interface B. The newThread() method declared in the ThreadFactory interface C. The overloaded submit() methods declared in the ExecutorService interface D. The call() method declared in the Callable interface
  • 21. Answer Which one of the following methods return a Future object? A. The overloaded replace() methods declared in the ConcurrentMap interface B. The newThread() method declared in the ThreadFactory interface C. The overloaded submit() methods declared in the ExecutorService interface D. The call() method declared in the Callable interface
  • 22. Explanation C . The overloaded submit() methods declared in ExecutorService interface. The ExecutorService interface extends the Executor interface and provides services such as termination of threads and production of Future objects. Some tasks may take considerable execution time to complete. So, when you submit a task to the executor service, you get a Future object. A. The overloaded replace() methods declared in the ConcurrentMap interface remove an element from the map and return the success status (a Boolean value) or the removed value. B. The new Thread() is the only method declared in the ThreadFactory interface and it returns a Thread object as the return value D. The call() method declared in Callable interface returns the result of the task it executed.
  • 23. Question In your application, there is a producer component that keeps adding new items to a fixed-size queue; the consumer component fetches items from that queue. If the queue is full, the producer has to wait for items to be fetched; if the queue is empty, the consumer has to wait for items to be added. Which one of the following utilities is suitable for synchronizing the common queue for concurrent use by a producer and consumer? A. ForkJoinPool B. Future C. Semaphore D. TimeUnit
  • 24. Answer In your application, there is a producer component that keeps adding new items to a fixed-size queue; the consumer component fetches items from that queue. If the queue is full, the producer has to wait for items to be fetched; if the queue is empty, the consumer has to wait for items to be added. Which one of the following utilities is suitable for synchronizing the common queue for concurrent use by a producer and consumer? A. ForkJoinPool B. Future C. Semaphore D. TimeUnit
  • 25. Explanation C. Semaphore The question is a classic producer–consumer problem that can be solved by using semaphores. The objects of the synchronizer class java.util.concurrent.Semaphore can be used to guard the common queue so that the producer and consumer can synchronize their access to the queue. Of the given options, semaphore is the only synchronizer ; other options are unrelated to providing synchronized access to a queue. A. ForkJoinPool provides help in running a ForkJoinTask in the context of the Fork/Join framework. B. Future represents the result of an asynchronous computation whose result will be “available in the future once the computation is complete.” D. TimeUnit is an enumeration that provides support for different time units such as milliseconds, seconds, and days.
  • 26. Question What will this code segment print? class StringConcatenator { public static String result = ""; public static void concatStr(String str) { result = result + " " + str; } } class StringSplitAndConcatenate { public static void main(String []args) { String words[] = "the quick brown fox jumps over the lazy dog".split(" "); Arrays.stream(words).parallel().forEach(StringConcatenator::concatStr); System.out.println(StringConcatenator.result); } } A. over jumps lazy dog the brown fox quick the B. the quick brown fox jumps over the lazy dog C. Prints each word in new line D. Cannot predict output
  • 27. Answer What will this code segment print? class StringConcatenator { public static String result = ""; public static void concatStr(String str) { result = result + " " + str; } } class StringSplitAndConcatenate { public static void main(String []args) { String words[] = "the quick brown fox jumps over the lazy dog".split(" "); Arrays.stream(words).parallel().forEach(StringConcatenator::concatStr); System.out.println(StringConcatenator.result); } } A. over jumps lazy dog the brown fox quick the B. the quick brown fox jumps over the lazy dog C. Prints each word in new line D. Cannot predict output
  • 28. Explanation D. Cannot predict output When the stream is parallel, the task is split into multiple sub-tasks and different threads execute it. The calls to forEach(StringConcatenator::concatStr) now access the globally accessible variable result in StringConcatenator class. Hence it results in garbled output.
  • 29. Question What is the expected output of this program when invoked as follows: java -ea AtomicIntegerTest static AtomicInteger ai = new AtomicInteger(10); public static void main(String []args) { ai.incrementAndGet(); ai.getAndDecrement(); ai.compareAndSet(10, 11); assert (ai.intValue() % 2) == 0; System.out.println(ai); } A. Prints 10 11 B. Prints 10 C. It crashes throwing an AssertionError D. Prints 9
  • 30. Answer What is the expected output of this program when invoked as follows: java -ea AtomicIntegerTest static AtomicInteger ai = new AtomicInteger(10); public static void main(String []args) { ai.incrementAndGet(); ai.getAndDecrement(); ai.compareAndSet(10, 11); assert (ai.intValue() % 2) == 0; System.out.println(ai); } A. Prints 10 11 B. Prints 10 C. It crashes throwing an AssertionError D. Prints 9
  • 31. Explanation C. It crashes throwing an AssertionError . The initial value of AtomicInteger is 10. Its value is incremented by 1 after calling incrementAndGet (). After that, its value is decremented by 1 after calling getAndDecrement ( ). The method compareAndSet (10, 11) checks if the current value is 10, and if so sets the atomic integer variable to value 11. Since the assert statement checks if the atomic integer value % 2 is zero (that is, checks if it is an even number), the assert fails and the program results in an AssertionError .
  • 32. Question Consider that you are developing an cards game where a person starts the game and waits for the other players to join. Minimum 4 players are required to start the game and as soon as all the players are available the game has to get started. For developing such kind of game application which of the following synchronization technique would be ideal: A. Semaphore B. Exchanger C. Runnable D. Cyclic Barrier
  • 33. Answer Consider that you are developing an cards game where a person starts the game and waits for the other players to join. Minimum 4 players are required to start the game and as soon as all the players are available the game has to get started. For developing such kind of game application which of the following synchronization technique would be ideal: A. Semaphore B. Exchanger C. Runnable D. Cyclic Barrier
  • 34. Explanation D. CyclicBarrier CyclicBarrier helps provide a synchronization point where threads may need to wait at a predefined execution point until all other threads reach that point. A. A Semaphore controls access to shared resources. A semaphore maintains a counter to specify number of resources that the semaphore controls B. The Exchanger class is meant for exchanging data between two threads. This class is useful when two threads need to synchronize between each other and continuously exchange data. C. Runnable is an interface used in creating threads
  • 35. Question Consider the following program and choose the correct option describing its behavior class PingPong extends Thread { public void run() { System.out.print("ping "); throw new IllegalStateException(); } public static void main(String []args) throws InterruptedException { Thread pingPong = new PingPong(); pingPong.start(); System.out.print("pong"); } } A. This program results in a compiler error. B. Prints the ping pong and exception in any order C. This program throws a runtime error. D. Prints pong ping
  • 36. Answer Consider the following program and choose the correct option describing its behavior class PingPong extends Thread { public void run() { System.out.print("ping "); throw new IllegalStateException(); } public static void main(String []args) throws InterruptedException { Thread pingPong = new PingPong(); pingPong.start(); System.out.print("pong"); } } A. This program results in a compiler error. B. Prints the ping pong and exception in any order C. This program throws a runtime error. D. Prints pong ping
  • 37. Explanation B. Prints the ping pong and exception in any order The programs executes fine and the exact output cannot be predicted as the main thread and the worker thread execute independently without any coordination.
  • 38. Question Consider the following program and choose the correct option describing its behavior public static void main(String[] args) { ExecutorService executor; try(executor = Executors.newFixedThreadPool(5)){ Runnable worker = new Runnable() { public void run() { System.out.print("Hello"); } }; executor.execute(worker); executor.shutdown(); System.out.println("Execution completed"); } } A. This program results in a compiler error. B. Prints Execution completed and Hello in next line C. Prints Hello D. Prints Execution completed
  • 39. Answer Consider the following program and choose the correct option describing its behavior public static void main(String[] args) { ExecutorService executor; try(executor = Executors.newFixedThreadPool(5)){ Runnable worker = new Runnable() { public void run() { System.out.print("Hello"); } }; executor.execute(worker); executor.shutdown(); System.out.println("Execution completed"); } } A. This program results in a compiler error. B. Prints Execution completed and Hello in next line C. Prints Hello D. Prints Execution completed
  • 40. Explanation A. This program results in a compiler error Try-with-resources statement cannot be used here as, ExecutorServices does not implement java.lang.AutoCloseable interface
  • 41. Upcoming Workshops/Bootcamps • SOLID Principles and Design Patterns – Aug 27th • Microsoft Azure Bootcamp – Aug 27th • Modern Software Architecture – Sep 10th Please visit CodeOps.tech for more details such as agenda/cost/trainer and registration. OCP Java: http://ocpjava.wordpress.com
  • 42. Tech talks  Tech talks are for knowledge sharing - so there is no cost associated with it  We usually share the presentation & supporting material to the participants after the tech talk  Duration of the tech talk would be for 1 hour and will be given at your office premises  Topics on which we offer tech talks can be found here Tech Talk Topics  We also offer free workshop on Introduction to Docker which will be a hands-on session
  • 43. Meetups • Core-Java-Meetup-Bangalore • Software-Craftsmanship-Bangalore – 20th July @Ginserv • Container-Developers-Meetup - 20th Aug @Avaya • CloudOps-Meetup-Bangalore - 20th Aug @Avaya • JavaScript-Meetup-Bangalore - 20th Aug • Technical-Writers-Meetup-Bangalore – 25th Sep • Software Architects Bangalore – 1st Oct @Prowareness • Bangalore-SDN-IoT-NetworkVirtualization-Enthusiasts
  • 44. Founders Achievements www.codeops.tech slideshare.net/codeops reachus@codeops.tech linkedin.com/codeops  Has 14+ years of corporate experience and worked in various roles and conducted many corporate trainings  Authored/co-authored many articles, research papers, and books that got internationally published and respected in the community  Have Software Engineering Certified Instructor (SECI) and Professional Software Engineering Master (PSEM) certifications from IEEE