Primitive Datentypen


NameBeschreibungWertebereich
byteThe byte data type is an 8-bit signed two’s complement integer-128 bis 127 (−2⁷ bis 2⁷ − 1)
shortThe short data type is a 16-bit signed two’s complement integer-32.768 bis 32.767
intBy default, the int data type is a 32-bit signed two’s complement integer-2.147.483.648 bis 2.147.483.647
longThe long data type is a 64-bit two’s complement integer-9.223.372.036.854.775.808 bis 9.223.372.036.854.775.807
floatThe float data type is a single-precision 32-bit IEEE 754 floating pointgrößte Zahl: ca. 3,4 · 10³⁸
kleinste positive Zahl: 1,4 · 10⁻⁴⁵
Stellengenauigkeit: ca. 7
doubleThe double data type is a double-precision 64-bit IEEE 754 floating pointgrößte Zahl: ca. 1.8 · 10³⁰⁸
kleinste positive Zahl: 4.9 · 10⁻³²⁴
Stellengenauigkeit: ca. 15
booleanThe Boolean data type has only two possible values: true and false
charThe char data type is a single 16-bit Unicode character\u0000 bis \uffff (0 bis 65535)
varSince Java 10. When initialize, the compiler finds the right Type from the value

Variablentypen


Variablen sind innerhalb geschweifter Klammern ”{}” gültig. Bei gleichem Namen können sie sich nicht überdecken.

final

final int x;

  • Attribut kann nur einmal gesetzt werden.
  • Danach unveränderlich.
  • Bei static final: echte Konstante.

public

public int a;

  • Von überall zugreifbar.
  • Klassen, Pakete, Vererbung: egal.
  • Wird sparsam verwendet, meist für APIs oder Konstanten.

private

private int b;

  • Nur innerhalb derselben Klasse sichtbar.
  • Standard für Attribute.
  • Zugriff von außen nur über Getter/Setter.

protected

protected int c;

  • Sichtbar:
    • innerhalb derselben Klasse
    • innerhalb desselben Pakets
    • in Unterklassen (auch in anderen Paketen)
  • Wird bei Vererbung genutzt.

static

public static int d;

  • Gehört zur Klasse, nicht zum Objekt.
  • Es gibt nur eine gemeinsame Variable für alle Instanzen.
  • Zugriff über Klassenname.attribut.