Like the definition of simple data types, Java Virtual Machines (JVM) also defines this data type of indexes. The index type can be "reference" variable, since Java does not explicitly define a pointer type, the index type can be considered to point to the actual value or pointing to the actual value representing the variable. An object can be "referred to" than more than one index. JVM never directly address object addressing is an index of operational objects. The index type is divided into three, which are: Class, Interface, and Array. Index types can reference dynamically created class instances, ordinary instances, and arrays. The index can also contain special values, this is the NULL index. NULL index does not have a corresponding type on run, but it can be converted to any type. The default value of the index type is NULL. Class (CLASS) refers to the definition method and data type of data. From the inside, JVM usually implements a Class type object to point to a pointer to the method and data. Defining the variable of the Class type can only reference the instance or null, as shown in the following code: MyObject Anobject = new myObject (); // Legal myObject AnotherObject = null; // Legal myObject stillanotherObject = 0; // illegal interface interface ( Interface is better than a template, which defines methods that objects must be implemented. The purpose is to let these methods can be referenced as an interface instance. The interface cannot be instantiated. Classs can implement multiple interfaces and are indexed by these implementations. Interface variables can only index instances of classes that implement the interface. For example, suppose we define an interface, the name is Comparable, but also defines a class sortItem. This class implements the interface Comparable, then we can write the following definition code: comparable c = new sortItem (); if the Compailable interface definition A method: Public void compare (Comparable Item), the SortItem class must provide the implementation of the Compare method, as shown by the following code: public class sortItem imports comparable {public void compare (Comparable Item) {... method usmentation here} } Array Java array (array) is a dynamically created index object, which is very similar. 5]; int [] anotherintarray = null; arrays are inheritance of the Object class, so that all methods of the Object class can be called called. Array object consists of elements. The number of elements can also be 0, and in this case, the array is empty. All arrays start from 0 to element numbers, which means that the index number of the first element within the array is the number 0. All access to array elements will be checked on running, if you try to use the number less than 0 or greater than the length of the array, arrayindexoutofboundsexception is abnormal and thrown out.
The elements of the array are indexed in the integer value, as shown in the following code: int [] MyintArray = {9, 5, 6}; int = myintArray [0]; int = MyIntArray [1]; int rt3 = MyIntArray [2 ]; The length of the array object is constant. In order to change the length of the array variable, you must create another array and assign a variable, as shown by the following code: int [] MyintArray = {9, 5, 6}; system.out.println ("MyintArray length =" MyIntArray .length); // output result is 3MyintArray = new int [] {3, 6, 4, 2, 8}; system.out.println ("MyintArray length =" MyIntArray.Length); // Output result is 5 Composite Data Type Java Language does not support structural or union data type. Its composite data type is constructed by classes or interfaces, and the class provides a bundled data and method, while limiting access to private data for class. For example, if you use a C language, the car (CAR) can define the structure shown in the following code: struct car {char * model; char * make; int year; engine * engine; body * body; Tire ** Tires The demonstration code above is also implicitly used in the previously defined engine, body (BODY), and tire structure. The Java language is used, and the car is defined as shown in Listing A. The above examples also assume that we have defined Carmodels and Carmakes interfaces and Engine, Body, Tire, DurangoEngine, DuRangObody, and Goodyeartire classes. The initial composite data type of the composite data type is initialized by the code defined in the constructor, and the constructor is called when the category creation function (such as "new" is applied to the class variable. Before the constructor is called, the individual members of the class are initialized to their respective default or explicitly imparted initial values. The program code in List B explained the above process. In the code of the List B, when the instance of myclass is created with the New operator, the constructor public myclass () is called to promote the initialization of the class. The process of initialization is as follows: Declaration "Int Myint;" gives Myint assigned to 0. Declare "AnotherClass AnotherClass;" assigns an default value null for AnotherClass. The declaration in the constructor "Myint = 2;" assigns a value of 2. The predefined composite data type Java language contains a large number of predefined composite data types. One of the String classes belong to a java.lang package. The method provided by the String class performs common string operations, such as Length (), Substring (Int BeginIndex), TouPpercase (), Toolcase (), Equals (), and more. Another commonly used Java composite data type is a VECTOR class that is a Java.util package. The method defined by the VECTOR class performs common operations of the extended object array. For example, add (int index, object element), elementat (int index), ISempty (), and Remove (int index), etc. These are representative examples of a small part of the predefined composite data type. In the later articles we will also discuss the predefined composite data type.