Java provides several primitive data types to store different kinds of data such as numbers, characters, and boolean values. These include byte
, short
, int
, long
, float
, double
, char
, and boolean
.
Java कई प्रकार के primitive data types देता है जिनसे numbers, characters, और boolean values को store किया जाता है। इनमें byte
, short
, int
, long
, float
, double
, char
, और boolean
शामिल हैं।
public class Main {
public static void main(String[] args) {
byte b = 127;
System.out.println("byte value: " + b);
}
}
Explanation (English): byte is an 8-bit signed integer with range -128 to 127.
Explanation (Hinglish): byte एक 8-bit signed integer है जिसका range -128 से 127 तक होता है।
Output:byte value: 127
public class Main {
public static void main(String[] args) {
short s = 32767;
System.out.println("short value: " + s);
}
}
Explanation (English): short is a 16-bit signed integer with range -32,768 to 32,767.
Explanation (Hinglish): short एक 16-bit signed integer है जिसका range -32,768 से 32,767 तक होता है।
Output:short value: 32767
public class Main {
public static void main(String[] args) {
int i = 100000;
System.out.println("int value: " + i);
}
}
Explanation (English): int is a 32-bit signed integer with range -2,147,483,648 to 2,147,483,647.
Explanation (Hinglish): int एक 32-bit signed integer है जिसका range -2,147,483,648 से 2,147,483,647 तक होता है।
Output:int value: 100000
public class Main {
public static void main(String[] args) {
long l = 123456789012345L;
System.out.println("long value: " + l);
}
}
Explanation (English): long is a 64-bit signed integer with a large range.
Explanation (Hinglish): long एक 64-bit signed integer है जिसका range बहुत बड़ा होता है।
Output:long value: 123456789012345
public class Main {
public static void main(String[] args) {
float f = 3.14f;
System.out.println("float value: " + f);
}
}
Explanation (English): float is a single-precision 32-bit floating-point number.
Explanation (Hinglish): float एक single-precision 32-bit floating-point नंबर है।
Output:float value: 3.14
public class Main {
public static void main(String[] args) {
double d = 3.141592653589793;
System.out.println("double value: " + d);
}
}
Explanation (English): double is a double-precision 64-bit floating-point number, more precise than float.
Explanation (Hinglish): double एक double-precision 64-bit floating-point नंबर है, जो float से अधिक precise है।
Output:double value: 3.141592653589793
public class Main {
public static void main(String[] args) {
char c = 'A';
System.out.println("char value: " + c);
}
}
Explanation (English): char stores a single 16-bit Unicode character.
Explanation (Hinglish): char एक single 16-bit Unicode character को store करता है।
Output:char value: A
public class Main {
public static void main(String[] args) {
boolean isJavaFun = true;
System.out.println("Is Java fun? " + isJavaFun);
}
}
Explanation (English): boolean holds only two values: true or false.
Explanation (Hinglish): boolean केवल दो मान रखता है: true या false।
Output:Is Java fun? true
public class Main {
public static void main(String[] args) {
int i = 100;
long l = i; // int to long
float f = l; // long to float
System.out.println("int: " + i);
System.out.println("long: " + l);
System.out.println("float: " + f);
}
}
Explanation (English): Widening casting happens automatically when converting smaller to larger types.
Explanation (Hinglish): Widening casting अपने आप होती है जब छोटे type को बड़े type में convert करते हैं।
Output:int: 100
long: 100
float: 100.0
public class Main {
public static void main(String[] args) {
double d = 100.04;
long l = (long)d; // double to long
int i = (int)l; // long to int
System.out.println("double: " + d);
System.out.println("long: " + l);
System.out.println("int: " + i);
}
}
Explanation (English): Narrowing casting must be done manually when converting larger to smaller types.
Explanation (Hinglish): Narrowing casting मैन्युअली करना पड़ता है जब बड़े type को छोटे type में convert करते हैं।
Output:double: 100.04
long: 100
int: 100