Java Questions

Q:

When will you define a method as static?

Answer When a method needs to be accessed even before the creation of the object of the class then we should declare the method as static.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 3717
Q:

When is the finalize() called ? What is the purpose of finalization ?

Answer

The finalize method is called by the garbage collector, just before releasing the object’s memory. It is normally advised to release resources held by the object inside the finalize method.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

1 3597
Q:

What do you know about the big-O notation and can you give some examples with respect to different data structures ?

Answer

The Big-O notation simply describes how well an algorithm scales or performs in the worst case scenario as the number of elements in a data structure increases. The Big-O notation can also be used to describe other behavior such as memory consumption. Since the collection classes are actually data structures, we usually use the Big-O notation to chose the best implementation to use, based on time, memory and performance. Big-O notation can give a good indication about performance for large amounts of data.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 3552
Q:

Why static methods cannot access non static variables or methods?

Answer

A static method cannot access non static variables or methods because static methods doesnt need the object to be accessed. So if a static method has non static variables or non static methods which has instantiated variables they will no be intialized since the object is not created and this could result in an error.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

9 3520
Q:

Can a main() method be declared final?

Answer Yes. Any inheriting class will not be able to have it's own default main() method.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 3441
Q:

What do you mean by platform independence?

Answer

Platform independence means that we can write and compile the java code in one platform (Eg Windows) and can execute the class in any other supported platform (Eg Linux,Solaris,etc).

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 3343
Q:

The keyword which indicates that a method can be accessed by only one thread at a time is

A) Strictfp B) Synchronized
C) New D) None
 
Answer & Explanation Answer: B) Synchronized

Explanation:

The synchronized keyword indicates that a method can be accessed by only one thread at a time

Report Error

View Answer Report Error Discuss

Filed Under: Java

2 3302
Q:

There is one default constructor in every class.

A) The above statement is true B) The above statement is false
C) Both true and false D) None
 
Answer & Explanation Answer: A) The above statement is true

Explanation:

There will always be a default constructor in every class 

Report Error

View Answer Report Error Discuss

Filed Under: Java

0 3292