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

  • Q : Explain the difference between RAM and

    Explain the difference between RAM and ROM?

  • Q : Define Interpretational inner class

    Interpretational inner class: It is an inner class whose role is to give a view or interpretation of data belongs to its enclosing class, however independent of the data's real representation.

  • Q : Explain Cohesion Cohesion : The level

    Cohesion: The level to which a component executes a single well-stated task. A strongly cohesive technique, for example, will execute a single task, like adding an item to a data structure, or sorting several data, while a weakly cohesive technique wi

  • Q : Explain Operator Explain Operator with

    Explain Operator with their types and examples?

  • Q : What is an Implicit type conversion

    Implicit type conversion: The type conversion which does not need a cast. Implicit type conversions usually do not comprise any loss of information. For example, joining an integer operand with a floating point operand in an arithmetic expression will

  • Q : Explain Abstract Windowing Toolkit

    Abstract Windowing Toolkit: The Abstract Windowing Toolkit (AWT) offers a collection of classes which simplify the creation of applications with the GUI (graphical user interfaces). Such are to be found in the java.awt packages. Included are classes f

  • Q : Use of setjmp and longjmp Use of

    Use of setjmp() and longjmp(): In C/C++, setjmp() saves the contents of the registers at a particular state in the program and longjmp() will restore that state later. In this way, longjmp() “returns” to the state of the program when setjm

  • Q : Describe IEEE 754 IEEE 754 : The

    IEEE 754: The standard 754-1985 issued by Institute of Electrical and Electronic Engineers for the binary floating point arithmetic. It is the standard to which Java's arithmetic matches.

  • Q : Why is Java pure object oriented

    Explain the reasons that Java is pure object oriented programming language.

  • Q : Write a program using simple loop

    Objective:  The purpose of this problem is to gain experience with the principles necessary to write a program using simple loop, decision processing, counters and accumulators Save the Barns, a bi-partisan po

©TutorsGlobe All rights reserved 2022-2023.