Primitive Datentypen
| Name | Beschreibung | Wertebereich |
|---|---|---|
| byte | The byte data type is an 8-bit signed two’s complement integer | -128 bis 127 (−2⁷ bis 2⁷ − 1) |
| short | The short data type is a 16-bit signed two’s complement integer | -32.768 bis 32.767 |
| int | By default, the int data type is a 32-bit signed two’s complement integer | -2.147.483.648 bis 2.147.483.647 |
| long | The 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 |
| float | The float data type is a single-precision 32-bit IEEE 754 floating point | größte Zahl: ca. 3,4 · 10³⁸ kleinste positive Zahl: 1,4 · 10⁻⁴⁵ Stellengenauigkeit: ca. 7 |
| double | The double data type is a double-precision 64-bit IEEE 754 floating point | größte Zahl: ca. 1.8 · 10³⁰⁸ kleinste positive Zahl: 4.9 · 10⁻³²⁴ Stellengenauigkeit: ca. 15 |
| boolean | The Boolean data type has only two possible values: true and false | |
| char | The char data type is a single 16-bit Unicode character | \u0000 bis \uffff (0 bis 65535) |
| var | Since 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.