JAVA Basic : Variables in JAVA

In this post, we're going to learn about Variables in JAVA. So without further do Let's Get Started!


Variables in JAVA

int [Integer]
long
double
float
char
string
boolean

int [Integer]

In the int [Integer] we can store any positive and Negative numbers including 0

long

We can store Large Numbers inside the Long.

double

Double is used to store floating-point numbers.

float

Difference between float and double variable in Java? Though both float and double datatype are used to represent floating-point numbers in Java, a double data type is more precise than float. A double variable can provide precision up to 15 to 16 decimal points as compared to float precision of 6 to 7 decimal digits.

char

In char, you can store any single character.

String

String used to store Multiple characters.

Note: [Difference Between String and other variables is - Other Variables are Primitive Data types but String is a Class in Java]

boolean 

Boolean has all the True and False Values.

Source Code


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.xDroidDev.firstJAVA;

public class Main {

    public static void main(String[] args) {
        System.out.println("Hello World!");


        // In the int [Integer] we can store any possitive and Negative numbers including 0

        int number = 16;
        System.out.println(number);

        // We can store Large Numbers inside the Long
        long longnum = 45667;
        System.out.println(longnum);

        // Double is used to store floating point numbers
        double mydouble = 7.9;
        System.out.println(mydouble);

        /* Difference between float and double variable in Java? Though both float and double datatype are
        used to represent floating-point numbers in Java, a double data type is more precise than float.
        A double variable can provide precision up to 15 to 16 decimal points as compared to float precision
        of 6 to 7 decimal digits. */

        float myfloat = (float) 7.9;
        System.out.println(myfloat);

        // In char you can store any single character
        char newchar = 'Z';
        System.out.println(newchar);

        // String is used to store Multiple character
        String strng = "This is Our String";
        System.out.println(strng);

        /*[Difference Between String and other variables is - Other Variables are Primitive Data types but String
        is a Class in Java] */

        // Boolean has all the True and False Values
        boolean mybool = true;
        System.out.println(mybool);

    }
}

Post a Comment

0 Comments