Operators are things that are used to build expressions between variables, literals and functioncalls, below is the reference for all the operators in Kenya and what the types they operate upon are.
Table 1.1. Kenya Boolean Operators
Operator | Name | Function | Example |
---|---|---|---|
&& | conditional and | boolean and, but only evaluates the second operand if the first one is true |
void main(){ boolean b = false; if( func1() && b ){ /*definatly does not run*/ } } |
|| | conditional or | boolean or, but only evaluates the second operand if the first one is false |
void main(){ boolean a = true; if( a || func2() ){ /*definatly runs*/ } } |
^ | binary xor | the result is binary xor (exclusive-or) of its two boolean arguments |
void main(){ boolean a = true; boolean b = true; if( a ^ b ){ /* definatly does not run */ } } |
! | binary negation | The result is the bianary negation of its argument |
void main(){ boolean a = true; if( !a ){ /* definatly does not run */ } } |
Table 1.2. Kenya Numerical Operators
Operator | Name | Function | Example |
---|---|---|---|
+ | Plus | Adds two numbers, and returns the result |
void main(){ //Prints out 5. int x = 3 + 2; println( x ); } |
- | Subtract | Subtracts two numbers, and returns the result |
void main(){ //Prints out 3 int x = 5 - 2; println( x ); } |
* | Multiply | Multiplies two numbers, and returns the result |
void main(){ //Prints out 6 int x = 3 * 2; println( x ); } |
/ | Divide | Divides two numbers. If both numbers are int's, this does an integer division (i.e. rounds the result), if either is a double, it does a double-precision division |
void main(){ //Prints out 1 int x = 3 / 2; println(x); //Prints out 1.5 double d = 3.0 / 2.0; println(d); } |
% | Modulo | Returns the remainder from dividing two numbers |
void main(){ //Prints out 1 int x = 3 % 2; println( x ); } |
Table 1.3. Kenya Relational Operators
Operator | Name | Function | Example |
---|---|---|---|
< | less than | compares two numeric arguments (char, int, double) and returns binary true if the left-hand argument is less than the right hand argument, or binary false otherwise |
void main(){ int a = 3; double d = 1.0; if( d < a ){ /* this definatly runs */ } } |
<= | less than or equals | compares two numeric arguments (char, int, double) and returns binary true if the left-hand argument is less than or equal to the right hand argument, or binary false otherwise |
void main(){ int a = 3; double d = 1.0; if( d <= a ){ /* this definatly runs */ } } |
> | greater than | compares two numeric arguments (char, int, double) and returns binary true if the left-hand argument is greater than the right hand argument, or binary false otherwise |
void main(){ int a = 3; double d = 1.0; if( d > a ){ /* this definatly does not run */ } } |
>= | greater than or equals | compares two numeric arguments (char, int, double) and returns binary true if the left-hand argument is greater than or equal to the right hand argument, or binary false otherwise |
void main(){ int a = 3; double d = 1.0; if( d >= a ){ /* this definatly does not run */ } } |
In previous versions of Kenya there where friendly versions of '&&', '||' and '!' ( being called 'and', 'or' and 'not' ). These have now been dropped as they are not in java.
All the operators above have the same function in java (except for String equality as noted), however there are a few extra things you can do in java that you can't do in Kenya:
'&' and '|' are not in kenya ( binary operators that definatly evaluate both the left and right hand side of the expression ).
The bitwise operators/versions of '&', '|', '~', '^' are not in Kenya.
The instanceof operator is not in Kenya.
The integer-bitwise shift operators <<, >> and >>> are not in Kenya.