There are two types of variables. Primative data types and classes/objects. Primative datatypes are treated slightly differently to classes. In order to treat them more like classes you have to use a wrapper class but we will come onto that later!

The primative data types you can use are -

Type
Java shorthand
Range
Size
Example
Integer int -2,147,483,648 to 2,147,483,647 4 8
Long integer long -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 8 8,033,321,23
float float

1.40129846 x 10 ^ -45 to

3.40282366 x 10 ^ 38

8 6.4
double double

4.94065 x 10 ^ -324 to

1.79769 x 10 ^ 308

16 93.98321
boolean boolean true / false

1

false
character char single letter 1 g

When you create a variable you must decide on what type of data it will store up front. This choice is very important as if you try and store a number that is too big or compare different types together you will get errors.

Remember Java can not compare different data types!

next converting types >>

 
Basics
Menu
Search