variable and datatype
Answers
Explanation:
A variable can be thought of as a memory location that can hold values of a specific type. The value in a variable may change during the life of the program—hence the name “variable.” A variable that holds integers (whole numbers) has the data type Integer and is called an integer variable. ...
Answer:
Variables are the nouns of a programming language: they are the entities (values, data) that act or are acted upon. The character-counting program uses two variables--count and args. The program increments count each time it reads a character from the input source and ignores args. The declarations for both variables appear in bold in the following listing:
class Count {
public static void main(String[] args)
throws java.io.IOException
{
int count = 0;
while (System.in.read() != -1)
count++;
System.out.println("Input has " + count + " chars.");
}
}
A variable declaration always contains two components: the type of the variable and its name. Also, the location of the variable declaration, that is, where the declaration appears in relation to other code elements, determines the scope of the variable.
Variable Types
All variables in the Java language must have a data type. A variable's type determines the values that the variable can have and the operations that can be performed on it. For example, the declaration int count declares that count is an integer (int). Integers can have only whole number values (both positive and negative) and you can use the standard arithmetic operators (+, -, and so on) on integers to perform the standard arithmetic operations (addition, subtraction, multiplication, and division).
There are two major categories of data types in the Java language: primitive types and reference types. Primitive types contain a single value and include types such as integer, floating point, character, and boolean. The following table lists, by keyword, all of the primitive data types supported by Java, their size and format, and a brief description of each.
Type Size/Format Description
(whole numbers)
byte 8-bit two's complement Byte-length integer
short 16-bit two's complement Short integer
int 32-bit two's complement Integer
long 64-bit two's complement Long integer
(real numbers)
float 32-bit IEEE 754 Single-precision floating point
double 64-bit IEEE 754 Double-precision floating point
(other types)
char 16-bit Unicode character A single character
boolean true or false A boolean value (true or false)
Reference types are called such because the value of a reference variable is a reference (a pointer in other terminology) to the actual value or set of values represented by the variable. For example, the character-counting program declares (but never uses) one variable of reference type, args, which is declared to be an array of String objects. When used in a statement or expression, the name args evaluates to the address of the memory location where the array lives. This is in contrast to the name of a primitive variable, the count variable, which evaluates to the variable's actual value.
B