Index

chapter1

chapter2page1

chapter2page2

chapter2page3

chapter2page4

chapter2page5

chapter2page6

chapter2page8

chapter2page9

chapter2page10

chapter2page11

chapter2page12

chapter2page13

chapter2page14

chapter2page15

chapter2page16

chapter2page17

chapter2page18

chapter2page19

chapter2page20

chapter2page21

chapter2page22

chapter2page23

chapter2page24

chapter2page25

chapter2page26

chapter2page27

chapter2page28

chapter2page29

chapter2page30

chapter2page31

chapter2page32

chapter2page33

chapter2page34

chapter3

link one

link one

link one

link one

link one

link one

2.6.1 - Non-Arithmetic Operators

As we have mentioned before, here we will present only assignment and cast operators. The other operators will be presented with their related topics.

2.6.1.1 - Assignment Operator

Java is strong (statically) typed language and all variables and expressions should have a definite type and value in the compilation stage. We should never forget this and we will always define variables before their use.

Definition of a variable is made by an assignment statement, using the assignment operator = . The assignment operator is a dual operand operator which have a single left side operand and a right side operand which will reduce to a single vale with a definite data type. For the assignment operation be successful, the data types of both operands should be the same. An example of a simplest assignment statement is presented below:

int t = 16;

The elements of this assignment statement is beginning from the left, by the data type of the left operand, left operand, assignment operator, right operand and (here hidden) data type of the right operator.

The assignment statement should not be confused with the mathematical equality. The statement above may not be interpreted as t equals to 16 never ever. The meaning of the above assignment statement is an instruction to the computer to store an int type data whose value is 16, to a memory location that can be accessed by the int type variable t.

In the above statement, the data type of the right operand exist, but not explicitly stated. Any integer literal without a type suffix is interpreted as int type by the compiler. Respectively, any real literal without a type suffix is interpreted as a double.

A variable declaration is a special assignment statement in Java. In a variable declaration, the type of the variable, the name of the variable and the initial value of the variable must be stated. An example of the variable declaration is shown below:

package preliminary;

public class VariableDeclaration {

public static void main(String[] args){
 String name = "Eileen";
System.out.println(" Name = " + name);
 } // end main

} //end class VariableDeclaration 

The result of this program :

      Name =  Eileen

We have many things to discuss in the above program. The program is within the user defined preliminary package. This means that the VariableDeclaration.class is inside the folder preliminary.

The assignment statement,

String name = "Eileen";

is a special assignment statement called variable declaration. In Java, all the variables should be declared before use with a variable declaration statement. In a variable declaration statement above, String is the type of the variable, name is the name of the variable, "Eileen" is the initial value of the variable. String variables may be initialised with any String type value or with null, or with an empty string as"". Integer variables may be initialized with any integer value or with 0. Real type variables may be initialised by any real type data or with 0.0.

<< Index

Polyglott HTML5(XHTML5 compliant HTML5 code)