Java Questions

Q:

What is the difference between a JDK and a JVM?

Answer

JDK is Java Development Kit which is for development purpose and it includes execution environment also.


JVM is Java Virtual Machine which is a run time environment for the compiled java class files .Hence you will not be able to compile your source files using a JVM.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2866
Q:

How to define a constant variable in Java?

Answer The variable should be declared as static and final. So only one copy of the variable exists for all instances of the class and the value can't be changed also.
static final int PI = 2.14; is an example for constant.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

1 2850
Q:

Does the order of public and static declaration matter in main() method?

Answer No. It doesn't matter but void should always come before main().
Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2839
Q:

Which of the following modifiers can be used with Local inner class?

A) Final or Abstract B) Final or Transcient
C) Abstract or Transcient D) Final or public
 
Answer & Explanation Answer: A) Final or Abstract

Explanation:

It can either be Final or Abstract

Report Error

View Answer Report Error Discuss

Filed Under: Java

0 2834
Q:

What is the purpose of garbage collection in Java, and when is it used ?

Answer

The purpose of garbage collection is to identify and discard those objects that are no longer needed by the application, in order for the resources to be reclaimed and reused.


 

Report Error

View answer Workspace Report Error Discuss

Subject: Java

1 2797
Q:

Keeping the actoins and attributes together under a single unit is called 

A) Encapsulation B) Information Hiding
C) Polymorphism D) Inheritance
 
Answer & Explanation Answer: A) Encapsulation

Explanation:

Encapsulation is a process of binding the data objects together under a single unit.It is one ofthe elements of oops

Report Error

View Answer Report Error Discuss

Filed Under: Java

0 2746
Q:

Can a source file contain more than one class declaration?

Answer Yes a single source file can contain any number of Class declarations but only one of the class can be declared as public.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2702
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 2675