Data Types and Keyword in Java

 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

TypeSize in bytesRange
byte1-128 to 127
short2-32,768 to 32,767
int4-2,147,483,648 to 2,147,483,647
long8-9,223,372,036,854,775,808 to 9,223.372,036,854,775,808

Float Type

TypeSize in bytesRange
float43.4e-038 to 3.4e+038.
double81.7e-308 to 1.7e+038.

Boolean

Keywordboolean
Syntaxboolean x;
ValueTrue/False
DefaultFalse

Character

Keywordchar
Syntaxchar x;
Value'a','@','9'
Range0 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

charcontinuedoubleelse
defaultcatchfinallyfinal
longinterfaceintinstanceof
assertabstractclassextends
implementsfloatconstboolean
privatepublicprotectedpackage
breakbytecasedo
enumforgotoif
importnativenewreturn
strictfpsynchronizedstaticshort
superswitchthisthrow
throwstransienttryvoid
volatilewhile


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.

Post a Comment

1 Comments

  1. class Program
    {
    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
    */

    ReplyDelete