Basic Java Language: Difference between revisions

No edit summary
wikademia>Mirwin
m →Statements: edit phrasing a little add a little
Line 62: Line 62:


==Statements==
==Statements==
A statement in Java is generally a line of code that does something. Statements are ended by a semicolon ;. An example of a statement is the declaration of a variable like we saw before. Another example you will recall from the "Hello World" program we made in Lesson 1.  
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;
 
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.
 
Another example you will recall from the "Hello World" program we made in Lesson 1.  
<pre>System.out.println("Hello World");</pre>
<pre>System.out.println("Hello World");</pre>
This line of code prints ''Hello World'' onto the console.
This line of code prints ''Hello World'' onto the console.
A third example
if (myShip.speed<10) then mShip.mainThrustPulse(2);
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.
==Comments==
==Comments==
Comments are notes that the developer can insert into their code. This allows the developer to keep track of their code and helps when developers are collaborating on a project. It is good to write a summary of the following code at the beginning of your methods, classes, etc. The Java compiler completely ignores comments, so you can say anything in them
Comments are notes that the developer can insert into their code. This allows the developer to keep track of their code and helps when developers are collaborating on a project. It is good to write a summary of the following code at the beginning of your methods, classes, etc. The Java compiler completely ignores comments, so you can say anything in them