DATA TYPES IN JAVA - SATISH THAWAN

Breaking

Breaking

Featured

Monday, 13 October 2025

DATA TYPES IN JAVA

 

🔹 English Explanation:

In programming languages, data types define what kind of value a variable can store and how much memory it will take.
For example — some variables store numbers, some store text, and some store true/false values.

In Java, every variable must have a data type before it is used.
That’s why Java is called a statically and strongly typed language — because the type of every variable is checked at compile time and you can’t store a wrong type of data in it.

Java data types are divided into two main categories:

  1. Primitive Data Types:
    These are the basic or built-in data types.
    👉 boolean, char, byte, short, int, long, float, double.
    They directly store simple values like numbers or characters.

  2. Non-Primitive Data Types:
    These are derived from classes and used to store complex data.
    👉 String, Arrays, Classes, Interfaces.
    They store references (addresses) of objects rather than direct values.


🔹 తెలుగు వివరణ:

ప్రోగ్రామింగ్ భాషల్లో డేటా టైపులు (Data Types) అంటే — ఒక వేరియబుల్ (variable) లో ఏ రకమైన విలువను (value) నిల్వచేయాలో, ఎంత మెమరీ అవసరం అవుతుందో నిర్ధారిస్తాయి.

ఉదాహరణకు — కొంతమంది వేరియబుల్స్ సంఖ్యలను (numbers) నిల్వ చేస్తాయి, మరికొన్ని అక్షరాలను (text/characters), ఇంకొన్ని true/false వంటి విలువలను నిల్వ చేస్తాయి.

జావాలో (Java) ప్రతి వేరియబుల్‌కి ఉపయోగించే ముందు ఒక డేటా టైపు ఉండాలి.
అందుకే Javaని statically మరియు strongly typed language అంటారు — ఎందుకంటే ప్రతి వేరియబుల్ యొక్క టైపు compile time లోనే తనిఖీ అవుతుంది, తప్పుడు రకమైన విలువను పెట్టడం అనుమతించదు.

జావాలో రెండు రకాల డేటా టైపులు ఉంటాయి:

  1. ప్రిమిటివ్ డేటా టైపులు (Primitive Data Types):
    ఇవి జావాలో ఉన్న ప్రాథమిక (basic) డేటా టైపులు.
    👉 boolean, char, byte, short, int, long, float, double
    ఇవి నేరుగా విలువలను (values) నిల్వ చేస్తాయి.

  2. నాన్-ప్రిమిటివ్ డేటా టైపులు (Non-Primitive Data Types):
    ఇవి క్లాసులు (classes) నుండి రూపొందినవి మరియు క్లిష్టమైన (complex) డేటాను నిల్వ చేయడానికి ఉపయోగిస్తారు.
    👉 String, Arrays, Classes, Interfaces
    ఇవి direct values కాదని, objects యొక్క address/reference ను నిల్వ చేస్తాయి.

అంటే, Primitive types simple data కోసం,
Non-primitive types complex / object data కోసం వాడతారు ✅

Java Primitive Data Types

In Java, primitive data types are the building blocks of data manipulation. These are the basic data types.

In Java, there are mainly eight primitive data types which are as follows.

  1. boolean data type
  2. char data type
  3. byte data type
  4. short data type
  5. int data type
  6. long data type
  7. float data type
  8. double data type

🧩 1. Boolean Data Type / బూలియన్ డేటా టైపు

🔹 English Explanation:

In Java, the boolean data type represents a value that can only have two possible states
true or ❌ false.

It is mainly used for logical expressions and conditional statements — for example, when you want to check if something is correct or not.

Although it is said to be 1 byte (8 bits), technically Java does not define a fixed size for boolean.
Usually, it’s implemented as a single bit because it only needs to store two values (true or false), but the actual size can depend on the JVM (Java Virtual Machine).

Example:

boolean isJavaFun = true; boolean isRainy = false;

Here,

  • isJavaFun stores true

  • isRainy stores false

These values are mostly used in if-else conditions, loops, and logical operations.

🔹 తెలుగు వివరణ:

Java లో boolean data type అంటే రెండు మాత్రమే విలువలు ఉండే ఒక డేటా టైపు —
true (నిజం) లేదా ❌ false (అబద్ధం).

ఇది తర్కసంబంధమైన (logical) లేదా పరిస్థితుల (conditions) ఫలితాలను నిల్వ చేయడానికి ఉపయోగిస్తారు.
ఉదాహరణకు — ఒక పని సరిగా జరిగిందా లేదా అని తెలుసుకోవడానికి.

సాధారణంగా దీని పరిమాణం 1 byte (8 bits) అని చెప్పినా, Java లో boolean కి ఖచ్చితమైన పరిమాణం (size) నిర్ణయించబడదు.
ఎందుకంటే ఇది true లేదా false అనే రెండు విలువలలో ఒక్కటినే ఉంచుతుంది కాబట్టి, JVM (Java Virtual Machine) దాన్ని single bit గా అమలు చేస్తుంది.

ఉదాహరణ:

boolean isJavaFun = true; boolean isRainy = false;

ఇక్కడ,

  • isJavaFun → true

  • isRainy → false

ఇలాంటి బూలియన్ విలువలను సాధారణంగా if-else statements, loops, conditions లలో వాడతారు.


🧩 2. Byte Data Type / బైట్ డేటా టైపు

🔹 English Explanation:

In Java, the byte data type is a primitive type that stores 8-bit signed integers.

  • Range: -128 to 127

  • Default value: 0

  • Size: 1 byte (8 bits)

It is commonly used when:

  1. You need to save memory because it takes less space than int (4 bytes) or long (8 bytes).

  2. You are working with raw binary data, such as reading files or network streams.

Example:

byte age = 25; byte temperature = -10;

Here, age stores 25 and temperature stores -10.


🔹 తెలుగు వివరణ:

Java లో byte data type అంటే ఒక primitive type మరియు ఇది 8-bit signed integer ను నిల్వ చేస్తుంది.

  • రేంజ్: -128 నుండి 127

  • డిఫాల్ట్ విలువ: 0

  • సైజ్: 1 byte (8 bits)

ఎప్పుడు వాడతారు:

  1. Memory ను పొదుపు చేయాలి అని వచ్చినప్పుడు — ఎందుకంటే ఇది int (4 bytes) లేదా long (8 bytes) కంటే తక్కువ memory తీసుకుంటుంది.

  2. Raw binary data తో పని చేస్తున్నప్పుడు, ఉదాహరణకు ఫైల్ చదివేటప్పుడు లేదా network data streams లో.

ఉదాహరణ:

byte age = 25; byte temperature = -10;

ఇక్కడ,

  • age → 25

  • temperature → -10

🧩 3. Short Data Type / షార్ట్ డేటా టైపు

🔹 English Explanation:

In Java, the short data type is a primitive type that stores 16-bit signed integers.

  • Range: -32,768 to 32,767

  • Default value: 0

  • Size: 2 bytes (16 bits)

It is similar to byte, but it can store larger numbers.
It is typically used when:

  1. You want to save memory compared to using int (4 bytes).

  2. You need more precision than byte but still want to keep memory usage low.

Example:

short distance = 1500; short height = -120;

Here, distance stores 1500 and height stores -120.


🔹 తెలుగు వివరణ:

Java లో short data type అంటే ఒక primitive type మరియు ఇది 16-bit signed integer ను నిల్వ చేస్తుంది.

  • రేంజ్: -32,768 నుండి 32,767

  • డిఫాల్ట్ విలువ: 0

  • సైజ్: 2 bytes (16 bits)

Byte data type లా short కూడా memory పొదుపు కోసం ఉపయోగిస్తారు, కానీ byte కంటే ఎక్కువ సంఖ్యలు నిల్వ చేయగలదు.

  • ఎప్పుడు వాడతారు:

    1. int కంటే తక్కువ memory ఉపయోగించాలంటే

    2. Byte కంటే ఎక్కువ precision అవసరమైతే

ఉదాహరణ:

short distance = 1500; short height = -120;

ఇక్కడ,

  • distance → 1500

  • height → -120

🧩 4. Int Data Type / ఇంట్ డాటా టైపు

🔹 English Explanation:

In Java, the int data type is a primitive type that stores 32-bit signed integers.

  • Range: -2,147,483,648 to 2,147,483,647

  • Default value: 0

  • Size: 4 bytes (32 bits)

The int type is one of the most commonly used data types.
It is typically used to store whole numbers (numbers without decimal points), such as counts, ages, indexes, etc.

Example:

int age = 25; int population = 1000000;

Here, age stores 25 and population stores 1,000,000.


🔹 తెలుగు వివరణ:

Java లో int data type అంటే ఒక primitive type మరియు ఇది 32-bit signed integer ను నిల్వ చేస్తుంది.

  • రేంజ్: -2,147,483,648 నుండి 2,147,483,647

  • డిఫాల్ట్ విలువ: 0

  • సైజ్: 4 bytes (32 bits)

Int data type చాలా ఎక్కువగా వాడే data type.
దీన్ని సాధారణంగా పూర్తి సంఖ్యలు (whole numbers) కోసం వాడతారు, ఉదాహరణకు counts, ages, array indexes, population, etc.

ఉదాహరణ:

int age = 25; int population = 1000000;

ఇక్కడ,

  • age → 25

  • population → 1,000,000

🧩 5. Long Data Type / లాంగ్ డేటా టైపు

🔹 English Explanation:

In Java, the long data type is a primitive type that stores 64-bit signed integers.

  • Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

  • Default value: 0L

  • Size: 8 bytes (64 bits)

The long type is used when int is not large enough to hold a value, or when you need a larger range of integers.

Example:

long distanceToMoon = 384400000L; long nationalDebt = 2100000000000L;

Here, distanceToMoon and nationalDebt store very large numbers that int cannot hold.


🔹 తెలుగు వివరణ:

Java లో long data type అంటే ఒక primitive type మరియు ఇది 64-bit signed integer ను నిల్వ చేస్తుంది.

  • రేంజ్: -9,223,372,036,854,775,808 నుండి 9,223,372,036,854,775,807

  • డిఫాల్ట్ విలువ: 0L

  • సైజ్: 8 bytes (64 bits)

Long data type ను వాడతారు:

  1. Int data type సరిగా పరిమాణం ఇవ్వలేకపోతే

  2. చాలా పెద్ద సంఖ్యలు (large integers) అవసరమైతే

ఉదాహరణ:

long distanceToMoon = 384400000L; long nationalDebt = 2100000000000L;

ఇక్కడ, distanceToMoon మరియు nationalDebt చాలా పెద్ద సంఖ్యలు, int లో నిల్వ చేయలేవు.

🧩 6. Float Data Type / ఫ్లోట్ డేటా టైపు

🔹 English Explanation:

In Java, the float data type is a primitive type that stores single-precision 32-bit floating-point numbers according to the IEEE 754 standard.

  • Size: 4 bytes (32 bits)

  • Default value: 0.0f or 0.0F

  • Precision: ~6-7 significant decimal digits

The float type is useful when:

  1. You need to store decimal values.

  2. You require a wide range of values, including very small and very large numbers.

  3. Exact precision is not critical (e.g., measurements, scientific calculations).

Note: Float is not suitable for precise calculations like currency because of its limited precision.

Example:

float price = 10.75f; float temperature = -4.32f;

Here, price stores 10.75 and temperature stores -4.32.


🔹 తెలుగు వివరణ:

Java లో float data type అంటే ఒక primitive type మరియు ఇది single-precision 32-bit floating-point number (IEEE 754 standard ప్రకారం) ను నిల్వ చేస్తుంది.

  • సైజ్: 4 bytes (32 bits)

  • డిఫాల్ట్ విలువ: 0.0f లేదా 0.0F

  • ప్రెసిషన్: సుమారు 6-7 డెసిమల్ అంకెలు

Float data type ఉపయోగాలు:

  1. Decimal values ను నిల్వ చేయడానికి

  2. చిన్న, పెద్ద, సానుకూల మరియు ప్రతికూల సంఖ్యలు లను నిల్వ చేయడానికి

  3. Exact precision అవసరం లేని సందర్భాల్లో (scientific calculations, measurements)

గమనిక: Float ను కరెన్సీ లాంటి precise calculations కోసం ఉపయోగించడం సరిగా కాదు, ఎందుకంటే precision పరిమితం ఉంటుంది.

ఉదాహరణ:

float price = 10.75f; float temperature = -4.32f;

ఇక్కడ,

  • price → 10.75

  • temperature → -4.32

🧩 7. Double Data Type / డబుల్ డేటా టైపు

🔹 English Explanation:

In Java, the double data type is a primitive type that stores double-precision 64-bit floating-point numbers according to the IEEE 754 standard.

  • Size: 8 bytes (64 bits)

  • Default value: 0.0d or 0.0D

  • Precision: ~15 significant decimal digits

The double type is useful when:

  1. You need high precision decimal values.

  2. You want to store very large or very small numbers.

It is commonly used in scientific calculations, financial calculations (with some caution), and anywhere float precision is not enough.

Example:

double pi = 3.141592653589793; double balance = -2500.75;

Here, pi stores 3.141592653589793 and balance stores -2500.75.


🔹 తెలుగు వివరణ:

Java లో double data type అంటే ఒక primitive type మరియు ఇది double-precision 64-bit floating-point number (IEEE 754 standard ప్రకారం) ను నిల్వ చేస్తుంది.

  • సైజ్: 8 bytes (64 bits)

  • డిఫాల్ట్ విలువ: 0.0d లేదా 0.0D

  • ప్రెసిషన్: సుమారు 15 డెసిమల్ అంకెలు

Double data type ఉపయోగాలు:

  1. High precision decimal values అవసరమైతే

  2. చాలా పెద్ద లేదా చాలా చిన్న సంఖ్యలు నిల్వ చేయాలి అంటే

సాధారణ ఉపయోగం:

  • Scientific calculations

  • Financial calculations (సహజంగా precision అవసరమైతే)

  • Float precision కంటే ఎక్కువ అవసరమున్నప్పుడు

ఉదాహరణ:

double pi = 3.141592653589793; double balance = -2500.75;

ఇక్కడ,

  • pi → 3.141592653589793

  • balance → -2500.75

🧩 8. Char Data Type / చార్ డేటా టైపు

🔹 English Explanation:

In Java, the char data type is a primitive type that stores a single 16-bit Unicode character.

  • Size: 2 bytes (16 bits)

  • Default value: '\u0000' (null character)

  • Range: '\u0000' to '\uffff' (0 to 65,535 in decimal)

The char type can store:

  1. Letters ('A', 'z')

  2. Digits ('0', '9')

  3. Symbols ('$', '@')

  4. Unicode characters from other languages (like 'అ', 'अ')

Note: Each character is internally represented by a Unicode value, so you can also perform arithmetic operations using char values.

Example:

char grade = 'A'; char digit = '7'; char symbol = '$';

Here, grade stores 'A', digit stores '7', and symbol stores '$'.


🔹 తెలుగు వివరణ:

Java లో char data type అంటే ఒక primitive type మరియు ఇది ఒక 16-bit Unicode character ను నిల్వ చేస్తుంది.

  • సైజ్: 2 bytes (16 bits)

  • డిఫాల్ట్ విలువ: '\u0000' (null character)

  • రేంజ్: '\u0000' నుండి '\uffff' (0 నుండి 65,535 వరకు)

Char data type వాడతారు:

  1. అక్షరాలు (Letters): 'A', 'z'

  2. సంఖ్యలు (Digits): '0', '9'

  3. చిహ్నాలు (Symbols): '$', '@'

  4. ఇతర భాషల Unicode characters ('అ', 'अ')

గమనిక:
ప్రతి character Unicode value ద్వారా సూచించబడుతుంది, కాబట్టి arithmetic operations కూడా చేయవచ్చు.

ఉదాహరణ:

char grade = 'A'; char digit = '7'; char symbol = '$';

ఇక్కడ,

  • grade'A'

  • digit'7'

  • symbol'$'



Java Primitive Data Types / జావా ప్రిమిటివ్ డేటా టైపులు
Data Type / డేటా టైపు Size / సైజ్ Range / రేంజ్ Default Value / డిఫాల్ట్ విలువ Description / వివరణ
byte 1 byte (8 bits) -128 to 127 0 Small integer values, memory-efficient. / చిన్న సంఖ్యలు, memory పొదుపు కోసం
short 2 bytes (16 bits) -32,768 to 32,767 0 Larger than byte but still memory-efficient. / byte కంటే పెద్దది, memory తగ్గింపు కోసం
int 4 bytes (32 bits) -2,147,483,648 to 2,147,483,647 0 Most commonly used for whole numbers. / పూర్తిసంఖ్యల కోసం ఎక్కువగా వాడే data type
long 8 bytes (64 bits) -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 0L For very large integer values. / చాలా పెద్ద సంఖ్యలు కోసం
float 4 bytes (32 bits) ±3.40282347E+38F (approx) 0.0f Single-precision decimal values, less precise. / చిన్న decimal values కోసం, precision తక్కువ
double 8 bytes (64 bits) ±1.79769313486231570E+308 (approx) 0.0d Double-precision decimal values, more precise. / పెద్ద decimal values కోసం, precision ఎక్కువ
boolean 1 byte (8 bits) true / false false Logical values only, true or false. / true లేదా false మాత్రమే నిల్వ చేసే logical type
char 2 bytes (16 bits) '\u0000' to '\uffff' (0 to 65,535) '\u0000' Single Unicode character, letters, digits, symbols. / ఒక character, అక్షరాలు, సంఖ్యలు, symbols


  1. premitive data type example: 

  2. public class Main  
  3. {  
  4.     public static void main(String args[])  
  5.     {  
  6.         boolean flag = true;  
  7.         char ch = 'z';  
  8.         int num = 1234;  
  9.         byte size = 2;  
  10.         short srt = 78;  
  11.         double value = 2.4546778;  
  12.         float temp = 3.8f;  
  13.         long val = 1888889;  
  14.         System.out.println("boolean: " + flag);  
  15.         System.out.println("char: " + ch);  
  16.         System.out.println("integer: " + num);  
  17.         System.out.println("byte: " + size);  
  18.         System.out.println("short: " + srt);  
  19.         System.out.println("float: " + value);  
  20.         System.out.println("double: " + temp);  
  21.         System.out.println("long: " + val);  
  22.     }  

  23. output :
boolean: true
char: z
integer: 1234
byte: 2
short: 78
float: 2.4546778
double: 3.8
long: 1888889

🧩 Non-Primitive Data Types / నాన్-ప్రిమిటివ్ డేటా టైపులు

🔹 English Explanation:

In Java, Non-Primitive Data Types (also called Reference Data Types) are types that do not store the value directly. Instead, they store a reference (address) to the memory location where the actual data is kept.

Examples of Non-Primitive Data Types:

  1. Classes – Blueprint of objects that can have properties (fields) and methods.

  2. Interfaces – Define a contract of methods that classes must implement.

  3. Strings – Represents a sequence of characters.

  4. Arrays – Stores multiple values of the same type in a single variable.

Key Points:

  • They can store complex data.

  • Their size is not fixed like primitive types.

  • They are created using constructors or new keyword.

Example:

// String String name = "Vagdevi"; // Array int[] marks = {85, 90, 75}; // Class class Student { String studentName; int age; } Student s1 = new Student(); s1.studentName = "Ravi"; s1.age = 20;

🔹 తెలుగు వివరణ:

Java లో Non-Primitive Data Types అంటే, వేరియబుల్‌లో డేటా నేరుగా నిల్వ కావడం కాదు.
ఇవి reference (memory address) ను నిల్వ చేస్తాయి, డేటా అదే address లో ఉంటుంది.

నాన్-ప్రిమిటివ్ డేటా టైపుల ఉదాహరణలు:

  1. Classes – Objects కు blueprint. Fields & methods ఉంటాయి.

  2. Interfaces – Methods contract, classes implement చేయాలి.

  3. Strings – అక్షరాల సీక్వెన్స్ నిల్వ చేయడానికి.

  4. Arrays – ఒకే type లోని multiple values నిల్వ చేయడానికి.

ప్రధాన విషయాలు:

  • Complex data నిల్వ చేయగలవు.

  • Size primitive types లా fixed కాదు.

  • Constructors / new keyword ద్వారా objects create చేస్తారు.

ఉదాహరణ:

// String String name = "Vagdevi"; // Array int[] marks = {85, 90, 75}; // Class class Student { String studentName; int age; } Student s1 = new Student(); s1.studentName = "Ravi"; s1.age = 20;

🧩 Non-Primitive Data Types / నాన్-ప్రిమిటివ్ డేటా టైపులు

🔹 English Explanation:

Non-Primitive Data Types in Java are also known as Reference Types because they refer to memory locations of objects, not the actual value itself.

These data types are created by programmers (except for String, which is predefined).

🧠 Main Differences between Primitive and Non-Primitive Data Types:
FeaturePrimitive Data TypesNon-Primitive Data Types
DefinitionPredefined and built into Java languageCreated by the programmer (except String)
Exampleint, float, boolean, charString, Array, Class, Interface
UsageStores actual valueRefers to an object in memory
MethodsCannot call methodsCan call methods (e.g., str.length())
Letter CaseStarts with lowercase letter (e.g., int)Starts with uppercase letter (e.g., String)
Null ValuesCannot be nullCan be null
Memory TypeStored in Stack memoryStored in Heap memory (reference in Stack)
💡 Example:
String name = "Vagdevi"; int[] marks = {90, 85, 95}; Student s1 = new Student();

🔹 తెలుగు వివరణ:

Non-Primitive Data Types అంటే Java లోని Reference Types.
ఇవి objects కు reference (memory address) ను సూచిస్తాయి, actual value కాదు.

ఇవి సాధారణంగా programmer సృష్టించినవి (కానీ String మాత్రమే predefined).

🧠 Primitive మరియు Non-Primitive Data Types మధ్య తేడాలు:
లక్షణంPrimitive Data TypesNon-Primitive Data Types
అర్ధంJava లో predefined గా ఉంటాయిProgrammer create చేసినవి (String తప్ప)
ఉదాహరణలుint, float, boolean, charString, Array, Class, Interface
వాడుకActual value నిల్వ చేస్తుందిObject memory reference ను సూచిస్తుంది
మెతడ్స్Methods ఉండవుMethods వాడవచ్చు (str.length() వంటి)
Caseచిన్న అక్షరంతో మొదలవుతుంది (int)పెద్ద అక్షరంతో మొదలవుతుంది (String)
Null ValuesNull అవ్వవుNull అవుతాయి
Memory TypeStack memory లో నిల్వ అవుతుందిHeap memory లో data, Stack లో reference ఉంటుంది
💡 ఉదాహరణ:
String name = "Vagdevi"; int[] marks = {90, 85, 95}; Student s1 = new Student();



🧩 var Keyword in Java / జావాలో var కీవర్డ్

🔹 English Explanation:

The var keyword was introduced in Java 10 (2018).
It allows the compiler to automatically detect (infer) the data type of a variable based on the value assigned to it.

This feature makes your code shorter, cleaner, and easier to read, especially when dealing with long or complex data types.

💡 Important:

  • var can only be used inside methods (local variables).

  • It cannot be used for class fields, method parameters, or return types.

  • The variable type is decided at compile time, not at runtime.

Example:
var x = 5; // int var name = "Vagdevi"; // String var price = 99.99; // double System.out.println(x); System.out.println(name); System.out.println(price);

In this example:

  • The compiler automatically detects the type of x as int,

  • name as String,

  • price as double.


🔹 తెలుగు వివరణ:

var కీవర్డ్ ను Java 10 (2018) లో పరిచయం చేశారు.
ఇది వేరియబుల్ యొక్క టైప్‌ను కంపైలర్ ఆటోమేటిక్‌గా గుర్తించేలా (type inference) చేస్తుంది.

ఇది కోడ్‌ను చిన్నగా, క్లియర్‌గా మరియు సులభంగా చదవదగినదిగా చేస్తుంది, ముఖ్యంగా పెద్ద లేదా కాంప్లెక్స్ టైప్స్ ఉన్నప్పుడు.

💡 గమనించాల్సిన విషయాలు:

  • var ను methods లోపల మాత్రమే ఉపయోగించవచ్చు (local variables కోసం).

  • Class fields, method parameters లేదా return types కోసం వాడలేము.

  • Variable టైప్ compile time లోనే నిర్ణయించబడుతుంది, runtime లో కాదు.

ఉదాహరణ:
var x = 5; // int var name = "Vagdevi"; // String var price = 99.99; // double System.out.println(x); System.out.println(name); System.out.println(price);

ఈ ఉదాహరణలో:

  • x ను కంపైలర్ int గా గుర్తిస్తుంది

  • name ను String గా గుర్తిస్తుంది

  • price ను double గా గుర్తిస్తుంది

var myNum = 5;         // int
var myDouble = 9.98;   // double
var myChar = 'D';      // char
var myBoolean = true;  // boolean
var myString = "Hello"; // String


if var with arrey insert:

// Import the ArrayList class
import java.util.ArrayList;

public class Main {
  public static void main(String[] args) {
    var cars = new ArrayList<String>();
    cars.add("Volvo");
    cars.add("BMW");
    cars.add("Ford");
    cars.add("Mazda");
    System.out.println(cars);
  }
}

output:

[Volvo, BMW, Ford, Mazda]

Food