Java - (Data Type|Type)

1 - About

data type in the java world.

The Java programming language is statically-typed, which means that all variables must first be declared before they can be used.

3 - Type

The language supports four kinds of types:

The first three are known as reference types. Class instances and arrays are objects; primitive values are not.

4 - Glossary

4.1 - Supertype

A supertype is a class that is extended by an other class. See Java - (Inheritance|Class Hierarchy) - (Subclass|Superclass) - (Extends, Super) - ("is a" relationship). This is hierarchic relationship.

In object-oriented terminology, this is called an “is a” relationship.

Example: As:

The following code is allowed:

Object someObject = new Object();
Integer someInteger = new Integer(10);
someObject = someInteger;   // OK
public void someMethod(Number n) { /* ... */ }
someMethod(new Integer(10));   // OK
someMethod(new Double(10.1));   // OK

4.2 - Subtype

Same as supertype but in the other direction.

A Subtype is a class that extends an other class.

4.3 - Interface

Interface are abstract data type. When you define a new interface, you are defining a new reference data type. You can use interface names anywhere you can use any other data type name. If you define a reference variable whose type is an interface, any object you assign to it must be an instance of a class that implements the interface.

As an example, here is a method for finding the largest object in a pair of objects, for any objects that are instantiated from a class that implements Relatable:

public Object findLargest(Object object1, Object object2) {
   Relatable obj1 = (Relatable)object1;
   Relatable obj2 = (Relatable)object2;
   if ( (obj1).isLargerThan(obj2) > 0)
      return object1;
      return object2;

By casting object1 to a Relatable type, the can invoke the isLargerThan method that is define in the Relatable interface.

5 - Well Known

  • BigInteger - 64 bit signed integer (from to -9223372036854775808 to 9223372036854775807)

6 - Documentation / Reference

lang/java/datatype.txt · Last modified: 2017/09/06 20:30 by gerardnico