A variable in java must be specified with data type that can be store different sizes and values. In Java there are two types of data types.
- Primitive Data Types
- Non-Primitive Data Types
Primitive Data Types
The Primitive Data type are predefined data types. There are 8 types of primitive data types,
Data Type | Size | Default Value | Min and Max value |
byte | 1 byte | 0 | -128 to 127 |
short | 2 byte | 0 | -32,768 to 32,767 |
int | 4 byte | 0 | -2,147,483,648 to 2,147,483,647 |
long | 8 byte | 0L | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
char | 2 byte | ‘\u0000’ | single character/letter or ASCII values |
float | 4 byte | 0.0f | upto 7 decimal digits |
double | 8 byte | 0.0d | upto 16 decimal digits |
boolean | 1 bit | false | true or false |
Byte
Instead of integer data type, byte data type is used to save memory. Byte data type is an 8 bit signed two’s complement integer. The minimum value of byte data type is -128 and maximum value is 127.
Example:
class byte_example
{
public static void main(String[] args)
{
byte val;
val = 110;
System.out.println(val);
}
}
Output:
110
Short
Short data type is an 16 bit signed two’s complement integer. The maximum value for short data type is 32767 and the minimum value is -32768. The default value is 0.
Example:
class short_example
{
public static void main(String[] args)
{
short val;
val = 2000;
System.out.println(val);
}
}
Output:
2000
int
Integer data type is a 32-bit signed two’s complement integer. The maximum value for integer data type is 2,147,483,647 and the minimum value is -2,147,483,648.
Example:
class int_example
{
public static void main(String[] args)
{
int val;
val = 300000;
System.out.println(val);
}
}
Output:
300000
long
long data type is a 64-bit signed two’s complement integer. The maximum value for long data type is 9,223,372,036,854,775,807 and the minimum value is -9,223,372,036,854,775,808.
Example:
class long_example
{
public static void main(String[] args)
{
long val;
val = 900000000;
System.out.println(val);
}
}
Output:
900000000
Char
char data type is a single 16 bit Unicode character/letter or ASCII values.
Example:
class char_example
{
public static void main(String[] args)
{
char val;
val = 'B';
System.out.println(val);
}
}
Output:
B
Float
float data type is a single-precision 32 bit floating point. It can have upto 7 decimal digits.
Example:
class float_example
{
public static void main(String[] args)
{
float val;
val = 12.787783f;
System.out.println(val);
}
}
Output:
12.787783
double
double data type is a double-precision 64 bit floating point. It can have values upto 16 decimal digits.
Example:
class double_example
{
public static void main(String[] args)
{
double val;
val = 23.778675587783d;
System.out.println(val);
}
}
Output:
23.778675587783
boolean
boolean data type represents only one bit of information. It has two possible values that’s is either true or false.
Example:
class boolean_example
{
public static void main(String[] args)
{
boolean val = true;
System.out.println("Java is used to develop Android Applications:" + " " + val);
}
}
Output:
Java is used to develop Android Applications: true
Non-Primitive Data Type
Non-Primitive Data Type is also known as Reference Data Types. It contain memory address of variable value because it won’t store variable values directly in memory.
non-primitive types starts with an uppercase letter. Reference Data Type is used to access objects. The default value is null.
Example of non-primitive data type is strings, objects, arrays, Classes, Interface, etc.
I think thus is one of the mpst importaant information for me.
Annd i am glad reading your article. But wanna remark
on few general things, The web site style is perfect,
the articles is really great!
Thanks for your valuable feedback. Keep supporting us for our future work.
Hello all, here every peson is sharing such know-how, so it’s pleasant to read
this website, and I usewd to goo to see this website daily.
Hello there! Would you miknd if I sare your
blog with my twitter group? There’s a lot of people that I think would
really appreciate your content.Please let me know.
Thanks!
Hello, I enjoy readinng all of your article.
I like to write a little cokment to support you.
Great delivery.Great arguments. Keep uup tthe amazing spirit.
Hello, I enjoy reading all oof your article. I like tto write a little commen to support you.
Pretty! This has been an extremely wonderful
post. Thaanks for providing this info.
With thanks for sharing your superb website!
Hello all, here everyy person is sharing such know-how, so it’s pleasant too read this website,
and I used tto go to seee this website daily.
It iis not my first time to go to see this website, i am visiting this web page dailly and
takee good information from hesre all the time.
Hi I am so happy I found your blog, I really found you by mistake, while I was browsing on Digg for something else, Anyhow I am here now and would just like to say thanks for a tremendous post and a all round thrilling blog (I also love the theme/design), I don抰 have time to read through it all at the moment but I have bookmarked it and also added your RSS feeds, so when I have time I will be back to read much more, Please do keep up the awesome work.
What i don’t realize is in fact how you’re not really a lot more smartly-favored than you might be now. You are so intelligent. You recognize therefore considerably relating to this subject, made me in my view believe it from a lot of numerous angles. Its like women and men aren’t interested until it is one thing to accomplish with Lady gaga! Your own stuffs excellent. All the time maintain it up!
You should participate in a contest for among the best blogs on the web. I’ll recommend this web site!