Java Questions

Q:

What is the Set interface ?

Answer

- The Set interface provides methods for accessing the elements of a finite mathematical set


- Sets do not allow duplicate elements


- Contains no methods other than those inherited from Collection


- It adds the restriction that duplicate elements are prohibited


- Two Set objects are equal if they contain the same elements

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1617
Q:

What is abstract method?

Answer

abstract method is a method declared with abstract modifier but  with out body.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1617
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 1615
Q:

What is an abstract class?

Answer

An abstract class is an incomplete class. An abstract class is defined with the keyword abstract . We cannot create an object of the abstract class because it is not complete. It sets a behavioral protocol for all its child classes.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1611
Q:

What is the purpose of the wait(), notify(), and notifyAll() methods ?

Answer

The wait(), notify(), and notifyAll() methods are used to provide an efficient way for threads to wait for a shared resource. When a thread executes an object's wait() method, it enters the waiting state. It only enters the ready state after another thread invokes the object's notify() or notifyAll() methods..

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1606
Q:

How to get contents of the folder?

Answer

File[] listFiles();


this method returns list of files stored in a directory.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1597
Q:

What is difference between methods and blocks?

Answer

Method contains name, parameters, return type and executable body. But block does not contains name, parameters, return type.It contains only executable body.


Methods are executed by method call statements. Blocks are executed automatically with class loading and with object creation.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1595
Q:

How do you traverse through a collection using its Iterator?

Answer

To use an iterator to traverse through the contents of a collection, follow these steps:


- Obtain an iterator to the start of the collection by calling the collections iterator() method.


- Set up a loop that makes a call to hasNext(). Have the loop iterate as long as hasNext() returns true.


- Within the loop, obtain each element by calling next().

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1592