Data Types in JAVA
- It is a type of data which is used in the program.
- There are many predefined data types in java library like int,char,float etc.
Type of Data Type
Primitive Data Type
- The data type which is predefined in the library is called primitive data type.
- It is named by a keyword for example int,float,char etc.
- There are eight primitive data types in java.
byte, short, int, long, float, double, boolean and char.
Integer Type
Type | Size in bytes | Range |
byte | 1 | -128 to 127 |
short | 2 | -32,768 to 32,767 |
int | 4 | -2,147,483,648 to 2,147,483,647 |
long | 8 | -9,223,372,036,854,775,808 to 9,223.372,036,854,775,808 |
Float Type
Type | Size in bytes | Range |
float | 4 | 3.4e-038 to 3.4e+038. |
double | 8 | 1.7e-308 to 1.7e+038. |
Boolean
Keyword | boolean |
Syntax | boolean x; |
Value | True/False |
Default | False |
Character
Keyword | char |
Syntax | char x; |
Value | 'a','@','9' |
Range | 0 to 65536 |
Non-primitive Data Type
- The data type which is derived from primitive data type is called non-primitive data type.
- It is also called reference data type.
- They don't store the value, but store a reference to that value.
- Example:Array,class,interface etc.
- The word which is pre-defined in the library is called keyword.
- It's functionality is also pre-defined.
- Keyword can not be used as a variable, function name ,class name or as an any identifier.
- Example of keywords are int,float,char,void,main etc.
List of keywords in Java
char | continue | double | else |
default | catch | finally | final |
long | interface | int | instanceof |
assert | abstract | class | extends |
implements | float | const | boolean |
private | public | protected | package |
break | byte | case | do |
enum | for | goto | if |
import | native | new | return |
strictfp | synchronized | static | short |
super | switch | this | throw |
throws | transient | try | void |
volatile | while |
Request:-If you found this post helpful then let me know by your comment and share it with your friend.
If you want to ask a question or want to suggest then type your question or suggestion in comment box so that we could do something new for you all.
If you have not subscribed my website then please subscribe my website.
Try to learn something new and teach something new to other. Thanks.
1 Comments
class Program
ReplyDelete{
public static void main(String[] args)
{
int[] ar = {20,50,50,30,15,80,30};
for (int i = 0; i < ar.length-1; i++)
{
for (int j = i+1; j < ar.length; j++)
{
if ((ar[i] == ar[j]) && (i != j))
{
System.out.println("Duplicate Element is "+ar[j]);
}
}
}
}
}
/*
Output
Duplicate Element is 50
Duplicate Element is 30
*/