Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Core Java Interview Questions and Answers

Test your skills through the online practice test: Core Java Quiz Online Practice Test

Ques 276. What is reflection API? How are they implemented?

What is reflection API? How are they implemented?
Reflection is the process of introspecting the features and state of a class at runtime and dynamically manipulate at run time. This is supported using Reflection API with built-in classes like Class, Method, Fields, Constructors etc. Example: Using Java Reflection API we can get the class name, by using the getName method.

Is it helpful? Add Comment View Comments
 

Ques 277. What is dead lock in thread?

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 278. When is static variable loaded? Is it at compile time or runtime? When exactly a static block is loaded in Java?

Static variable are loaded when classloader brings the class to the JVM. It is not necessary that an object has to be created. Static variables will be allocated memory space when they have been loaded. The code in a static block is loaded/executed only once i.e. when the class is first initialized. A class can have any number of static blocks. Static block is not member of a class, they do not have a return statement and they cannot be called directly. Cannot contain this or super. They are primarily used to initialize static fields.

Is it helpful? Add Comment View Comments
 

Ques 279. Difference between wait, notify and notifyAll in Core Java.

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 280. What is thread pool in java?

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
 

Most helpful rated by users:

©2024 WithoutBook