Prev Main Next

Independence from Context

Java is a much simpler language than English, or any other natural language. There are simple rules, and simple ways of combining things. It is important not to make things more complicated than they really are.

As you read these notes, remember the following rules.

  1. In almost all contexts, if you can write an expression in a particular place, then you can write any expression there, as long as the type of thing that the expression produces is right for the way in which it is being used. You are not required to use especially simple expressions. Feel free to write larger expressions when they help.

    The same is true for statements. If you can write a statement in a particular place, then you can write any statement there.

  2. What you get from a statement or expression does not depend on where you write it, except for one important issue. Each component of a Java program has its own variables, and all statements or expressions within a component refer to that component's variables, not some other component's variables.

    For example, expression (2/3) evaluates to 0, regardless of where you write it, or what is surrounding it.


Prev Main Next