Java 7 new features quick Scanning

Source: Internet
Author: User

Java 7 is approaching. Here we will first look at some new practical features, so we can understand them in a simple and clear way.

1) switch, you can no longer use integer types, such as the previous steps:
Switch (someint ){
Case 0: Return zerointresult; break;
Case 1: Return oneintresult; break;
Default: return New brokenswitchexception ("Bad integer ");
}

Now we can.
Switch (somestring ){
Case "Bubba": Return bubbastringresult; break;
Case "Sue": Return suestringresult; break;
Default: return New brokenswitchexception ("odd string! ");
}
2) Try Improvement
Previously:
Try {

} Catch (anyexceptionthrownbythatop aetbto ){
// Handle the exception byfm
} Finally {

Try {

} Catch (exception ignored ){

}
}

Previously it was very troublesome. now:
Try (fileoutputstream Fos = new fileoutputstream (File )){

} Catch (anyexceptionthrownbythatop aetbto ){

}

I no longer use finally.

3) combination of multiple try Methods
Previously:
Try {

} Catch (firstsimilarexception FSE ){

} Catch (secondsimilarexception SSE ){

} Catch (exception ex ){
}
Now we can work together:
Try {

} Catch (firstsimilarexception | secondsimilarexception e ){

} Catch (exception ex ){

}

4) Simplified writing
Previously:
Map <integer, list <string> AMAP = new hashmap <integer, list <string> ();

In Java 7, you can:
Map <integer, list <string> AMAP = new hashmap <> ();

5) Clear long display
Previously:
Long creditcard = 5440444033300005l;
Long phonenumber = listen 5551212l;
Clear statement:
Long creditcard = 5440_4440_3330_0005l;
Long phonenumber = maid;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.