Basic Java Language: Difference between revisions

wikademia>MetaBohemian
m →Assignment Operator '=': clarified char literals, reworded float/double
wikademia>MetaBohemian
→Valid Identifiers: added reserved words table
Line 186: Line 186:


=Valid Identifiers=
=Valid Identifiers=
There are several rules for the naming of your variables. Identifiers can be named using all the letters from A through Z (capital or lowercase, you choose), numbers 0-9 and underscore _ and the dollar sign $. The first character of the identifier cannot be a number, but it can be a letter, _ or $.  
There are several rules for the naming of your variables. Identifiers can be named using all the letters from A through Z (capital or lowercase, you choose), numbers 0-9 and underscore _ and the dollar sign $. The first character of the identifier cannot be a number, but it can be a letter, _ or $. Identifiers can be no longer than 32 characters.
 
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, listed below. [[Flashcards for Java keywords]] provides some assistance in memorizing the concepts behind specific keywords.
 
<div align=center>
{| class="wikitable"
| <code>abstract</code>
| <code>assert</code>
| <code>boolean</code>
| <code>break</code>
| <code>byte</code>
| <code>case</code>
|-
| <code>catch</code>
| <code>char</code>
| <code>class</code>
| <code>const</code>
| <code>continue</code>
| <code>default</code>
|-
| <code>else</code>
| <code>enum</code>
| <code>extends</code>
| <code>false</code>
| <code>final</code>
| <code>finally</code>
|-
| <code>float</code>
| <code>for</code>
| <code>goto</code>
| <code>if</code>
| <code>implements</code>
| <code>import</code>
|-
| <code>instanceof</code>
| <code>int</code>
| <code>interface</code>
| <code>long</code>
| <code>native</code>
| <code>new</code>
|-
| <code>null</code>
| <code>package</code>
| <code>private</code>
| <code>protected</code>
| <code>public</code>
| <code>return</code>
|-
| <code>short</code>
| <code>static</code>
| <code>strictfp</code>
| <code>super</code>
| <code>switch</code>
| <code>synchronized</code>
|-
| <code>this</code>
| <code>throw</code>
| <code>throws</code>
| <code>transient</code>
| <code>true</code>
| <code>try</code>
|-
| <code>void</code>
| <code>volatile</code>
| <code>while</code>
|
|
|
|}
</div>
 
Identifiers should also be meaningful, while maintaining practicality. If calculating the sum of a set of numbers, <code>sum<code> is better than <code>cumulativeTotal</code>, but <code>s</code> might be too short.


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=
=Using the Displayer with Variables=
This section is about printing to the console using <code>System.out.println();</code>.
This section is about printing to the console using <code>System.out.println();</code>.