Java 7 (Code Name Dolphine ) is a major update to Java that was launched on July 7, 2011 and was made available for developers on July 28 2011.
New Features Java 7:
1. Underscores in Numeric Literals
2. String in switch Statement
3. The try-with-resources Statement
4. Catching Multiple Exception Types and Rethrowing Exceptions with Improved Type Checking
5. Binary Literals
6. Type Interface for Generic Instance Creation
7. Improved Compiler Warnings and Errors When Using Non-Reifiable Formal Parameters with Varargs Methods
1. Underscores in Numeric Literals : Any number of underscore character(_) can appear anywhere between digits in a numerical literal.
Example : To separate groups of digits in numeric literals, which can improve the readability of your code.
long creditCardNumber = 1234_5678_9012_3456L;
float pi = 3.14_15F;
You can place underscore only between digits; you cannot place underscore in the following places;
1. At the beginning or end of a number
Example: int x1 = _ 52; int x2 = 52_ // Invalid
int x3 = 5________6 // ok (decimal literal)
2. Adjacent to a decimal point in a floating point literal
Example: float pi = 3_.1415F ; float pi1 = 3._1415F; // Invalid
3. Prior to an F or L suffix
Example: long socialSecurityNumber = 999_99_9999_L; // Invalid
4. In positions where a string of digits is expected
2. String in switch Statement
The switch statement compares the String object in its expression with the expressions associated with each case label as if it were using the String.equals method;
The comparison of String objects in switch statements is case sensitive
Ex:
public class Example
public static void main(String[] args) {
String dayOfWeekArg = "Thursday" ;
switch (dayOfWeekArg){
case "Monday":
System.out.println("Monday");
break;
case "Tuesday":
System.out.println("Tuesday");
break;
case "Wednesday":
System.out.println( "Wednesday"");
break;
case "Thursday":
System.out.println("Thursday");
break;
case "Friday":
System.out.println("Friday");
break;
case "Saturday":
System.out.println("Saturday");
break;
case "Sunday":
System.out.println("Sunday");
break;
default:
System.out.println("Invalid day of the week");
break;
}
}
}
Reference
Oracle Java SE7
Wikipedia
New Features Java 7:
1. Underscores in Numeric Literals
2. String in switch Statement
3. The try-with-resources Statement
4. Catching Multiple Exception Types and Rethrowing Exceptions with Improved Type Checking
5. Binary Literals
6. Type Interface for Generic Instance Creation
7. Improved Compiler Warnings and Errors When Using Non-Reifiable Formal Parameters with Varargs Methods
1. Underscores in Numeric Literals : Any number of underscore character(_) can appear anywhere between digits in a numerical literal.
Example : To separate groups of digits in numeric literals, which can improve the readability of your code.
long creditCardNumber = 1234_5678_9012_3456L;
float pi = 3.14_15F;
You can place underscore only between digits; you cannot place underscore in the following places;
1. At the beginning or end of a number
Example: int x1 = _ 52; int x2 = 52_ // Invalid
int x3 = 5________6 // ok (decimal literal)
2. Adjacent to a decimal point in a floating point literal
Example: float pi = 3_.1415F ; float pi1 = 3._1415F; // Invalid
3. Prior to an F or L suffix
Example: long socialSecurityNumber = 999_99_9999_L; // Invalid
4. In positions where a string of digits is expected
2. String in switch Statement
The switch statement compares the String object in its expression with the expressions associated with each case label as if it were using the String.equals method;
The comparison of String objects in switch statements is case sensitive
Ex:
public class Example
public static void main(String[] args) {
String dayOfWeekArg = "Thursday" ;
switch (dayOfWeekArg){
case "Monday":
System.out.println("Monday");
break;
case "Tuesday":
System.out.println("Tuesday");
break;
case "Wednesday":
System.out.println( "Wednesday"");
break;
case "Thursday":
System.out.println("Thursday");
break;
case "Friday":
System.out.println("Friday");
break;
case "Saturday":
System.out.println("Saturday");
break;
case "Sunday":
System.out.println("Sunday");
break;
default:
System.out.println("Invalid day of the week");
break;
}
}
}
Reference
Oracle Java SE7
Wikipedia
No comments:
Post a Comment