Data Types, Operators and Expressions

When a method accepts parameters, we have already seen that the precise data type for each parameter is specified in the method definition. For example, the method declared as:

void Shape.setBorderThickness(int newThickness)
expects to be sent a single parameter which must be of data type int.

Similarly, we have seen that when a variable is declared, the precise data type must be declared. For example, we might declare a variable as:

int myChoice;
If you wish to set the value of such a variable, you can do so with an assignment statement, such as
myChoice = ... ;
so long as the right hand side ("...") is of the proper data type (int).

For each of the above, there are three possible ways in which you can specify the desired int value.


Here, we give a table highlighting the various data types we discussed, as well as the syntax for literals of that type and available operators and precedence order. Details are given in the reading from the text.

Data Type: int double char String boolean
Literals: 5, 23 3.14, 5.0 'A', '@' "How are you?" true, false
Operators
(from high to low precedence):
( )
* / %
+ -
( )
* /
+ -
+ (concatenation) ! ("not")
^ ("xor")
&& ("and")
|| ("or")

We conclude by addressing a handful of other issues related to expressions.
Michael Goldwasser
Last modified: Monday, 02 February 2004