Java variable Storage Method

Source: Internet
Author: User
Tags visualvm

1. Comparison of Java objects (provided that the equals () and hashcode () Methods of the object are not overwritten)

'=' Compares the reference addresses of two objects. That is, true is returned for the reference addresses of the same object;
'Equal' calls the '=' operator;
The same object must have an equal hash code (or hash code)

Ii. Java memory allocation:

1. Register: we cannot control it in the program
2. STACK: stores basic data and object references, but the object itself is not stored in the stack, but stored in the heap.
3. Heap: store data generated with new
4. static fields: static members defined by static in objects
5. Constant pool: store Constants
6. Non-ram storage: Permanent storage space such as hard disk

Final is only valid for the referenced "value" (that is, the memory address:
Usage and understanding of final in string
Final stringbuffer A = new stringbuffer ("111 ");
Final stringbuffer B = new stringbuffer ("222 ");
A = B; // This sentence cannot be compiled
Final stringbuffer A = new stringbuffer ("111 ");
A. append ("222"); // compiled

The intern method of the string object is described as follows:
Public class test4 {
Private Static string a = "AB ";
Public static void main (string [] ARGs ){
String S1 = "";
String S2 = "B ";
String S = S1 + S2;
System. Out. println (S = A); // false
System. Out. println (S. Intern () = A); // true
}
}
Java is used here as a constant pool problem. For the S1 + S2 operation, a new object is actually created in the heap, and s stores the content of the new object in the heap space, the values of S and a are not equal. When the S. Intern () method is called, the address value of S in the constant pool can be returned. Because the value of A is stored in the constant pool, the values of S. intern and a are equal.

3. How to change the JVM memory size
Java-xms100m-xmx250 memory

The JVM is independent of the platform and has different available memory sizes on different platforms. You can use the following command to view the maximum memory available for JVM on a specific platform:
Java-xmx * m-version (where * is the maximum memory value)
If the following figure is displayed, the heap memory is available:
Java version "1.5.0 _ 06"
Java (TM) 2 Runtime Environment, Standard Edition (build 1.5.0 _ 06-b05)
Java hotspot (TM) server VM (build 1.5.0 _ 06-b05, mixed mode)
If the following figure is displayed, the heap memory exceeds the system limit:
Error occurred during initialization of VM
Cocould not reserve enough space for object heap
Cocould not create the Java Virtual Machine.
By default, the maximum available heap memory value in Windows is 1800 MB, and that in Linux is 2600 MB.

Meanings of parameters:
-XMS: the initial size of Java heap. The default value is 1/64 of the physical memory.
-Xmx: maximum value of Java heap. We recommend that you set it to half of the physical memory. The physical memory cannot exceed.
-XX: permsize: Set the initial size of the permanent memory storage area. The default value is 64 MB. (I used visualvm.exe to view)

-XX: maxpermsize: sets the maximum size of the permanent memory storage zone. The default value is 64 MB. (I used visualvm.exe to view)

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.