File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes general query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "general query" Watch "general query" New topic

general query

gunjan khanuja
Ranch Hand

Joined: Apr 16, 2012
Posts: 37
Which can appropriately be thrown by a programmer using Java SE technology to create
a desktop application?
A. ClassCastException
B. NullPointerException
C. NoClassDefFoundError
D. NumberFormatException
E. ArrayIndexOutOfBoundsException

Please expalin what is the answer and WHY??
Md. Minhajur Rahman
Ranch Hand

Joined: Apr 10, 2012
Posts: 33
Hello gunjan khanuja,
Exception Handling needs to be done depends on your code regardless of desktop or web, mobile or any kind of application software.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Mostly programmers *throws* checked exceptions and jvm *throw* unchecked exception, again ofcourse some time programmer throw unchecked exception. ;) . but programmer is not expected to throw any Errors.
So shortly programmer can throw all the mentioned exception except NoClassDefFoundError
John Jai

Joined: May 31, 2011
Posts: 1776
Technically all the sub classes of Throwable including Error can be thrown using the throw clause. Still as the question asks for 'appropriate', as Seetharaman said Errors are not expected to be handled by the programmer and are thrown for abnormal conditions by the JVM.

If you see the API - Error

A method is not required to declare in its throws clause any subclasses of Error that might be thrown during the execution of the method but not caught, since these errors are abnormal conditions that should never occur.
I agree. Here's the link:
subject: general query
It's not a secret anymore!