In Java there are eight primitive Data Types.they are: byte, short, int, long, char, float, double, and boolean.
We arrange these data types in four groups: Integer,Float,Character,Boolean.
these data types represent integer numbers,i.e.,the numbers which do not have any fractional part.for example-34,456.these are again sub divided into byte,short,int and long types.
byte
The smallest integer type is byte. It is a signed 8-bit type that has a range from –128 to 127.
Variables of type byte are especially useful when you’re working with a stream of data from
a network or file. They are also useful when you’re working with raw binary data that may
not be directly compatible with Java’s other built-in types.
short
short is a signed 16-bit type. It has a range from –32,768 to 32,767. It is probably the least-used Java type.
int
The most commonly used integer type is int. It is a signed 32-bit type that has a range from –2,147,483,648 to 2,147,483,647. In addition to other uses, variables of type int are
commonly employed to control loops and to index arrays. When byte and short values are used in an expression they are promoted to int when the expression is evaluated.
long
long is a signed 64-bit type and is useful for those occasions where an int type is not large enough to hold the desired value. The range of a long is quite large. Their range is from -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807. This makes it useful when big, whole numbers are needed.
How to declare variables of Integer Data types
To declare Byte we use keyword "byte" as follows-
byte x;
x=10;
here x is a variable of Byte type integer whose value is 10
To declare Short data type the keyword "short" is used.
short=y;
To declare Int data type keyword "int " is used
int a;
To declare Long data type we use keyword "long"
long l=15L;
here we should write"L" at the end of statement. If we don't write it ,the JVM will allot only 2 byte to it.If we attach "L " the JVM will consider it as long value and will allot 8 byte.
In next blog we will discuss Character and Float data types.
So keeping reading this blog daily.And follow it.
We arrange these data types in four groups: Integer,Float,Character,Boolean.
- Integers This group includes byte, short, int, and long, which are for whole-valued signed numbers.
- Floating-point numbers This group includes float and double, which represent numbers with fractional precision.
- Characters This group includes char, which represents symbols in a character set, like letters and numbers.
- Boolean This group includes boolean, which is a special type for representing true/false values
these data types represent integer numbers,i.e.,the numbers which do not have any fractional part.for example-34,456.these are again sub divided into byte,short,int and long types.
byte
The smallest integer type is byte. It is a signed 8-bit type that has a range from –128 to 127.
Variables of type byte are especially useful when you’re working with a stream of data from
a network or file. They are also useful when you’re working with raw binary data that may
not be directly compatible with Java’s other built-in types.
short
short is a signed 16-bit type. It has a range from –32,768 to 32,767. It is probably the least-used Java type.
int
The most commonly used integer type is int. It is a signed 32-bit type that has a range from –2,147,483,648 to 2,147,483,647. In addition to other uses, variables of type int are
commonly employed to control loops and to index arrays. When byte and short values are used in an expression they are promoted to int when the expression is evaluated.
long
long is a signed 64-bit type and is useful for those occasions where an int type is not large enough to hold the desired value. The range of a long is quite large. Their range is from -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807. This makes it useful when big, whole numbers are needed.
How to declare variables of Integer Data types
To declare Byte we use keyword "byte" as follows-
byte x;
x=10;
here x is a variable of Byte type integer whose value is 10
To declare Short data type the keyword "short" is used.
short=y;
To declare Int data type keyword "int " is used
int a;
To declare Long data type we use keyword "long"
long l=15L;
here we should write"L" at the end of statement. If we don't write it ,the JVM will allot only 2 byte to it.If we attach "L " the JVM will consider it as long value and will allot 8 byte.
In next blog we will discuss Character and Float data types.
So keeping reading this blog daily.And follow it.
No comments:
Post a Comment