Java Questions

Q:

By whom will the unallocated memory that is no longer needed will be cleared in java?

A) Java Virtual Machine B) Garebage collector
C) Both A and B D) None
 
Answer & Explanation Answer: B) Garebage collector

Explanation:

The Java programming language provides a system-level thread to track memory allocation.

Garbage collection has the following characteristics:

• Checks for and frees memory no longer needed

• Is done automatically

• Can vary dramatically across JVM implementations

Report Error

View Answer Report Error Discuss

Filed Under: Java

0 2808
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 2806
Q:

How does thread synchronization occurs inside a monitor?

Answer

A Monitor defines a lock and condition variables for managing concurrent access to shared data. The monitor uses the lock to ensure that only a single thread inactive in the monitor code at any time.


A monitor allows only one thread to lock an object at once.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2755
Q:

What is Interpreter in Java?

Answer

  • An Interpreter is a program that reads in as input a source program, along with data for the program, and translates the source program step by step.


 


The Java interpreter decodes each lines bytecode and runs a series of machine instructions for that bytecode. The JVM takes the byte code and generates machine code. The byte code is compiled to machine code, and the machine code is executed.

Report Error

View answer Workspace Report Error Discuss

7 2732
Q:

What are the restrictions when overriding a method ?

Answer

Overridden methods must have the same name, argument list, and return type (i.e., they must have the exact signature of the method we are going to override, including return type.)


The overriding method cannot be less visible than the method it overrides( i.e., a public method cannot be override to private).


The overriding method may not throw any exceptions that may not be thrown by the overridden method

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2727
Q:

What is the common usage of serialization? What exceptions occur during serialization?

Answer

The object need to be serialized when it’s sent over a network and when it’s state is saved. Exceptions which occur during serialization are:


a. transient fields


b. when the base class is serialized then only base class fields are handled.


c. static fields are ignored because they are not part of any state.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

1 2711
Q:

What is the difference between ViewState and SessionState?

Answer

'ViewState' is specific to a page in a session.
'SessionState' is specific to user specific data that can be accessed across all pages in the web application.

Report Error

View answer Workspace Report Error Discuss

Subject: Java
Job Role: Analyst , IT Trainer

3 2707
Q:

Why static method can not call non static method of the same class?

Answer

bcoz the static method does not contains the 'this' reference.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2687