🔹 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:
-
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. -
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 లోనే తనిఖీ అవుతుంది, తప్పుడు రకమైన విలువను పెట్టడం అనుమతించదు.
జావాలో రెండు రకాల డేటా టైపులు ఉంటాయి:
-
ప్రిమిటివ్ డేటా టైపులు (Primitive Data Types):
ఇవి జావాలో ఉన్న ప్రాథమిక (basic) డేటా టైపులు.
👉boolean,char,byte,short,int,long,float,double
ఇవి నేరుగా విలువలను (values) నిల్వ చేస్తాయి. -
నాన్-ప్రిమిటివ్ డేటా టైపులు (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.
- boolean data type
- char data type
- byte data type
- short data type
- int data type
- long data type
- float data type
- 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:
Here,
-
isJavaFunstorestrue -
isRainystoresfalse
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 గా అమలు చేస్తుంది.
ఉదాహరణ:
ఇక్కడ,
-
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:
-128to127 -
Default value:
0 -
Size: 1 byte (8 bits)
It is commonly used when:
-
You need to save memory because it takes less space than
int(4 bytes) orlong(8 bytes). -
You are working with raw binary data, such as reading files or network streams.
Example:
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)
ఎప్పుడు వాడతారు:
-
Memory ను పొదుపు చేయాలి అని వచ్చినప్పుడు — ఎందుకంటే ఇది
int(4 bytes) లేదాlong(8 bytes) కంటే తక్కువ memory తీసుకుంటుంది. -
Raw binary data తో పని చేస్తున్నప్పుడు, ఉదాహరణకు ఫైల్ చదివేటప్పుడు లేదా network data streams లో.
ఉదాహరణ:
ఇక్కడ,
-
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,768to32,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:
-
You want to save memory compared to using
int(4 bytes). -
You need more precision than byte but still want to keep memory usage low.
Example:
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 కంటే ఎక్కువ సంఖ్యలు నిల్వ చేయగలదు.
-
ఎప్పుడు వాడతారు:
-
intకంటే తక్కువ memory ఉపయోగించాలంటే -
Byte కంటే ఎక్కువ precision అవసరమైతే
-
ఉదాహరణ:
ఇక్కడ,
-
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,648to2,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:
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.
ఉదాహరణ:
ఇక్కడ,
-
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,808to9,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:
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 ను వాడతారు:
-
Int data type సరిగా పరిమాణం ఇవ్వలేకపోతే
-
చాలా పెద్ద సంఖ్యలు (large integers) అవసరమైతే
ఉదాహరణ:
ఇక్కడ, 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.0for0.0F -
Precision: ~6-7 significant decimal digits
The float type is useful when:
-
You need to store decimal values.
-
You require a wide range of values, including very small and very large numbers.
-
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:
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 ఉపయోగాలు:
-
Decimal values ను నిల్వ చేయడానికి
-
చిన్న, పెద్ద, సానుకూల మరియు ప్రతికూల సంఖ్యలు లను నిల్వ చేయడానికి
-
Exact precision అవసరం లేని సందర్భాల్లో (scientific calculations, measurements)
గమనిక: Float ను కరెన్సీ లాంటి precise calculations కోసం ఉపయోగించడం సరిగా కాదు, ఎందుకంటే precision పరిమితం ఉంటుంది.
ఉదాహరణ:
ఇక్కడ,
-
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.0dor0.0D -
Precision: ~15 significant decimal digits
The double type is useful when:
-
You need high precision decimal values.
-
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:
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 ఉపయోగాలు:
-
High precision decimal values అవసరమైతే
-
చాలా పెద్ద లేదా చాలా చిన్న సంఖ్యలు నిల్వ చేయాలి అంటే
సాధారణ ఉపయోగం:
-
Scientific calculations
-
Financial calculations (సహజంగా precision అవసరమైతే)
-
Float precision కంటే ఎక్కువ అవసరమున్నప్పుడు
ఉదాహరణ:
ఇక్కడ,
-
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:
-
Letters (
'A','z') -
Digits (
'0','9') -
Symbols (
'$', '@') -
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:
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 వాడతారు:
-
అక్షరాలు (Letters):
'A','z' -
సంఖ్యలు (Digits):
'0','9' -
చిహ్నాలు (Symbols):
'$', '@' -
ఇతర భాషల Unicode characters (
'అ','अ')
గమనిక:
ప్రతి character Unicode value ద్వారా సూచించబడుతుంది, కాబట్టి arithmetic operations కూడా చేయవచ్చు.
ఉదాహరణ:
ఇక్కడ,
-
grade→'A' -
digit→'7' -
symbol→'$'
| 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 |
- premitive data type example:
- public class Main
- {
- public static void main(String args[])
- {
- boolean flag = true;
- char ch = 'z';
- int num = 1234;
- byte size = 2;
- short srt = 78;
- double value = 2.4546778;
- float temp = 3.8f;
- long val = 1888889;
- System.out.println("boolean: " + flag);
- System.out.println("char: " + ch);
- System.out.println("integer: " + num);
- System.out.println("byte: " + size);
- System.out.println("short: " + srt);
- System.out.println("float: " + value);
- System.out.println("double: " + temp);
- System.out.println("long: " + val);
- }
- }
- 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:
-
Classes – Blueprint of objects that can have properties (fields) and methods.
-
Interfaces – Define a contract of methods that classes must implement.
-
Strings – Represents a sequence of characters.
-
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:
🔹 తెలుగు వివరణ:
Java లో Non-Primitive Data Types అంటే, వేరియబుల్లో డేటా నేరుగా నిల్వ కావడం కాదు.
ఇవి reference (memory address) ను నిల్వ చేస్తాయి, డేటా అదే address లో ఉంటుంది.
నాన్-ప్రిమిటివ్ డేటా టైపుల ఉదాహరణలు:
-
Classes – Objects కు blueprint. Fields & methods ఉంటాయి.
-
Interfaces – Methods contract, classes implement చేయాలి.
-
Strings – అక్షరాల సీక్వెన్స్ నిల్వ చేయడానికి.
-
Arrays – ఒకే type లోని multiple values నిల్వ చేయడానికి.
ప్రధాన విషయాలు:
-
Complex data నిల్వ చేయగలవు.
-
Size primitive types లా fixed కాదు.
-
Constructors / new keyword ద్వారా objects create చేస్తారు.
ఉదాహరణ:
🧩 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:
| Feature | Primitive Data Types | Non-Primitive Data Types |
|---|---|---|
| Definition | Predefined and built into Java language | Created by the programmer (except String) |
| Example | int, float, boolean, char | String, Array, Class, Interface |
| Usage | Stores actual value | Refers to an object in memory |
| Methods | Cannot call methods | Can call methods (e.g., str.length()) |
| Letter Case | Starts with lowercase letter (e.g., int) | Starts with uppercase letter (e.g., String) |
| Null Values | Cannot be null | Can be null |
| Memory Type | Stored in Stack memory | Stored in Heap memory (reference in Stack) |
💡 Example:
🔹 తెలుగు వివరణ:
Non-Primitive Data Types అంటే Java లోని Reference Types.
ఇవి objects కు reference (memory address) ను సూచిస్తాయి, actual value కాదు.
ఇవి సాధారణంగా programmer సృష్టించినవి (కానీ String మాత్రమే predefined).
🧠 Primitive మరియు Non-Primitive Data Types మధ్య తేడాలు:
| లక్షణం | Primitive Data Types | Non-Primitive Data Types |
|---|---|---|
| అర్ధం | Java లో predefined గా ఉంటాయి | Programmer create చేసినవి (String తప్ప) |
| ఉదాహరణలు | int, float, boolean, char | String, Array, Class, Interface |
| వాడుక | Actual value నిల్వ చేస్తుంది | Object memory reference ను సూచిస్తుంది |
| మెతడ్స్ | Methods ఉండవు | Methods వాడవచ్చు (str.length() వంటి) |
| Case | చిన్న అక్షరంతో మొదలవుతుంది (int) | పెద్ద అక్షరంతో మొదలవుతుంది (String) |
| Null Values | Null అవ్వవు | Null అవుతాయి |
| Memory Type | Stack memory లో నిల్వ అవుతుంది | Heap memory లో data, Stack లో reference ఉంటుంది |
💡 ఉదాహరణ:
🧩 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:
varcan 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:
In this example:
-
The compiler automatically detects the type of
xasint, -
nameasString, -
priceasdouble.
🔹 తెలుగు వివరణ:
var కీవర్డ్ ను Java 10 (2018) లో పరిచయం చేశారు.
ఇది వేరియబుల్ యొక్క టైప్ను కంపైలర్ ఆటోమేటిక్గా గుర్తించేలా (type inference) చేస్తుంది.
ఇది కోడ్ను చిన్నగా, క్లియర్గా మరియు సులభంగా చదవదగినదిగా చేస్తుంది, ముఖ్యంగా పెద్ద లేదా కాంప్లెక్స్ టైప్స్ ఉన్నప్పుడు.
💡 గమనించాల్సిన విషయాలు:
varను methods లోపల మాత్రమే ఉపయోగించవచ్చు (local variables కోసం).Class fields, method parameters లేదా return types కోసం వాడలేము.
Variable టైప్ compile time లోనే నిర్ణయించబడుతుంది, runtime లో కాదు.
✅ ఉదాహరణ:
ఈ ఉదాహరణలో:
-
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