Easy-to-ignore Java knowledge points (collation ing)

Source: Internet
Author: User
Tags volatile

As a result of the recent preparation of some written review of the relevant Java knowledge points, can't help feeling: So many years to Java know too little!

1. About the Finally keyword

One of the ibmdeveloperworks has been explained in great detail:

On the depth discrimination of finally statement block in Java

Add to the original idea of designing a finally statement for the Java designer: We can't know when the exception happened, but we need to make sure that it does not matter if it has some critical resources that are handled properly (such as IO streams, database connections, and so on) when the GC reclaims memory.

Error point: The execution mechanism of the finally statement before return

2. Keyword synchronized,volatile,transient

The ①synchronized keyword is a sync keyword that includes two usages: the Synchronized method and the synchronized block of code.

②volatile-Modified member variables force the value of the member variable to be read from shared memory each time it is accessed by a thread. Also, when a member variable changes, the forcing thread writes the value of the change back to shared memory. So at any moment, two different threads always see the same value for a member variable, which can only be used to modify a variable.

The ③transient keyword indicates that the property is not saved when the object is serialized (serialization, persisted). It can only be used to modify variables or constants.

Easy-to-ignore Java knowledge points (collation ing)

Related Article

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.