Java Tutorial Data Types and Variables
Content • What is Data Type in Java • What is Variable
What is Data Type in Java • Data type specifies the size and type of values that can be stored in an identifier. • Data types in Java are classified into two types: • Primitive • Non-primitive
Primitive Data Types • Integer • Character • Boolean • Floating Point
Non-primitive • Classes • Interfaces • Arrays
Integer • Integer types can hold whole numbers such as 123 and −96. The size of the values that can be stored depends on the integer type that we choose. • Byte • Short • Int • long
Floating Point • Floating point data types are used to represent numbers with a fractional part • float • double
Character • It stores character constants in the memory. • char
Boolean • Boolean data types are used to store values with two states: • true • false.
What is Variable • A Java variable is a piece of memory that can contain a data value • There are different types of variables in Java. They are as follows: • Instance Variables (Non-Static Fields) • Class Variables (Static Fields) • Local Variables • Parameters
Variable Declaration • Syntax for variable declaration datatype1 variable1, datatype2 variable2, … datatypen variablen; • For Example • int a; char ch; •Initialization • a = 10; • ch = ‘A’;
Java Data Types and Variables

Java Data Types and Variables

  • 1.
  • 2.
    Content • What isData Type in Java • What is Variable
  • 3.
    What is DataType in Java • Data type specifies the size and type of values that can be stored in an identifier. • Data types in Java are classified into two types: • Primitive • Non-primitive
  • 4.
    Primitive Data Types •Integer • Character • Boolean • Floating Point
  • 5.
  • 6.
    Integer • Integer typescan hold whole numbers such as 123 and −96. The size of the values that can be stored depends on the integer type that we choose. • Byte • Short • Int • long
  • 7.
    Floating Point • Floatingpoint data types are used to represent numbers with a fractional part • float • double
  • 8.
    Character • It storescharacter constants in the memory. • char
  • 9.
    Boolean • Boolean datatypes are used to store values with two states: • true • false.
  • 10.
    What is Variable •A Java variable is a piece of memory that can contain a data value • There are different types of variables in Java. They are as follows: • Instance Variables (Non-Static Fields) • Class Variables (Static Fields) • Local Variables • Parameters
  • 11.
    Variable Declaration • Syntaxfor variable declaration datatype1 variable1, datatype2 variable2, … datatypen variablen; • For Example • int a; char ch; •Initialization • a = 10; • ch = ‘A’;