Basic Java Language: Difference between revisions

wikademia>Mirwin
m →Statements: edit phrasing a little add a little
wikademia>Mirwin
m →Statements: fix formatting
Line 64: Line 64:
A statement in Java is a chunk of code that does something specific completely. Statements are ended by a semicolon ;. An example of a statement is the declaration of a variable like we saw before.  
A statement in Java is a chunk of code that does something specific completely. Statements are ended by a semicolon ;. An example of a statement is the declaration of a variable like we saw before.  


private int static numberOfObjectsInstantiated;
<pre>private int static numberOfObjectsInstantiated;</pre>


The above declares a single memory location per class which may be incremented each time an object of that class is instantiated by calling its constructor method.
The above declares a single memory location per class which may be incremented each time an object of that class is instantiated by calling its constructor method.
Line 74: Line 74:
A third example
A third example


if (myShip.speed<10) then mShip.mainThrustPulse(2);
<pre>if (ourShip.speed<10) then ourShip.mainThrustPulse(2);</pre>


The above checks a ship object's speed and if it is less than ten then it commands the ship object to fire two pulses from its main propulsion rockets.  It is a single specific application task completed at the semi-colon when it moves to the next chunk of code.
The above checks a ship object's speed and if it is less than ten then it commands the ship object to fire two pulses from its main propulsion rockets.  It is a single specific application task completed at the semi-colon when it moves to the next chunk of code.