The term data type refers to the type of data that can be stored in a variable. Sometimes, Java is called a “strongly typed language” because when you declare a variable, you must specify the variable’s type. Then the compiler ensures that you don’t try to assign data of the wrong type to the variable. The following example code generates a compiler error:
int x;
x = 3.1415;
Because x is declared as a variable of type int (which holds whole numbers), you can’t assign the value 3.1415 to it.
Java distinguishes between two kinds of data types: primitive types and reference types. Primitive types are the data types defined by the language itself. By contrast,reference types are types defined by classes in the Java application programming interface (API) or by classes you create rather than by the language itself.
•Integer Types:
–int: Most numbers you’ll deal with.
–long: Big integers; science, finance, computing.
–short: Small integers. Legacy. Not very useful.
–byte: Very small integers, useful for generic data.
•Floating Point (Decimal) Types:
–float: Single-precision decimal numbers
–double: Double-precision decimal numbers.
•Other Types:
–String: Text strings.
–boolean: True or false.
–char: Latin Alphanumeric Characters
0 comments:
Post a Comment