what is Java Variable and Data type

Sandipan Kr Bag Apr 03, 2024
what is Java Variable and Data type

Java Variable 

A variable is a named storage location in computer memory that holds a data value, which can be modified during program execution. It serves as a symbolic representation for data, allowing programmers to manipulate and reference values within their code. Variables have a data type, such as integers, floating-point numbers, characters, or custom objects, which defines the type of data they can hold.

Variable Data Types in Java

In Java, data types specify the types of values that can be stored in variables. There are two categories of data types:

1. Primitive Data Types: These are the basic data types built into the Java language. They include:
  - `boolean`: Represents true or false values.
  - `char`: Represents single characters.
  - `byte`, `short`, `int`, `long`: Represents integers of varying sizes.
  - `float`, `double`: Represents floating-point numbers.

2. Reference Data Types: These data types are references to objects in memory. They include:
  - Classes
  - Interfaces
  - Arrays
  
Java also provides the ability to create custom data types through classes and interfaces, which are considered reference data types.

Data Type--Default Value--Memory Size--Width--                   Range--
booleanfalse1 bit--true or false
char'\u0000'2 bytes16-bitUnicode characters (0 to 65,535)
byte01 byte8-bit-128 to 127
short02 bytes16-bit-32,768 to 32,767
int04 bytes32-bit-2,147,483,648 to 2,147,483,647
long0L8 bytes64-bit-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
float0.0f4 bytes32-bit±1.4e-45 to ±3.4e38
double0.0d8 bytes64-bit±4.9e-324 to ±1.7e308

 

Share this article

sndp bag

Sandipan Kr Bag

I'm a dedicated full-stack developer, entrepreneur, and the proud owner of ocec.org.in , hailing from the vibrant country of India. My passion lies in creating informative tutorials and sharing valuable tips that empower fellow artisans in their journey. With a deep-rooted love for technology, I've been an ardent enthusiast of PHP, Laravel, Angular, Vue, Node, JavaScript, jQuery, Codeigniter, and Bootstrap from their earliest days. My philosophy revolves around the values of hard work and unwavering consistency, driving me to continuously explore, create, and share my knowledge with the tech community.

* Hire Me

0 Comments

Load more Comments

Post a Comment

Hint: Please enter between 80 - 300 characters.
ocec.org.in

helllo