Aqua Phoenix
     >>  Lectures >>  Java 1  
 

Navigator
   
 
       
   

1.10 Expressions, Assignments, and Operators

Expressions evaluate to values, and are used in assignments or in calls to methods:

Mathematical (result in numerical values)

  • 5 + 4
  • a - 6
  • Math.sqrt(18) * 0.3

Boolean (results in a boolean value)

  • (a > b)
  • ((a == b) && (c > d))
  • (someClass.isValid() == true)

Some special notations exist for incrementing/decrementing:

  • i++ , i-- (in-/decrement by one)
  • i += 10 , i -= 10 , i *= 10 , i /= 10 (shorthand for operating on the variable and re-assigning the value)

In an assignment, values are stored in a location denoted by a name. The left side of an assignment must necessarily denote a memory location denoted by a variable name. The right side of an assignment must be a value:

  • int i = 6
  • double d = Math.sqrt(193)
  • String s = new String("a useful string")

Operators in Java include:

Mathematical: + , - , * , / , % (modulus)

Boolean: && (and), || (or), == (test equality), != (test inequality