Java - Native Data Types

About

Java - Native Data Types include :

  • BYTE,
  • SHORT,
  • INT,
  • FLOAT
  • and DOUBLE

Articles Related

Initialization

float[] new_sal = new float[10];

Enum type

An enum type is a type whose fields consist of a fixed set of constants. Common examples include compass directions (values of NORTH, SOUTH, EAST, and WEST) and the days of the week.

Because they are constants, the names of an enum type's fields are in uppercase letters.

In the Java programming language, you define an enum type by using the enum keyword. For example, you would specify a days-of-the-week enum type as:

public enum Day {
    SUNDAY, MONDAY, TUESDAY, WEDNESDAY, 
    THURSDAY, FRIDAY, SATURDAY 
}

Enumerable

Enumerable types include type :

Interface

Using an Interface as a 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;
   else 
      return object2;
}

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

Documentation / Reference

  • Bookmark "Java - Native Data Types" at del.icio.us
  • Bookmark "Java - Native Data Types" at Digg
  • Bookmark "Java - Native Data Types" at Ask
  • Bookmark "Java - Native Data Types" at Google
  • Bookmark "Java - Native Data Types" at StumbleUpon
  • Bookmark "Java - Native Data Types" at Technorati
  • Bookmark "Java - Native Data Types" at Live Bookmarks
  • Bookmark "Java - Native Data Types" at Yahoo! Myweb
  • Bookmark "Java - Native Data Types" at Facebook
  • Bookmark "Java - Native Data Types" at Yahoo! Bookmarks
  • Bookmark "Java - Native Data Types" at Twitter
  • Bookmark "Java - Native Data Types" at myAOL
 
language/java/datatype.txt · Last modified: 2012/03/19 15:21 by gerardnico