In this article, we will discussComplex data types in Java. The content involves the initialization process, default initial values, and some operations on complex data types.
Index
Similar to the definition of a simple data type, the Java Virtual Machine (JVM) also defines the index data type. The index type can be a reference variable. Because Java does not explicitly define the pointer type, the index type can be considered as a pointer to the actual value or to the actual value represented by the variable. An object can be referred to by more than one index ". The JVM never directly addresses the object but operates on the index of the object.
There are three types of indexes: class, interface, and array ). The index type can reference dynamically created class instances, common instances, and arrays. An index can also contain special values. This is a null index. The null index does not have a corresponding type at runtime, but it can be converted to any type. The default value of the index type is null.
Class
Class refers to the data type that defines methods and data. Internally, JVM usually implements class objects as a set of pointers pointing to methods and data. Variables defining the class type can only reference the class instance or null, as shown in the following code:
MyObjectAnObject = new MyObject ();// Valid
MyObjectAnotherObject = null;// Valid
MyObjectStillAnotherObject = 0;// Invalid
Interface
An interface is like a template. This template defines the methods that an object must implement, so that these methods can be referenced as interface instances. The interface cannot be instantiated. Class can implement multiple interfaces and are indexed through these interfaces. Interface variables can only be indexed to instances of classes that implement this interface. For example, if we define an interface named Comparable and a SortItem class which implements the interface Comparable, we can write the following definition code:
Comparable c = new SortItem ();
If the Comparable interface defines a method: public void compare (Comparable item), The SortItem class must provide the compare method implementation, as shown in the following code:
Public class SortItem implements Comparable
{
Public void compare (Comparable item)
{
... Method implementation here
}
< p><>