The basic types you should know are: int, double, String, boolean, and char. For structuring data you need to know arrays and how to define a class.
Primitive types | Object types | ||||||||||||||||||||
There are 8 primitive types: boolean (true and false); char (Unicode characters); byte, short, int, and long (integers); float and double (floating point). | Object types are created whenever a class is defined. Object type names start with an uppercase character (eg, String). The most commonly used pre-defined object type is String. | ||||||||||||||||||||
Integers - primitive types | Integers - object types | ||||||||||||||||||||
The integer types byte, short, int, and long are stored
as two's complement, signed binary integers. char, which is technically also
an integer type, is stored as an unsigned binary number.
Expressions are computed as ints, so a cast is needed to store in a smaller type.
Utility methods: Math class. |
The "wrapper" classes correspond to each primitive
integer types: Integer (not Int), Short, Byte, Long.
Objects of these classes are immutable -- they can not be changed
after they are created.
The wrapper classes contain utility methods such as conversions between String and numbers
(eg, Integer.parseInt(s) ),
constants for the min and max values, ... .
Autoboxing. Conversion between the primitive and the wrapper classes is largely automatic as of Java 5. java.math.BigInteger is very useful for arithmetic on unbounded integers. Several other integer classes have limited or special utility: Number, AtomicInteger, and AtomicLong. |
||||||||||||||||||||
Floating-point - primitive types | Floating-point - object types | ||||||||||||||||||||
The floating-point types, float and double, are stored
in IEEE-754 format. Calculations may produce NaN (Not a Number) or +/- infinity.
Calculations are done as doubles, so a cast is needed to store in a float.
Utility methods: Math class. |
The "wrapper" classes correspond to the primitive
floating-point types: Double and Float.
Objects of these classes are immutable -- they can not be changed
after they are created.
The wrapper classes contain utility methods such as conversions between String and numbers
(eg, Integer.parseInt(s) ),
constants for the min and max values, ... .
Autoboxing. Conversion between the primitive and the wrapper classes is largely automatic as of Java 5. java.math.BigDecimal is very useful for arithmetic on unbounded floating-point numbers. Several other integer classes have limited or special utility: Number. |
||||||||||||||||||||
boolean - primitive type | Boolean - object type | ||||||||||||||||||||
boolean is used to store the values true or false.
The storage is unspecified.
Operators: logical, ==, !=, assignment. |
Boolean is a wrapper class for boolean, but it has relatively little utility. | ||||||||||||||||||||
char - primitive types | Character, String, ... - object types | ||||||||||||||||||||
char type is a Unicode character stored as an unsigned number in two bytes
(range 0..65,535 or '\u0000'..'\uFFFF').
char is an integer type.
char literals
|
Character is the wrapper class for char. It contains many very
useful methods for working with characters.
String is the extremely common immutable object type for storing multiple characters. java.util.StringBuilder (as of Java 5) and java.util.StringBuffer (very slightly slower than the equivalent StringBuilder because it's synchronized) are useful for strings that can be changed. java.util.regex.Pattern and java.util.regex.Matcher can be used for regular expression matching as of Java 1.4.. java.util.StringTokenizer is an earlier, and not as general way to break input strings into "tokens". |