Variables & Data Type in Java



Variables :-
 Variable are a way to store information in our computer random  access memory(RAM). A variable means that can be changed. Java support different type of variables like int, long, double etc.. collectively  these are knows as Data Type.

While declaring variable we must have to tell the type of variable to computer. Lets start defining a variable to store whole number without decimal.

Syntax to define variable 

<Type> <Variable Name> = <value>

int myFirstNumber = 10;

Here int is the type of variable in Java which mean integer, that store whole number and myFirstNumber is the variable name which is used to access the variable and finally assigned 10 value into myFirstNumber variable.


Data Type :- In Java  data type in divided into two categories.
  1. Primitive
  2. Non-Primitive 
Total we have 8 primitive type(int,short,long,byte,float,double,boolean,char).

 Data Type     Size 
 boolean     1 bit
 char                     2 byte              
 byte 1 byte
 short 2 byte
 int 4 byte
 long 8 byte
 float 4 byte
 double 8 byte

package com.ekumeedhelp;

public class PrimitiveDataType1 {

public static void main(String[] args) {
int minIntValue = Integer.MIN_VALUE;
int maxIntValue = Integer.MAX_VALUE;

System.out.println("Min Int Value : " + minIntValue);
System.out.println("Max Int Value : " + maxIntValue);

short minShortValue = Short.MIN_VALUE;
short maxShortValue = Short.MAX_VALUE;

System.out.println("Min Short Value : " + minShortValue);
System.out.println("Max Short Value : " + maxShortValue);

byte minByteValue = Byte.MIN_VALUE;
byte maxByteValue = Byte.MAX_VALUE;

System.out.println("Min Byte Value : " + minByteValue);
System.out.println("Max Byte Value : " + maxByteValue);

long minLongValue = Long.MIN_VALUE;
long maxLongValue = Long.MAX_VALUE;

System.out.println("Min Long Value : " + minLongValue);
System.out.println("Max Long Value : " + maxLongValue);

}

}

Test

Share this

Related Posts

Previous
Next Post »

3 comments

Write comments
13 June 2020 at 03:18 delete

Thanks so much, for sharing your knowledge with us

Reply
avatar
13 June 2020 at 19:46 delete

Thank you !! Happy learning and keep growing

Reply
avatar
13 June 2020 at 19:47 delete

Subscribe this to get the notification. Will keep adding post in this blogs

Reply
avatar