Java 7 was launched on July 7, 2011 and was made available for developers on July 28, 2011. There are a lot of new features added in JDK 7. In this article we will review some of these new Java 7 features with examples.
Project Coin
Project Coin, a central part of Java 7, was described by Darcy [Joseph Darcy,Member of the Oracle Technical Staff] as "a suite of language and library changes to make things programmers do everyday easier".
coin, n. A piece of small change
coin, v. To create new language
Coin - Binary Literal
public class BinaryLiteral { public static void main(String[] args) { //Binary literal starts with 0b int binNum=0b01111110; System.out.println(binNum); } }
Coin - Underscores in Numeric Literals
public class LiteralIimprovement{ public static void main(String[] args) { int intNum = 1_345; long longNum = 2_000_234; int binNum=0b011_111_10; int octNum = 012_74; int hexNum = 0x12_AD_EF; double tax = 1_458.456_45; System.out.println(intNum); System.out.println(longNum); System.out.println(binNum); System.out.println(octNum); System.out.println(hexNum); System.out.println(tax); } }
Coin - String in Switch
public class StringSwitchExample { public static void seasonSelector(String season) { season = season.toLowerCase(); switch (season) { case "winter": System.out.println("It is " + season); break; case "spring": System.out.println("It is " + season); break; case "autumn": System.out.println("It is " + season); break; case "summer": System.out.println("It is " + season); break; default: System.out.println("Invalid input"); } } public static void main(String[] args) { seasonSelector("spring"); seasonSelector("Winter"); } }
0 comments:
Post a Comment