Types of variables in java with examples

    how to declare int in java
    how to declare int in javascript
    how to initialize int in java
    how to create int in java
  • How to declare int in java
  • Variable in java example.

    Java Variables

    Variables are the containers for storing the data values or you can also call it a memory location name for the data.

    Instance variable in java

  • Local variables in java
  • Variable in java example
  • Data types in java
  • How to declare variables in java example
  • Every variable has a:

    • Data Type – The kind of data that it can hold. For example, int, string, float, char, etc.
    • Variable Name – To identify the variable uniquely within the scope.
    • Value – The data assigned to the variable.

    There are three types of variables in Java – Local, Instance, and Static.

    Example:

    int age = 27; // integer variable having value 27

    String name = "gfg" // string variable

    How to Declare Java Variables?

    We can declare variables in Java as pictorially depicted below:

     

    From the image, it can be easily perceived that while declaring a variable, we need to take care of two things that are:

    1. datatype: In Java, a data type define the type of data that a variable can hold. 
    2. data_name: Name was given to the variable. 

    In this way, a name can only be given to a memory location.

    It can be assigned values in two ways: 

    • Variable Initialization
    • Assig

        how to initialise int in java
        how to declare variables in javascript class