| Declaring and assigning variables |
| Integers |
| Floating point types |
| Other |
| Constants |
| Strings |
Declare variables:
int myInteger;
char ch;
Assigning variables:
ch = 'Y';
Declaration and assignment can be done at the same line:
int i = 10;
| int | 4 bytes | -2,147,483,648 to 2,147,483,64 |
| short | 2 bytes | -32,678 to 32,767 |
| long | 8 bytes | 9,223,372,036,854,775,808L to 9,223,372,036,854,775,807L |
| byt | 1 byte | -128 to127 |
| float | 4 bytes | 6-7 significant digits |
| double | 8 bytes | 15 significant digits |
| char | Note that single quotes are used to denote char constants. 'H' is a char, "H" is a string. |
| boolean | Has two values: true and false |
Use the keyword final to denote a constant:
final double myConstanmts = 2.45;
A constant can be defined as a class constant so that it is vailable to all methods inside the class. Class constants are defined as static final:
public static final double myCon = 8.57;
Note that strings are not a built in dadat type. Instead the standard java library contains a predefined String class.
String e = "";
String hallo = "Hallo world";
| Converted from CHM to HTML with chm2web Standard 2.7 (unicode) |