Basic Java Language: Difference between revisions

wikademia>Cremisis13
wikademia>Cremisis13
Line 130: Line 130:
int a = 6;
int a = 6;
</pre>
</pre>
However, you can't say <code>char myChar = y;</code> to set a character to 'y'. You have to use ' ' for characters. That is: <code>char myChar = 'y';</code>. For Strings, use " ". That is: <code>String myString = "This is an example of a string"</code>. Note how characters are just 1 and strings can consist of entire words.
Finally, what is the difference between double/float and int/long. Well, doubles and floats can have decimals: <code>float myFloat = 5.1;</code>
Now, why would you want to set a variable? For further use, ie, to access at a later time. For example, you can do calculations with other operators...


===Addition Operator +===
===Addition Operator +===