Wednesday, February 6, 2019

Variables and Data Types in Java



Variables:


A variable is a name given to the value. For Example: Where, int i =10;
  • int= Data Type
  • i = Variable
  • 10 = Value
  • semicolon(;) is given after the end of the action.


Types Of Variables:

  1. Static Variable
  2. Instance Variable
  3. Local Variable

  4. Let’s know little deeper about Java training institute in Chennai


    1.What is Static Variable?

    • Static Variable is a class level Variable
    • It can be accessed within the class only
    • Static Variable can be accessed without the use or creation of an object.
    • For Static Variable, We have to mention Static
    • For Example: static int i = 10; static String st= ” NAME”;

    2.What is Instance Variable?

    • Instance Variable is not like Static Variable.
    • No need to mention any Instance
    • It’s a copy of its own instance variable

    3.What is a Local Variable?

    • Local Variable is Method Level variable, Java training institute in Chennai
    • It can be accessed within the method only.
    • To call the local variable, we have to create an object.
    • It cannot be accessed outside the method.

    So I have covered mostly all variable types …… So let’s jump into another topic is Data Types




    Data Types In JAVA


    Types of Data Types in Java:


    Data Types are classified into two types, they are:


    1. Primitive Data Type
    2. Non-Primitive Data Type

    3. Primitive Data Types:


      Primitive Data Types are classified into Eight types of Core java training in Chennai.

      1. Byte
      2. Short
      3. Int
      4. Long
      5. Float
      6. Double
      7. Boolean
      8. Char

      Non-Primitive Data Types:


      Non-Primitive Data Types are classified into two types. they are:


      1. Arrays
      2. Strings

      Primitive Data Type:


      Byte:

      • For Storing whole Numbers
      • It stores a value between -128 to 127
      • Size = 1 byte
      • Value = 0

      Short:

      • For Storing Whole Numbers
      • It stores value between -32,768 to 32767
      • Size = 2 byte
      • Value = 0

      Int:

      • For Storing Whole Numbers
      • It stores value between -2,147,483,648 to 2,147,483,647
      • Size = 4 byte
      • Value = 0

      Long:

      • For Storing Whole Numbers
      • It stores value between 9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
      • Size = 8 byte
      • Value = 0

      Double:

      • It is used for Fractional Numbers
      • It stores upto 15 decimal digits
      • Size = 8 byte
      • Value = 0

      Float:

      • It is used for Fractional Numbers
      • It stores upto 7 decimal digits
      • Size = 4 byte
      • Value = 0

      Boolean:

      • It is used to tell either true or false

      Char:

      • It is used in character
      • Size = 2 bytes


      For Example:

      int i = 10; byte b = 5; short s = 10; long = 123l; float = 23.9f; double = 34.98d; or 34.98 boolean = true; or false; char = ‘A’;


      Non-Primitive Data type:


      Array:


      Array is classified into two types:


      1. 1.Single-Dimension Array
      2. 2.Multi-Dimension Array

      String:

      • String is a collection of character
      • It can be initialized into double quotes

      For example:


      String st=”My Name”;



      I hope this will be helpful for the beginners in java ...See you in the Next topic. core java training in chennai


No comments:

Post a Comment