next up previous
Next: Methods Up: The Frightened Freshers Guide Previous: Constructors

Types

Java, like almost every other programming language ever invented, has a great deal of different types that its variables can be. If you are thinking about variables like boxes, then their type is what you are allowed to put into the box. There are a great deal of variable types and a few of the major ones are listed in the table below:

 Type Description
 int Stores whole numbers
 double Stores decimals
 boolean Stores true or false
 char Stores single characters
 String Stores lots of chars

Examples of those above could be 14 (int), 3.14 (double), true (boolean), "h" (char) and "Hello World" (String).

We had the example in the previous section of setting the variable named helloWorld to equal 1. Here are some examples for the datatypes mentioned above. First a note about these variables I've declared them without a public or private on the front which means that they are variables for inclusion in a method, but this comes a tiny bit later on. Dont worry about it :-).


\begin{lstlisting}
int helloWorld;
helloWorld = 59;
\par
double mmmPi;
mmmPi ...
...fString;
howLongsAPieceOfString = ''Twice half its length!'';
\end{lstlisting}

You'll note that these all take the same form of variableName = someValueHere;, this is important to remember! Use a single equals sign for variable assignment. You'll find out the significance of this soon enough...


next up previous
Next: Methods Up: The Frightened Freshers Guide Previous: Constructors
Tom Carlson 2006-01-10