/* related posts with thumb nails */

data types in Java:

Data-type: Data-type specifies what type of value a variable can store. It also specifies its size. Every variable in Java has a data-type. Java language is rich in its data types. The categories of different data-types are shown below. The two main types are Primitive and non-primitive types.










1. Integer type: An integer type of variables can hold integer constants. Java supports four types of integer data types. They are byte, short, int and long. The following table shows size in bytes and range of values each data type can represent. Integer can be converted to long type by typing ‘L’ after them.

TYPE

MEMORY (bytes)

VALUES

byte

short

int

long

1

2

4

8

-128 to 127

-32768 to 32767

-231 to 231-1

-263 to 263-1

2. Floating point type: This data type is used to represent numbers containing fractional values. They are two types of data-types under this category, namely, float and double. float type number are single precision numbers while double type number are double precision numbers. By default float are double precision and can converted to single precision by adding ‘f’ at the end. Double precision types are used when greater precision is required in storage of floating point. Floating point data types have special NaN (Not a Number) value for undefined numbers like 0/0 etc.

TYPE

SIZE

MAXIMUM VALUE

MINIMUM VALUE

float

double

4 bytes

8 bytes

3.4e-038

1.7e-308

3.4e+038

1.7e+308

3. Character type: Java provides a data type called char to hold character values. It is of size 2 bytes and assumes single character. The character value must be enclosed in single quotes.

4. Boolean type: It can have only two values, either ‘true’ or ‘false’. Its keyword is ‘boolean’ and use only 1 bit. All comparison operators return boolean type values. The words ‘true’ and ‘false’ cannot be used as identifiers.

Related Topics:

1 comments:

Merit Campus said...

You can clear many of your doubts regarding data types in Core Java through Merit Campus, visit: http://java.meritcampus.com/core-java-topics/data-types-in-java, http://java.meritcampus.com/core-java-topics/floating-point-data-types-in-java

Not only data types, we also have each and every topic in Core Java with example for each. You can read lot of sessions and can write many practice tests in Merit Campus Java website. visit: http://java.meritcampus.com/core-java-topics/ to know more.

Post a Comment