Basic concepts of Java programming

Source: Internet
Author: User

Jvm

(1) for string: References to objects are stored in the stack, and if the compilation period has been created (defined directly in double quotes), it is stored in a constant pool, which is stored in the heap if the runtime (new) is determined. For a string equal to equals, there is always only one copy in the constant pool, with multiple copies in the heap. For example:
1 string s1 = "China", 2 string s2 = "China", 3 string s3 = "China", 4 string ss1 = new String ("China"); 5 string ss2 = new St Ring ("China"); 6 string ss3 = new String ("China");   

When a string is generated by new (assuming "China"), the constant pool is first searched for whether the "Chinese" object is already in use, and if none is created in the constant pool, then a copy object of this "China" object in the heap is created in a constant pool. This is the way of the interview: string s = new string ("xyz"), how many objects are produced? A: One or two, if there is no "xyz" in the constant pool, it is two. (2) for variables and constants of the underlying type: Variables and references are stored in the stack, and constants are stored in a constant pool. For example:
1 int i1 = 9;2 int i2 = 9;3 int i3 = 9; 4 public static final int INT1 = 9;5 public static final int INT2 = 9;6 public static final int INT3 = 9;

For member variables and local variables: member variables are external to the method, variables defined internally by the class, and local variables are variables defined inside a method or statement block. Local variables must be initialized. The formal parameter is a local variable, and the data for the local variable exists in the stack memory. Local variables in the stack memory disappear as the method disappears. Member variables are stored in objects in the heap and are collected by the garbage collector.

Explanation of examples:

Http://www.cnblogs.com/Eason-S/p/5658230.html

Http://www.jianshu.com/p/c7f47de2ee80

Http://www.cnblogs.com/sunada2005/p/3577799.html

Http://www.cnblogs.com/dingyingsi/p/3760447.html

Java exception mechanism

http://blog.csdn.net/hguisu/article/details/6155636

http://yangshen998.iteye.com/blog/1311682

The difference between final, finally, and finalize

http://blog.csdn.net/lichaohn/article/details/5424519

Basic concepts of Java programming

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.