Java Questions

Q:

Convert the expression ((A + B) * C – (D – E) ^ (F + G)) to equivalent  Postfix notations.

A) AC + B * DE - FG +^- B) AB + C * DE - FG + ^-
C) AC + B* DE - FG -+ ^ D) AB + C * DE - FG -+ ^
 
Answer & Explanation Answer: B) AB + C * DE - FG + ^-

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: Java

4 4335
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 4201
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 4193
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 4135
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 3972
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 3866
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 3799
Q:

Which of the following are valied?

A) A class can extend any number of classes simulteneously B) A class can implement only one interface at a time
C) A class can extend other class or can implement interface but not both simulteneously D) None of the above
 
Answer & Explanation Answer: D) None of the above

Explanation:

A is wrong because a class can extend nly one class .B is wrong because a class can implement any number of interfaces.C is wronb because both can can be done simulteneously.So, D is correct

Report Error

View Answer Report Error Discuss

Filed Under: Java
Job Role: IT Trainer

1 3743