Java Questions

Q:

How do you handle error condition while writing stored procedure or accessing stored procedure from java ?

Answer

Stored procedure should return error code if some operation fails but if stored procedure itself fail than catching SQLException is only choice.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

1 4017
Q:

Inside an interface when should the variables be initialized?

A) Globally B) Whenever required
C) Inside a function D) During the time of declaration
 
Answer & Explanation Answer: D) During the time of declaration

Explanation:

They should be initialized during the time of declaration itself otherwise it is a compilation eror

Report Error

View Answer Report Error Discuss

Filed Under: Java
Job Role: IT Trainer

0 4017
Q:

Which of the following method declarations are allowed inside interface?

A) public void m1() B) private void m1()
C) protected void m1() D) abstract public void m1()
 
Answer & Explanation Answer: D) abstract public void m1()

Explanation:

Inside an interface every method will be by default abstract and public

Report Error

View Answer Report Error Discuss

Filed Under: Java
Job Role: IT Trainer

0 3941
Q:

What is the difference between Serial and Throughput Garbage collector ?

Answer

The throughput garbage collector uses a parallel version of the young generation collector and is meant to be used with applications that have medium to large data sets. On the other hand, the serial collector is usually adequate for most small applications (those requiring heaps of up to approximately 100MB on modern processors).

Report Error

View answer Workspace Report Error Discuss

Subject: Java

5 3847
Q:

If sub class data member is hiding super class data member then how to access super class data member inside sub class methods?

Answer

use super keyword.


super keyword points immediate super class.


Class Sample {


int a =23;


 }


Class Sub extends Sample { 


 String a = "bablu";


 void show() {


 System.out.println(a); //bablu


 System. out. println(this.a); //bablu


 System. out.println(super.a); //23


}


}


Class Demo {


Public static void main(string[] args) {


sub s = new Sub();


s.show();


}


}


 

Report Error

View answer Workspace Report Error Discuss

Subject: Java

1 3688
Q:

Which of the following statements about inheritance is false?

A) Inheritance allows you to minimize the amount of duplicate code in an application by sharing common code among several subclasses. B) A subclass inherits all the members (fields, methods, and nested classes) from its superclass.
C) Through inheritance, a parent class is a more specialized form of the child class. D) Inheritance allows you to reuse the fields and methods of the super class without having to write them yourself.
 
Answer & Explanation Answer: C) Through inheritance, a parent class is a more specialized form of the child class.

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Java
Job Role: Analyst , Database Administration , IT Trainer

3 3641
Q:

Explain different ways of creating a thread. Which one would you prefer and why ?

Answer

There are three ways that can be used in order for a Thread to be created:


A class may extend the Thread class.


A class may implement the Runnable interface.


An application can use the Executor framework, in order to create a thread pool.


The Runnable interface is preferred, as it does not require an object to inherit the Thread class. In case your application design requires multiple inheritance, only interfaces can help you. Also, the thread pool is very efficient and can be implemented and used very easily.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 3604
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 3574