Java 7 New features

The following are some of the new feautres in Java 7 (SE 7) Programming language

1.) Strings can be used in Switch Statements, for example

         public static void main(String[] args) {
                               
                String str = args[0];
                switch(str)
                {
                case "one":
                        System.out.println("The String represents number 1");
                        break;
                case "two":
                        System.out.println("The String represents number 2");
                        break;
                        default:
                                System.out.println("Not a valid string");
                }
        }

       

2.) Underscore can be used in numberic values

    int num = 1_000;
    double num1 = 1_000_00.00;
   

3.) Catching multiple exceptions

        public static void main(String[] args) throws Exception {
               
               
                try
                {
                        //your code here
                }
                catch(FileNotFoundException|IndexOutOfBoundsException e)
                {
                        throw e;
                }
        }

   

Technology: 

Search