Basic Java Concepts

Source: Internet
Author: User

A, JVM and JDK concept Description:

1.JVM is a Java virtual machine, and all Java programs are shipped in a Java virtual machine.

2.JDK is the Java SDK for developing Java programs, the core of Java, including the Java Runtime Environment, Java tools, and the Java base Class library

There is a compiler in 3.JDK that compiles your Java source code into bytecode (intermediate code) that can run on a virtual machine (JVM).


Ii. conceptual differentiation of heap and stack

1.heap is a heap and stack is a stack.

2.heap of space is manually applied and released, and the heap is often assigned with the New keyword. Stack space is automatically allocated and freed by the operating system.

3.heap of space is a large free zone, stack space is limited. In Java, if you just declare an object, it is assigned an address space in the stack memory, and if you instantiate it again, it is assigned an address in heap memory.

Declaring objects (allocating address space on the stack) = = = (allocating address space in heap heap)

4. Example: data type variable name; So define something in the stack area. such as: Object a =null; Allocate space only in stack memory

New data type (), or malloc (length); Something like this is defined in the heap area such as: Object B =new Object (); Allocates space in heap memory

5. Object-and stack-oriented relationships: When we take the object apart, you will find that the object's properties are actually data, stored in the heap, and the object's behavior (method) is run logic, put in the stack. When we write the object, we write the data structure, and we write the logic to deal with it.

6. The object is stored in the heap. The stack is a reference to the base data type and the objects in the heap. The size of an object is not estimated, or can be dynamically changed, but in the stack, an object only corresponds to a 4byte reference (the benefit of stack separation).


The heap of the JVM

The JVM heap setting is the set of memory space that the JVM can provision during the run of the Java program. The JVM automatically sets the value of the heap size when it starts, and its initial space (that is,-XMS) is 1/64 of the physical memory, and the maximum space (-XMX) is 1/4 of the physical memory. You can use options such as the-XMN-XMS-XMX provided by the JVM to set it up. For example: java-jar-xmn16m-xms64m-xmx128m Myapp.jar If the heap size setting is small, in addition to these exception information, you will find that the program's responsiveness slows down. The Heap Size does not exceed 80% of the available physical memory, generally the-XMS and-XMX options are set to the same, the wiki is set to-xms30g-xmx30g, and the physical memory is 96G


Third, garbage collection (GC)

GC often occurs in the area of the heap, the heap can be subdivided into the new generation, the old age, the Cenozoic is also divided into a Eden area and two survivor area.

1.1 Object precedence is allocated in Eden, and when there is not enough space in Eden, the virtual machine will have a minor GC, because most of the objects in Java are going to be born out, so the minor GC is very frequent and fast;

1.2 Full GC, which occurs in the old GC, when there is not enough space in the old age to occur when full GC occurs, a full GC will generally have a minor GC. Large objects directly into the old age, such as a long string array, the virtual machine provides a-xx:pretenuresizethreadhold parameter, so that the object is larger than the value of this parameter is allocated directly in the old age, to avoid a large number of memory copies in the Eden area and two survivor areas;

1.3 When the minor GC occurs, the virtual opportunity detects whether the average size of each promotion to the old age is greater than the remaining space size of the old age, if it is greater than the full GC, and if it is less than the Handlepromotionfailure setting, whether to allow the guarantee to fail, If allowed, it will only be performed once minor GC, if not allowed, then a full GC


Reference: https://zhidao.baidu.com/question/1864149247064670867.html

Https://zhidao.baidu.com/question/1864149247064670867.html

Basic Java Concepts

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.