Variables


Variables

Java and Fortran define a number of types to represent various boolean, character, numerical, and object data. The types supported by the languages are shown in Table 2.1.

Fortran has five intrinsic types. The three numerical types, INTEGER , REAL , and COMPLEX, represent integer, floating point, and complex number values. The LOGICAL type represents a boolean value. It can have values of .TRUE. and .FALSE. with periods on either side of the word. The CHARACTER type represents strings (sequences of characters ).

Table 2.1. Types

F ORTRAN

J AVA

D ESCRIPTION

LOGICAL

boolean

Boolean true or false value

N/A

byte

A single byte of data

N/A

char

A Unicode character

INTEGER

short, int, long

Integer numeric type

REAL

float, double

Floating point numeric type

COMPLEX

N/A

Complex integer or floating point number

CHARACTER

String

A sequence of characters

N/A

reference (object)

A class instance

Java defines more types than Fortran. Java has three integer types ” short , int , and long , representing 16-, 32-, and 64-bit integer values. Java supports two floating point data types. The float type is single precision. The double type is double precision. Java supports the byte and char types that Fortran does not. On the other hand, Java does not have a complex number type. The Java String class represents a sequence of characters. The reference type represents an instance of a Java class or array.

Java is a strongly typed language, meaning that the type of every variable must be specified when the variable is declared. Java will not assume that a variable whose name starts with the letter i is an integer variable for example. Java variables must be declared before they are used. The basic syntax for declaring a variable in Java is the variable type, the variable name, and a semicolon ”

 variable_type variable_name; 

A Java variable can be initialized when it is declared or it can be assigned a value later in the program. Java does not support global variables. A Java variable exists only in the block of code in which it is declared. Once the program execution leaves a block of code, any variables declared inside that block disappear.

Java variables can represent either primitive types such as integer and floating point types or reference types such as objects and arrays. Java variables can be assigned different characteristics and behavior by using one or more modifying keywords when the variable is declared. The keywords that can be used with variables include public , private , protected , final , transient , volatile , and static .



Technical Java. Applications for Science and Engineering
Technical Java: Applications for Science and Engineering
ISBN: 0131018159
EAN: 2147483647
Year: 2003
Pages: 281
Authors: Grant Palmer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net