Basic Java Language: Difference between revisions
wikademia>Historybuff →Variables: Removed "worry about" statement, reworded. |
wikademia>Historybuff m →Declaring Variables: made prototype consistent |
||
| Line 63: | Line 63: | ||
To declare a variable, use this syntax: | To declare a variable, use this syntax: | ||
<pre> | <pre> | ||
[ | [protection] [classname] [identifier] | ||
</pre> | </pre> | ||
This is one type of statement. The class name is the type of variable you want. Currently, you will only use basic primitive variables, but you will learn about objects soon. Here is an example of declaring a variable: | This is one type of statement. The class name is the type of variable you want. Currently, you will only use basic primitive variables, but you will learn about objects soon. Here is an example of declaring a variable: | ||
| Line 70: | Line 70: | ||
</pre> | </pre> | ||
myInt has protection of public. It is of class int, or Integer (see Primitive Types). int is a class in Java. When you say that, you are basically making a primitive object. | myInt has protection of public. It is of class int, or Integer (see Primitive Types). int is a class in Java. When you say that, you are basically making a primitive object. | ||
==Primitive Data Types== | ==Primitive Data Types== | ||
Primitives are the simplest type of data. Primitives consist of numbers, letters and strings of letters (more than one letter in one variable). The following table shows all the types of primitives. | Primitives are the simplest type of data. Primitives consist of numbers, letters and strings of letters (more than one letter in one variable). The following table shows all the types of primitives. | ||