Variables and Data Types (JAVA III)

Names are important in programming techniques. In a program, the name used to refer to something. To use "something" is, the programmer must understand how the rules of nomenclature and rules for using that name in the program. Or in other words, the programmer must understand the syntax and semantics of the name.

According to the rules of Java syntax, the name is a series of 1 or more characters. It should begin with the letter and must consist of letters, numbers or the underscore character '_'. The following are examples of names that are allowed:

N n rate X15 quite_a_long_name HelloWorld

Hurus small and large letters are considered different, so the HelloWorld, HelloWorld, HelloWorld, and HelloWorld is the name different. Some of the particular word is a name that has a specific purpose by Java, and can not be used by programmers. These words are called reserved words (words reserve) for example: class, public, static, if, else, while, and others.

Another important thing is to compound names or the name of the mixture, ie which is the common name associated with a point, such as System.out.println. The idea is "something" in Java can consist of "something" else. System.out.println Name System means to accommodate out and out to accommodate println. We call that "something" as an identifier (ID) do not care if he is single or mixed form of the name.

Programs manipulate data stored in memory. In the language of machines, data can only be retrieved by calling the address in memory. In the high-level programming languages such as Java, the name can be used Untk change of address data in memory. Computer task is to track where data is stored, while the programmer to use names to instruct the computer retrieve data from memory. The name used is called a variable.

Variables actually mean more complex. Variables not the contents of the data, but the location in memory that stores data. Variables can be described as data storage box, not the contents of the box. Because the data within the box can be changed, the variable can only be trusted at one point only, although the place is always the same.

In the Java language, the only way to enter data into a variable is to use an assignment statement, or statement of value. This statement is in the form:

variable = expression;

where the expression of any claim relating to a data value. When a computer running this instruction, the computer will calculate and store the result into a variable. Example:

speed = 40;

Variable in the above statement is the speed and its expression is the number 40. Computers calculate this statement and saves 40 to the variable speed, and replace any that have been stored previously.

Now for example we want to perform more complex calculations:

distance = speed * time

Here, * is the multiplication operation. Computers take the data stored in variable speed and time, do the multiplication, and stores the result in the distance.

Variables in the Java language designed to store only 1 type data type. Compiler will display an error if the variable sintax is attempted to be given other kinds of data types. Therefore, the Java programming language type is called a strong or a strongly typed language.

There are 8 primitive data types in the Java language.
Type Maximum Minimum Size Description
boolean 1-bit true or false can contain
char 16-bit Unicode character
byte 128 -127 8-bit Integer
Short 32 767 -32 768 16-bit Integer
int 2,147,483,647 -2,147,483,648 32-bit Integer
Long -9223372036854775808 9223372036854775807 64-bit Integer

float 32-bit real number 1.40129846432481707e-45 3.40282346638528860e +38
double 64-bit real number 4.94065645841246544e +308 1.79769313486231570e-324

A new variable can be used if it has been declared. Variable declaration statement used to declare one or more variables and give names. When the computer executes the variable declaration, the computer will provide a room at the memory and then stores these addresses in accordance with the given variable name. Shaped like a variable declaration:

nama_tipe nama_variabel;

nama_variabel can be a variable name or several names at once separated by commas. Good programming style is to declare a variable in one statement, except those variables closely related to each other. For example:

float num;
String name;
String name;
boolean bol;
int x, y;

Or declaring variables can also be done at once by giving its value, as in the following example:

int num = 1000;
char ch = 'e';
float number = -1504;
boolean bol = true;

Variable Types

Java has several types of variables that can be grouped as follows:

* Instance Variables (not static). In object-oriented programming language, object store are not variables declared with the static keyword in the category of non-static, or may be fickle. A class can dijelmakan into several objects. Values contained in the non-static variables is different for each object.
* Class Variables (static). This variable is an integral part of a class, and no one objects to any claim of ownership over these variables. Variables that are declared as static is shared by all objects. This global variable whose value is more similar to each object in the class concerned.
* Local Variables. This variable is defined in a method (method) or in a procedure. This variable is local because it can only be accessed by any method or procedure.
* Parameter. Parameter or argument is a variable that is used when a method or procedure is invoked. Parameter is useful to give initial values to be transmitted (pass) into a procedure or method.
2 Komentar untuk "Variables and Data Types (JAVA III)"

What a great informative post for those who are learning programming! You did great job by creating this post. I would like to share this post to others. Keep posting!

Back To Top