6
Q:

void waitForSignal() {

Object obj = new Object();

synchronized (Thread.currentThread()) {

obj.wait();

obj.notify();

}

}

Which statement is true?

A) This code can throw an InterruptedException. B) This code can throw an IllegalMonitorStateException.
C) This code can throw a TimeoutException after ten minutes D) All the above

Answer:   B) This code can throw an IllegalMonitorStateException.



Explanation:

It will throw  IllegalMonitorStateException.

Subject: Java
Job Role: IT Trainer
Q:

What is the difference between processes and threads ?

Answer

- A process is an execution of a program, while a Thread is a single execution sequence within a process.


- A process can contain multiple threads. A Thread is sometimes called a lightweight process.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2581
Q:

Explain different ways of creating a thread. Which one would you prefer and why ?

Answer

There are three ways that can be used in order for a Thread to be created:


A class may extend the Thread class.


A class may implement the Runnable interface.


An application can use the Executor framework, in order to create a thread pool.


The Runnable interface is preferred, as it does not require an object to inherit the Thread class. In case your application design requires multiple inheritance, only interfaces can help you. Also, the thread pool is very efficient and can be implemented and used very easily.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 3836
Q:

What are pass by reference and pass by value ?

Answer

When an object is passed by value, this means that a copy of the object is passed. Thus, even if changes are made to that object, it doesn’t affect the original value. 


When an object is passed by reference, this means that the actual object is not passed, rather a reference of the object is passed. Thus, any changes made by the external method, are also reflected in all places.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2129
Q:

What is the difference between an Interface and an Abstract class ?

Answer

1.Main difference is methods of a Java interface are implicitly abstract and cannot have implementations. A Java abstract class can have instance methods that implements a default behavior.


2.Variables declared in a Java interface is by default final. An abstract class may contain non-final variables.


3.Members of a Java interface are public by default. A Java abstract class can have the usual flavors of class members like private, protected, etc..


4.Java interface should be implemented using keyword “implements”; A Java abstract class should be extended using keyword “extends”.


5.An interface can extend another Java interface only, an abstract class can extend another Java class and implement multiple Java interfaces.


6.A Java class can implement multiple interfaces but it can extend only one abstract class.


7.Interface is absolutely abstract and cannot be instantiated; A Java abstract class also cannot be instantiated, but can be invoked if a main() exists.


8.In comparison with java abstract classes, java interfaces are slow as it requires extra indirection.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1931
Q:

What is autoboxing and unboxing ?

Answer

Autoboxing is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes. For example, converting an int to an Integer, a double to a Double, and so on. If the conversion goes the other way, this is called unboxing. 

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 3181
Q:

Can you access non static variable in static context ?

Answer

A static variable in Java belongs to its class and its value remains the same for all its instances. A static variable is initialized when the class is loaded by the JVM. If your code tries to access a non-static variable, without any instance, the compiler will complain, because those variables are not created yet and they are not associated with any instance.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2171
Q:

What is dynamic method dispatch?

Answer

Dynamic method dispatch which is also known as runtime polymorphism is a process in which a call to an overridden method is resolved at runtime rather than at compile-time. In this process, an overridden method is called through the reference variable of a superclass. The determination of the method to be called is based on the object being referred to by the reference variable.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 5069
Q:

What is the similarity between Dynamic Binding and linking?

Answer

Dynamic binding is orthogonal to dynamic linking. Binding refers to the linking of a procedure call to the code to be executed in response to the call. Dynamic binding It is associated with polymorphism and inheritance, it(also known as late binding) means that the code associated with a given procedure call is not known until the time of the call at run-time.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1724