Home  >  Article  >  Java  >  Java Basics Introduction Essay (6) JavaSE Edition

Java Basics Introduction Essay (6) JavaSE Edition

黄舟
黄舟Original
2016-12-22 13:04:591350browse

1. Array

Concept: a collection of data of the same type. In fact, an array is a container.

Benefits: The elements in the array can be automatically numbered starting from 0, making it easier to operate these elements.

 Format:

 ①. Element type [] array name = new element type [number of elements or array length]; Example: int[] arr = new int[5];

 ②. Element type [] array name = new element type []{element, element,....}; Example: int[] arr = new int[]{3,5,1,7}; or int[] arr = {3,5,1 ,7};

 Common exceptions:

 ①.ArrayIndexOutOfBoundsException: //This exception occurs when an index that does not exist in the array is accessed.

 ②.NullPointerException: //When the reference variable does not have any entity pointing to it, it is still used to operate the entity. This exception will occur.

 ③.[I@c17164 //Hash number address, the front part of @ represents an integer array.

Appendix 1:

Division of memory:

1. Register.

 2. Local method area. (Related to the system)

 3. Method area.

 4. Stack memory.

   What is stored are local variables, and once the scope to which the variable belongs ends, the variable will be automatically released.

 5. Heap memory.

  Storage is arrays and objects (in fact, arrays are objects). All new is created in the heap.

  Features:

  1. Each entity has a first address value.

  2. Every variable in the heap memory has a default initialization value, which varies according to the type. The integer is 0, the decimal is 0.0 or 0.0f, boolean false, char 'u0000'.

  3. Garbage collection mechanism.

The above is the content of Java Basic Introduction Essay (6) JavaSE version. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn