An Chanda

+ Follow
since Mar 30, 2015
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by An Chanda

Question is : Which can appropriately be thrown by a programmer using Java SE technology to create a desktop application?

Solution can be obtained by analyzing the existing classes.

1. NoClassDefFoundError
Any errors which are subclasses of Error should not be thrown programmatically. They are handled by JVM and Exceptions can only be handled by a programmer .

2. NullPointerException
Ex: consider the code
ArrayList<Integer> a=null;
a.add(1); // throws NullPointerException

If we analyze the code present in ArrayList.add, we don't find the method throwing NullPointerException. Similarly we don't find ClassCastException and ArrayIndexOutOfBoundsException exceptions are also not thrown explicitly in the existing Oracle JDK classes. Reason is JVM takes care of throwing the appropriate exception in such scenarios.

3. ArrayIndexOutOfBoundsException
String[] s=new String[1];
s[2]="abc"; // throws ArrayIndexOutOfBoundsException, But there is no declaration in String class

ArrayList<Integer> a=new ArrayList<Integer>();
List<Integer> list=a;
LinkedList<Integer> l=(LinkedList<Integer>)list; // throws ClassCastException, But no declaration in LinkedList class

5. NumberFormatException
double val = Double.parseDouble("abc");
Double.parseDouble explicitly throw NumberFormatException if the format of the string is unexpected.

//Following is the syntax of Double.parseDouble method
public static double parseDouble(String s) throws NumberFormatException {
return FloatingDecimal.parseDouble(s);

So the answer is NumberFormatException.
Is there any way to get discount vouchers for OCPJP 1z0-851 certification (Oracle Certified Java Professional 6 exam ).