Explain different types of variable iv java and also JVM

The kind of value that a variable can own is known as data type. When we state a variable we require specifying the type of value it will own with the name of the variable. This tells the compiler that the particular variable will hold the certain amount of the memory to store values. For example, in the lines of code above num is Int type and takes two bytes to hold the integer value, boils a Boolean value. Some common types of data are used in the java called as the primitive types like called bool, characters integers, floating point numbers (float and double) etc. These primitive data types are given below where size represents the memory size it takes, for example, Boolean takes a value true or false in 1 bit memory. It takes value false if not initialized (in the case of non local variables)

 

Java primitive data types

Data type

Description

size

Default value

Boolean

True or false

1 bit

False

Char

Unicode char

16 bit

\u 0000

Byte

Signed integer

8 bit

(byte) 0

Short

Signed

integer

 

16 bit

(short) 0

Int

Signed

integer

 

32 bit

0 l

Long

Signed

integer

 

64 bit

0.0 f

Float

Real number

32 bit

0

Double

Real number

64 bit

0.0 d

The java contains the follows types of variables:

1.      Instance variables (non static fields): in object oriented programming, objects store their individual states in the non static fields that is declared without the without the static keyword. Every object of the class has its own set of values for these non static variables so we can state that these are connected to objects (instances of the class). Hence these variables are also known as instance variable. These variables put default values if not initialized.

2.      Class variables (static fields): these are jointly linked to a class and none of the object can argue them its only proprietor. The variables defined with static an keyword are shared by all objects. Here objects to do not share store an individual value but they are forced to share it among themselves. These variables are confirmed as static fields with the use of static keyword. Always the similar set of values is shared between distinct objects of the identical class. So these variables are like global variables which are the same for all objects of the class. These variables put default values if not started.

3.      Local variables: the variables defined in a method or block of code is known as local variables. These variables can be accessed within a method or block of code only. These variables can be accessed within a method or techniques do not take default values if not or block of code only. These variables put default values if not started.

4.      Parameters: the variables defined in a method or block of code is known as local variables.

   Related Questions in Programming Languages

©TutorsGlobe All rights reserved 2022-2023.