Download Android App in your Android Device from Google Play Store
- Search for "Withoutbook Practice Exam Test" in Mobile/Tablet Play Store
Practice InterviewNew Search by Name or Email

Exams Attended

Make Homepage

Bookmark this page

Subscribe Email Address

Core Java Interview Questions and Answers

Ques 291. What is Cloneable Interface in Core Java?

Ans. A  clone of an object is an object with distinct identity and equal contents. To define clone, a class must implement cloneable interface and must override Objectís clone method with a public modifier. At this point, it is worth nothing that cloneable interface does not contain the clone method, and Objectís clone method is protected.

When the Object class finds that the object to be cloned isnít an instance of a class that implements cloneable interface, it throws CloneNotSupportedException.
If a class wants to allow clients to clone itís instances, it must override Objectís clone method with a public modifier.

Is it helpful? Add Comment View Comments
Ques 292. What is dead lock in thread?
Ans.

A special type of error that you need to avoid that relates specifically to multitasking is deadlock, which occurs when two threads have a circular dependency on a pair of synchronized objects.

For example, suppose one thread enters the monitor on object X and another thread enters the monitor on object Y. If the thread in X tries to call any synchronized method on Y, it will block as expected. However, if the thread in Y, in turn, tries to call any synchronized method on X, the thread waits forever, because to access X, it would have to release its own lock on Y so that the first thread could complete.

Is it helpful? Add Comment View Comments
Ques 293. Difference between wait, notify and notifyAll in Core Java.
Ans.
Methods - wait, notify, and notifyAll are used for inter thread communication in Java. wait() allows a thread to check for a condition, and wait if condition doesn't met, while notify() and notifyAll() method informs waiting thread for rechecking condition, after changing state of shared variable. 
hough Both notify() and notifyAll()  are used to notify waiting threads, waiting on shared queue object, but there are some subtle difference between notify and notifyAll in Java. Well, when we use notify(), only one of the sleeping thread will get notification, while in case of notifyAll(), all sleeping thread on that object will get notified. 
Is it helpful? Add Comment View Comments
Ques 294. What is thread pool in java?
Ans. A thread pool is a group of threads initially created that waits for jobs and executes them. The idea is to have the threads always existing, so that we won't have to pay overhead time for creating them every time. They are appropriate when we know there's a stream of jobs to process, even though there could be some time when there are no jobs.


Is it helpful? Add Comment View Comments
Ques 295. What is concurrency in java?
Ans.

Concurrency is the ability to run several programs or several parts of a program in parallel. If a time consuming task can be performed asynchronously or in parallel, this improve the throughput and the interactivity of the program.

A modern computer has several CPU's or several cores within one CPU. The ability to leverage these multi-cores can be the key for a successful high-volume application.

Concurrency Issues:

Threads have their own call stack, but can also access shared data. Therefore you have two basic problems, visibility and access problems.

A visibility problem occurs if thread A reads shared data which is later changed by thread B and thread A is unaware of this change.

An access problem can occur if several thread access and change the same shared data at the same time.

Visibility and access problem can lead to

  • Liveness failure: The program does not react anymore due to problems in the concurrent access of data, e.g. deadlocks.

  • Safety failure: The program creates incorrect data.

Is it helpful? Add Comment View Comments

Most helpful rated by users:

©2019 WithoutBook