Friday, January 4, 2013

Java 7



Download Link:


Feature added in Java 7:

JDK 7 Installation Procedure in Eclipse:-
-------------------------------------------------------------------------------------------------------
You need to let know eclipse where the JRE 7 is, and you can do in this way :

Go to Preferences pane of eclipse
Open Java on the left pane
Click on Installed JREs
Add Button ---> Standard JVM and Next
Insert : /Library/Java/JavaVirtualMachines/jdk1.7.0_06.jdk/Contents/Home in the JRE Home TextBox
Next and Save the configuration
-------------------------------------------------------------------------------------------------------
Now Run this Code...
--------------------------------------------------

import java.util.Scanner;
public class CatchMultipleException {
public static void main(String args[]) {
   Scanner scnr = new Scanner(System.in);
   System.out.println("Enter a number:");
   String number = scnr.next();
   try {
       if (number.length() > 5) {
          throw new IllegalArgumentException();
       }
       Integer.parseInt(number);
   } catch (NullPointerException | IllegalArgumentException e) {
    if(e instanceof NullPointerException){
    System.out.println("NullPointerException "+e);
    }
    if(e instanceof IllegalArgumentException){
    e.printStackTrace();
    }
      // e.printStackTrace();
   }

// Example #2

int array[] = { 20, 10, 30 };
int num1 = 15, num2 = 2;
int res = 0;
try {
res = num1 / num2;
System.out.println("The result is" + res);
for (int ct = 2; ct >= -1; ct--) {
System.out.println("The value of array are" + array[ct]);
}
} catch (ArrayIndexOutOfBoundsException | ArithmeticException e) {
if (e instanceof ArrayIndexOutOfBoundsException) {
System.out.println("Error?. Array is out of Bounds");
}
if (e instanceof ArithmeticException) {
System.out.println("Can't be divided by Zero");
}
System.out.println("Default Case");
}
}
}
--------------------------------------------------------------------------------------------------------
Sumit Tehanguriya