Basic Java Language: Difference between revisions

wikademia>Cremisis13
m →Comments: Minor Edit - REmoval of -s
wikademia>Cremisis13
Line 165: Line 165:


You can't create two variables with the same identifier, all identifiers must be unique. You also can't use an identifier that is a Java keyword. Here is a list of all the [http://en.wikipedia.org/wiki/Java_keywords Java Keywords].  [[Flashcards for Java keywords]] provides some assistance in memorizing the concepts behind specific keywords.
You can't create two variables with the same identifier, all identifiers must be unique. You also can't use an identifier that is a Java keyword. Here is a list of all the [http://en.wikipedia.org/wiki/Java_keywords Java Keywords].  [[Flashcards for Java keywords]] provides some assistance in memorizing the concepts behind specific keywords.
=Using the Displayer with Variables=
This section is about printing to the console using <code>System.out.println();</code>.
For Strings, it is extremely simple:
<code>System.out.println(STRING IDENTIFIER HERE);</code>
But for other variables, you have to do it like this:
<code>System.out.println(VARIABLE IDENT + "")</code>
This is because that method's parameter requires a string, and to change a variable to a string you say +"". Note that this only works on primitive types. On objects you have to have a method toString(). (You will read more).
Example:
<code>System.out.println(54 + "")</code>
You can also do multiple variables on the same line:
<code>System.out.println(false + 54 + "")</code>
You can put it anywhere: <code>System.out.println(false + "" + 54)</code>
Note that this won't work for two number values:
<code>System.out.println(54 + 32)</code>. It would mistake it for the adding operator for values. For strings, the operator is different. So you would have to do: <code>System.out.println(54+""+32)</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