0% found this document useful (0 votes)
10 views3 pages

Datatypes Java

The document explains Java data types, which are categorized into primitive and non-primitive types. Primitive data types include eight types such as char, boolean, byte, short, int, long, float, and double, each with specific value ranges and default values. Non-primitive data types refer to objects and include identifiers that must follow specific naming rules.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Datatypes Java

The document explains Java data types, which are categorized into primitive and non-primitive types. Primitive data types include eight types such as char, boolean, byte, short, int, long, float, and double, each with specific value ranges and default values. Non-primitive data types refer to objects and include identifiers that must follow specific naming rules.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

In java, data types are classified into two catagories :

1. Primitive Data type


2. Non-Primitive Data type

1) Primitive Data type

A primitive data type can be of eight types :

Primitive Data types

char boolean byte short int long float double

Once a primitive data type has been declared its type can never change,
although in most cases its value can change. These eight primitive type
can be put into four groups

Integer

This group includes byte, short, int, long

byte : It is 1 byte(8-bits) integer data type. Value range from -128 to


127. Default value zero. example: byte b=10;

short : It is 2 bytes(16-bits) integer data type. Value range from -32768


to 32767. Default value zero. example: short s=11;

int : It is 4 bytes(32-bits) integer data type. Value range from -


2147483648 to 2147483647. Default value zero. example: int i=10;
long : It is 8 bytes(64-bits) integer data type. Value range from -
9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. Default
value zero. example: long l=100012;

Floating-Point Number
This group includes float, double

float : It is 4 bytes(32-bits) float data type. Default value


0.0f. example: float ff=10.3f;

double : It is 8 bytes(64-bits) float data type. Default value


0.0d. example: double db=11.123;

Example:

In this example, we used floating point type and declared


variables to hold floating values. Floating type is useful to
store decimal point values.

Characters

This group represent char, which represent symbols in a character set,


like letters and numbers.

char : It is 2 bytes(16-bits) unsigned unicode character. Range 0 to


65,535. example: char c='a';

Boolean

This group represent boolean, which is a special type for representing


true/false values. They are defined constant of the language.
example: boolean b=true;

2) Non-Primitive(Reference) Data type


A reference data type is used to refer to an object. A
reference variable is declare to be of specific and that type
can never be change.

For example: String str, here str is a reference variable of


type String. String is a class in Java. We will talk a lot more
about reference data type later in Classes and Object lesson.

Reference type are used to hold reference of an object.


Object can be instance of any class or entity.

In object oriented system, we deal with object that stores


properties. To refer those objects we use reference types.

Identifiers in Java

All Java components require names. Name used for classes,


methods, interfaces and variables are called Identifier.
Identifier must follow some rules. Here are the rules:

 All identifiers must start with either a letter( a to z or A


to Z ) or currency character($) or an underscore.
 After the first character, an identifier can have any
combination of characters.
 Java keywords cannot be used as an identifier.
 Identifiers in Java are case sensitive, foo and Foo are two
different identifiers.
Some valid identifiers are: int a, class Car, float
amount etc.

You might also like