Java Units API
Build 2004-02-06

Class BaseUnit

  extended byUnit
      extended byBaseUnit
All Implemented Interfaces:

public class BaseUnit
extends Unit

This class represents the building blocks on top of which all others units are created.

Base units are mutually independent; although some implementation may support conversions between base units by allowing the dimensional unit of a base unit to be changed (ref. optional operation: setDimension(javax.units.Unit, javax.units.Converter)).

Examples of base units:

         METER = BaseUnit.getInstance("m");
         KILOGRAM = BaseUnit.getInstance("kg");
         SECOND = BaseUnit.getInstance("s");
         AMPERE = BaseUnit.getInstance("A");

See Also:
Serialized Form

Field Summary
Fields inherited from class Unit
Constructor Summary
protected BaseUnit(String symbol)
          Creates a base unit with the specified symbol.
Method Summary
 boolean equals(Object that)
          Indicates if this unit is equal to the object specified.
 Unit getBaseUnits()
static BaseUnit getInstance(String symbol)
          Returns the base unit with the specified symbol.
 String getSymbol()
          Returns the symbol for this base unit.
 Unit getSystemUnit()
          Returns the system unit for this unit.
 void setDimension(Unit unit, Converter toDimension)
          Optional operation: Sets the dimensional unit of this base unit.
Methods inherited from class Unit
add, alternate, appendTo, divide, getConverterTo, getDimension, getInstance, getInstances, hashCode, isCompatible, isSystemUnit, multiply, multiply, pow, readResolve, root, searchSymbol, toString, valueOf
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait

Constructor Detail


protected BaseUnit(String symbol)
Creates a base unit with the specified symbol.

symbol - the symbol of this base unit.
Method Detail


public static BaseUnit getInstance(String symbol)
Returns the base unit with the specified symbol. If the base unit does not already exist, then it is created.

symbol - the base unit symbol.
the corresponding base unit.
IllegalArgumentException - if the specified symbol is currently associated to a different type of unit.


public final String getSymbol()
Returns the symbol for this base unit.

this base unit's symbol.


public void setDimension(Unit unit,
                         Converter toDimension)
Optional operation: Sets the dimensional unit of this base unit. By default a base unit's dimension is itself. It is possible to set the dimension to any other unit. The only constraint being that distinct dimensional units should be independent from each other (e.g. if the dimensional unit for meter is "ns", then the dimensional unit for second should be "ns" as well). For example:
                           new MultiplyConverter(1e9 / c));
                            new MultiplyConverter(1e9));
     // In this high-energy context, length and time are compatible,
     // they have the same "ns" dimensional unit.

Note: Changing the dimensional units, makes possible conversions otherwise prohibited (e.g. conversion between meters and seconds in a relativistic context).

unit - the unit identifying the new dimension of this base unit.
toDimension - the converter to the specified dimensional unit.
UnsupportedOperationException - if this operation is not supported by this implementation.


public Unit getSystemUnit()
Description copied from class: Unit
Returns the system unit for this unit. The system unit identifies the nature of the quantity being measured using this unit.

Note: Having the same system units is not sufficient to ensure that a converter exists between the two units (e.g. °C/m and K/m).

Specified by:
getSystemUnit in class Unit
the system unit for this unit.
See Also:


public boolean equals(Object that)
Description copied from class: Unit
Indicates if this unit is equal to the object specified. Units are unique and immutable, therefore users might want to use == to test for equality.

Specified by:
equals in class Unit
that - the object to compare for equality.
true if this unit and the specified object are considered equal; false otherwise.


public Unit getBaseUnits()

Java Units API
Build 2004-02-06

Symbols, terms and definitions
JSR-108 project