Ticker

6/recent/ticker-posts

Java Data type | Primitive & Non-primitive in JAVA

Data type 

A data type is a classification of the type of data that a variable can hold in computer programming. 

Data types in Java are classified into two types: 

1. Primitive - which include integer, character, boolean, and floating Point type values. 

2. Non-primitive - which include Classes, Interfaces, Object type and Arrays. 

Primitive Data Types: 

    There are eight primitive data types supported by Java. 

byte: 

  • data type is an 8-bit 
  • value from -128 to 127 (27 to 27 -1) 
  • default value is 0 

short: 

  • data type is an 16-bit 
  • value from -32,768 to 32,767 (215 to 215 -1) 
  • default value is 0 

int: 

  • data type is an 32-bit 
  • value from - 2,147,483,648 to 2,147,483,647 (231 to 231 -1) 
  • default value is 0 

long: 

  • data type is an 64-bit 
  • value from (263 to 263 -1) 
  • default value is 0L 

float: 

  • data type is an 32-bit 
  • Float is mainly used to save memory in large arrays of floating point numbers 
  • default value is 0.0f 

double: 

  • data type is an 64-bit 
  • This data type is generally used as the default data type for decimal values, generally the default choice 
  • default value is 0.0 

boolean: 

  • it represents one bit of information 
  • it can contain only true or false ( no 1 or 0 is allowed ) 
  • default value is false 

char: 

  • its size is 16 bit
  • it is used to store only one character 
  • default value is space ( we represent it by 0) 

Variables 

A variable is the one which holds some value which can be altered later in the program. Or it is the named storage which can be altered later in the program. 

int i; //declaration 

i = 20; // initialisation 

ALSO SEARCH:

"java data type primitive & non primitive in java example"

"java data type primitive & non primitive in java"

"java data type primitive & non primitive in java program""

"primitive data type and non primitive data type in java"

"primitive data type and non primitive in java"

"non primitive data types in java"

"primitive vs non primitive data types"