Interview Questions

Q:

What is difference between Path and Classpath?

Answer

Path and Classpath are operating system level environment variales. Path is used define where the system can find the executables(.exe) files and classpath is used to specify the location .class files.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1577
Q:

What is the impact of declaring a method as final?

Answer

A method declared as final can't be overridden. A sub-class can't have the same method signature with a different implementation.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1373
Q:

What is static initializer block? What is its use?

Answer

A static initializer block is a block of code that declares with the static keyword. It normally contains the block of code that must execute at the time of class loading. The static initializer block will execute only once at the time of loading the class only.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1671
Q:

How does a try statement determine which catch clause should be used to handle an exception?

Answer

When an exception is thrown , the catch block of the try statement are examined in the order in which they appear. The first catch block that is capable of handling the exception is executed. The remaining catch blocks are ignored

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1468
Q:

What are the the different ways for creating a thread?

Answer

A thread can be created by subclassing Thread, or by implementing the Runnable interface.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1474
Q:

What is the difference between creating a thread by extending Thread class and by implementing Runnable interface? Which one should prefer?

Answer

When creating a thread by extending the Thread class, it is not mandatory to override the run method (If we are not overriding the run method , it is useless), because Thread class have already given a default implementation for run method. But if we are implementing Runnable , it is mandatory to override the run method. The preferred way to create a thread is by implementing Runnable interface, because it give loose coupling.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1406
Q:

What is Thread ?

Answer

A thread is a lightweight subprocess, a smallest unit of processing. It is a separate path of execution. It shares the memory area of process.



As shown in the above figure, thread is executed inside the process. There is context-switching between the threads. There can be multiple processes inside the OS and one process can have multiple threads.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1502
Q:

What do you understand by private, protected and public?

Answer

These are accessibility modifiers. Private is the most restrictive, while public is the least restrictive. There is no real difference between protected and the default type (also known as package protected) within the context of the same package, however the protected keyword allows visibility to a derived class in a different package.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1463