| Previous | Home | Next |
Java Programming Language Changes Highlights (project Coin)
Example
//Binary Literals
****package java7;
public class BinaryLiterals {
byte b = 0b01001001;
short s = 0B00100100;
int x = 0b10010010;
long y = 0B01001001;
}
//Underscores in Numeric Literals
package java7;
public class UnderscoresInNumericLiterals {
short answer = 0b1_0_1_0_1_0;
int twoMonkeys = 0xAFFE_AFFE;
long smallestLong = 0x8000_0000_0000_0000L;
long somePhoneNumber = +49_7031_4357_0L;
double e = 2.718_281_829D;
}
// before java 7 underscores not allows in numeric literals
//Strings in switch Statements
package java7;
public class StringsInSwitch {
public static void main(String[] args) {
String os = System.getProperty("os.name");
// NB: if the string in switch is null, we will see NPE on the next line!
switch (os) {
case "Linux":
System.out.println("Cool!");
break;
case "Windows":
System.out.println("Not so cool!");
break;
default:
System.out.println("Obst?");
break;
}
}
}
//Before JDK 7, only integral types can be used as selector for switch-case statement.
//In JDK 7, you can use a String object as the selector.
Before Java 7
Resources are need to be closed manually. After processing.
In Java 7
It implements autoclosable method.
Close method run automatically.
Need not to close the resources manually.
| Previous | Home | Next |