Data Types Java

Data Types Java

You may use these types to declare variables and to create arrays. There are two types of data types in Java:

Primitive Types: Java defines eight primitive types of data: byte, short, int, long, char, float, double, and boolean.

Non-primitive data types: The non-primitive data types include Classes, Interfaces, and Arrays.

Primitive Types in Java

Integers: Java defines four integer types: byte, short, int, and long. All of these are signed, positive and negative values. Java does not support unsigned, positive-only integers. Many other computer languages support both signed and unsigned integers.

Floating-point numbers also known as real numbers, are used when evaluating expressions that require fractional precision. For example, calculations such as square root, or transcen dentals such as sine and cosine, result in a value whose precision requires a floating point

Char In Java, the data type used to store characters is char. However, C/C++ programmers beware: char in Java is not the same as char in C or C++. In C/C++, char is 8 bits wide. This is not the case in Java. Instead, Java uses Unicode to represent characters

Boolean Java has a primitive type, called boolean, for logical values. It can have only one of two possible values, true or false. This is the type returned by all relational operators, as in the case of a < b. boolean is also the type required by the conditional expressions that govern the control statements such as if and for.