PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम Java Data Types: 8 Primitive Data Types (byte, short, int, long, float, double, char, boolean) (8 प्रिमिटिव डेटा प्रकार: साइज़, रेंज और डिफ़ॉल्ट मान) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।
Overview: Java is a statically typed language that defines exactly eight primitive data types—byte, short, int, long, float, double, char, and boolean—with platform-independent bit widths specified by the Java Language Specification. Unlike objects, primitives store raw values directly in memory slots without heap allocation overhead, making arithmetic and boolean logic fast and predictable across every hardware architecture.
अध्याय सार: जावा एक स्टैटिकली टाइप्ड भाषा है जो ठीक आठ प्रिमिटिव डेटा प्रकार—byte, short, int, long, float, double, char और boolean—परिभाषित करती है, जिनकी बिट चौड़ाई Java Language Specification द्वारा हर प्लेटफॉर्म पर समान तय की गई है। ऑब्जेक्ट्स के विपरीत, प्रिमिटिव सीधे मेमोरी स्लॉट में मान संग्रहीत करते हैं, जिससे बिना हीप ओवरहेड के तेज़ और सटीक अंकगणितीय व तार्किक गणना संभव होती है।
Java Data Types: 8 Primitive Data Types (byte, short, int, long, float, double, char, boolean): Detailed Notes & Architecture (8 प्रिमिटिव डेटा प्रकार: साइज़, रेंज और डिफ़ॉल्ट मान)
1. Signed Integral Types: byte, short, int, and long (साइन्ड इंटीजर प्रकार: byte, short, int और long)
[EN] Java provides four signed two's-complement integer types with strictly fixed sizes across all CPUs: byte (8-bit, -128 to 127), short (16-bit, -32,768 to 32,767), int (32-bit, -2^31 to 2^31 - 1), and long (64-bit, -2^63 to 2^63 - 1). The default type for any integer literal such as 100 is int; literals exceeding int range require an 'L' or 'l' suffix (for example, 9000000000L), with uppercase 'L' strongly preferred so it is not confused with the digit 1. All four integral types default to 0 (0L for long) when declared as class or instance fields, and Java 7+ permits underscores in numeric literals like 1_000_000 for readability. Because Java integers have no unsigned variants (except char), integer overflow silently wraps around modulo 2^n without raising an exception unless Math.addExact() is used.
[HI] जावा सभी CPU पर निश्चित आकार के चार साइन्ड टूज़-कॉम्प्लिमेंट इंटीजर प्रकार प्रदान करता है: byte (8-बिट, -128 से 127), short (16-बिट, -32,768 से 32,767), int (32-बिट, -2^31 से 2^31 - 1), तथा long (64-बिट, -2^63 से 2^63 - 1)। 100 जैसे किसी भी पूर्णांक लिटरल का डिफ़ॉल्ट प्रकार int होता है; int सीमा से बड़े लिटरल के लिए अंत में 'L' या 'l' प्रत्यय (जैसे 9000000000L) लगाना आवश्यक होता है। क्लास या इंस्टेंस फ़ील्ड होने पर इन चारों का डिफ़ॉल्ट मान 0 (long के लिए 0L) होता है, तथा Java 7+ में पठनीयता हेतु 1_000_000 जैसे अंडरस्कोर अनुमत हैं। ओवरफ़्लो होने पर जावा बिना किसी एरर के मॉड्यूलो 2^n के अनुसार मान को रैप-अराउंड कर देता है।
2. IEEE 754 Floating-Point Types: float and double (IEEE 754 फ़्लोटिंग-पॉइंट प्रकार: float और double)
[EN] Decimal and fractional numbers are represented by two IEEE 754 binary floating-point types: float (32-bit single-precision, ~6 to 7 significant decimal digits, default 0.0f) and double (64-bit double-precision, ~15 significant decimal digits, default 0.0d). Every decimal literal like 3.14 defaults to double in Java; assigning 3.14 directly to a float variable causes a compile-time error unless suffixed with 'f' or 'F' (3.14f). Both float and double support special IEEE 754 values—POSITIVE_INFINITY, NEGATIVE_INFINITY, and NaN (Not-a-Number, where NaN == NaN always evaluates to false). Because binary floating-point cannot represent base-10 fractions like 0.1 exactly, financial calculations in Java should use java.math.BigDecimal rather than float or double.
[HI] दशमलव और भिन्नात्मक संख्याओं के लिए जावा में दो IEEE 754 बाइनरी फ़्लोटिंग-पॉइंट प्रकार हैं: float (32-बिट सिंगल-प्रिसिजन, ~6-7 सार्थक अंक, डिफ़ॉल्ट 0.0f) और double (64-बिट डबल-प्रिसिजन, ~15 सार्थक अंक, डिफ़ॉल्ट 0.0d)। जावा में 3.14 जैसा हर दशमलव लिटरल डिफ़ॉल्ट रूप से double होता है; अतः इसे float में रखने के लिए 'f' या 'F' प्रत्यय (3.14f) जोड़ना अनिवार्य है। float और double दोनों POSITIVE_INFINITY, NEGATIVE_INFINITY और NaN (जहाँ NaN == NaN हमेशा false होता है) का समर्थन करते हैं। चूंकि बाइनरी फ़्लोटिंग-पॉइंट 0.1 जैसे दशमलव का सटीक प्रतिनिधित्व नहीं कर पाता, इसलिए वित्तीय गणनाओं के लिए BigDecimal का उपयोग अनुशंसित है।
3. Character Type (char) and Logical Type (boolean) (कैरेक्टर प्रकार (char) और लॉजिकल प्रकार (boolean))
[EN] Unlike C/C++ where char is an 8-bit ASCII signed or unsigned byte, Java's char is strictly a 16-bit (2-byte) unsigned integer representing a UTF-16 code unit in the range 0 to 65,535 ('\u0000' to '\uffff'). Because char is unsigned numeric internally, integer literals between 0 and 65535 (such as char c = 65; yielding 'A') and arithmetic operations on char are valid. The boolean type stores only two logical literals—true and false—with a default field value of false, and cannot be converted to or from integers (unlike C, 0 and 1 are never booleans). While a boolean logically represents 1 bit of information, the JVM Specification leaves its exact storage size implementation-dependent (typically 1 byte in boolean[] arrays and 4 bytes as an int slot on the JVM operand stack).
[HI] C/C++ के 8-बिट ASCII char के विपरीत, जावा में char एक 16-बिट (2-बाइट) अनसाइन्ड पूर्णांक है जो 0 से 65,535 ('\u0000' से '\uffff') रेंज में UTF-16 कोड यूनिट का प्रतिनिधित्व करता है। आंतरिक रूप से अनसाइन्ड संख्यात्मक होने के कारण char में 0 से 65535 तक की संख्याएँ (जैसे char c = 65; अर्थात 'A') और अंकगणितीय संक्रियाएँ वैध हैं। boolean प्रकार केवल दो तार्किक मान—true और false—संग्रहीत करता है (डिफ़ॉल्ट false), और इसे किसी संख्या (0 या 1) में कास्ट नहीं किया जा सकता। हालांकि तार्किक रूप से boolean 1 बिट जानकारी दर्शाता है, JVM विनिर्देश के अनुसार इसकी वास्तविक मेमोरी खपत इम्प्लीमेंटेशन पर निर्भर करती है (आमतौर पर boolean[] एरे में 1 बाइट और स्टैक पर 4-बाइट int स्लॉट)।
4. Default Values: Fields vs Local Variables (डिफ़ॉल्ट मान: क्लास फ़ील्ड बनाम लोकल वेरिएबल)
[EN] A common exam trap in Java concerns when primitive default values actually apply. Instance variables (non-static fields) and static class variables are automatically zero-initialized by the JVM (0 for integers, 0.0 for floating-point, '\u0000' for char, and false for boolean) if not explicitly assigned. Array elements allocated with 'new' (for example, new int[5]) also receive these exact primitive default values. In contrast, local variables declared inside methods, constructors, or blocks NEVER receive automatic default values; reading an uninitialized local variable results in an immediate compile-time error ('variable might not have been initialized').
[HI] जावा परीक्षाओं का एक प्रमुख विषय यह है कि प्रिमिटिव डिफ़ॉल्ट मान वास्तव में कहाँ लागू होते हैं। इंस्टेंस वेरिएबल्स (नॉन-स्टैटिक फ़ील्ड्स) और स्टैटिक क्लास वेरिएबल्स को स्पष्ट मान न देने पर JVM स्वतः शून्य-इनिशियलाइज़ (पूर्णांकों के लिए 0, दशमलव के लिए 0.0, char के लिए '\u0000' और boolean के लिए false) कर देता है। 'new' द्वारा बनाए गए एरे के तत्वों (जैसे new int[5]) को भी यही डिफ़ॉल्ट मान प्राप्त होते हैं। इसके विपरीत, मेथड या ब्लॉक के भीतर घोषित लोकल वेरिएबल्स को कभी कोई डिफ़ॉल्ट मान नहीं मिलता; बिना इनिशियलाइज़ किए उन्हें पढ़ने पर तुरंत कंपाइल-टाइम त्रुटि आती है।
Syntax, Formula & Technical Example (Java Data Types: 8 Primitive Data Types (byte, short, int, long, float, double, char, boolean))
public class PrimitiveTypesDemo {
static int defInt; // Default: 0; boolean default: false
public static void main(String[] args) {
byte b = 127; // 8-bit (-128 to 127)
long pop = 8_100_000_000L; // 64-bit; L suffix required
float pi = 3.14159f; // 32-bit IEEE 754; f suffix required
char grade = 65; boolean active = true; // 16-bit unsigned UTF-16 ('A')
System.out.println(b + ", " + pop + ", " + pi + ", " + grade + ", " + active + ", " + defInt);
}
}
Java Data Types: 8 Primitive Data Types (byte, short, int, long, float, double, char, boolean) Quick Reference & Comparison Table
| Primitive Type | Size & Range | Key Exam Fact |
|---|---|---|
| byte | 8-bit (1 byte); -128 to 127 | Smallest signed integer type; default value 0 |
| long | 64-bit (8 bytes); -2^63 to 2^63 - 1 | Requires 'L' suffix for values beyond int range |
| float | 32-bit (4 bytes); IEEE 754 single-precision | Requires 'f'/'F' suffix because 3.14 defaults to double |
| char | 16-bit (2 bytes); 0 to 65,535 (unsigned UTF-16) | Only unsigned primitive numeric type; default '\u0000' |
Java Data Types: 8 Primitive Data Types (byte, short, int, long, float, double, char, boolean) Top 20 Bilingual MCQs with Answers
Q1. How many primitive data types are defined in the Java programming language?
(जावा प्रोग्रामिंग भाषा में कुल कितने प्रिमिटिव डेटा प्रकार परिभाषित हैं?)
(A) 8
(B) 6
(C) 7
(D) 9
Correct Answer: (A)
[EN] Java specifies exactly 8 primitive types: byte, short, int, long, float, double, char, and boolean (String is non-primitive).
[HI] जावा में ठीक 8 प्रिमिटिव डेटा प्रकार हैं: byte, short, int, long, float, double, char और boolean (String एक नॉन-प्रिमिटिव क्लास है)।
Q2. What is the exact bit width and numeric range of a Java 'byte' data type?
(जावा के 'byte' डेटा प्रकार की सटीक बिट चौड़ाई और संख्यात्मक रेंज क्या है?)
(A) 16 bits; -32,768 to 32,767
(B) 8 bits; -127 to 128
(C) 8 bits; -128 to 127
(D) 8 bits; 0 to 255
Correct Answer: (C)
[EN] A Java byte is an 8-bit signed two's complement integer spanning from -2^7 (-128) to 2^7 - 1 (127).
[HI] जावा का byte एक 8-बिट साइन्ड टूज़-कॉम्प्लिमेंट पूर्णांक है जिसकी सीमा -2^7 (-128) से 2^7 - 1 (127) तक होती है।
Q3. What is the size and character encoding of Java's 'char' primitive type?
(जावा के 'char' प्रिमिटिव प्रकार का आकार और कैरेक्टर एन्कोडिंग क्या है?)
(A) 4 bytes (32-bit signed UTF-32)
(B) 2 bytes (16-bit unsigned UTF-16)
(C) 1 byte (8-bit signed ASCII)
(D) 1 byte (8-bit unsigned ASCII)
Correct Answer: (B)
[EN] Java allocates 2 bytes (16 bits, unsigned 0 to 65,535) for char to store UTF-16 code units rather than 1-byte ASCII as in C.
[HI] जावा में UTF-16 कोड यूनिट्स रखने के लिए char को 2 बाइट्स (16-बिट अनसाइन्ड, 0 से 65,535) आवंटित किए जाते हैं।
Q4. Why does the declaration 'float rate = 5.5;' fail to compile in Java?
(जावा में 'float rate = 5.5;' घोषणा कंपाइल होने में विफल क्यों होती है?)
(A) float cannot hold fractional values greater than 1.0
(B) 5.5 exceeds the maximum exponent of 32-bit float
(C) The '=' operator cannot initialize float variables
(D) Decimal literals like 5.5 default to double, causing possible lossy conversion to float
Correct Answer: (D)
[EN] In Java, every floating-point literal without an 'f' or 'F' suffix is treated as a 64-bit double, which cannot implicitly narrow into a 32-bit float.
[HI] जावा में 'f' या 'F' प्रत्यय के बिना प्रत्येक दशमलव लिटरल 64-बिट double माना जाता है, जो स्वतः 32-बिट float में संकुचित नहीं हो सकता।
Q5. Which primitive data type in Java is unsigned?
(जावा में निम्नलिखित में से कौन सा प्रिमिटिव डेटा प्रकार अनसाइन्ड (unsigned) है?)
(A) int
(B) byte
(C) short
(D) char
Correct Answer: (D)
[EN] byte, short, int, and long are all signed two's complement types; char (0 to 65,535) is the sole unsigned primitive type.
[HI] byte, short, int और long सभी साइन्ड टूज़-कॉम्प्लिमेंट प्रकार हैं; केवल char (0 से 65,535) ही एकमात्र अनसाइन्ड प्रिमिटिव प्रकार है।
Q6. What is the default value of an uninitialized local 'int x;' declared inside a method?
(किसी मेथड के भीतर घोषित बिना इनिशियलाइज़ किए गए लोकल 'int x;' का डिफ़ॉल्ट मान क्या होता है?)
(A) No default value; reading it produces a compile-time error
(B) 0
(C) null
(D) Garbage value from stack memory
Correct Answer: (A)
[EN] Unlike instance or static fields, local variables inside methods are never given default values by Java and must be explicitly initialized before use.
[HI] इंस्टेंस या स्टैटिक फ़ील्ड्स के विपरीत, मेथड्स के भीतर लोकल वेरिएबल्स को कोई डिफ़ॉल्ट मान नहीं मिलता और बिना मान दिए पढ़ने पर कंपाइल-टाइम त्रुटि आती है।
Q7. What is the default value of an instance field of type 'char' in a Java class?
(किसी जावा क्लास में 'char' प्रकार के इंस्टेंस फ़ील्ड का डिफ़ॉल्ट मान क्या होता है?)
(A) '\u0000' (numeric 0)
(B) '0'
(C) ' ' (space character 32)
(D) null
Correct Answer: (A)
[EN] Class and instance char fields default to the null Unicode character '\u0000', whose integer value is 0.
[HI] क्लास और इंस्टेंस char फ़ील्ड्स का डिफ़ॉल्ट मान '\u0000' होता है, जिसका संख्यात्मक मान 0 है।
Q8. What happens if you assign 'boolean flag = 1;' in Java?
(यदि आप जावा में 'boolean flag = 1;' लिखते हैं तो क्या होता है?)
(A) Compile-time error: incompatible types (int cannot be converted to boolean)
(B) Runtime ClassCastException
(C) flag becomes true
(D) flag becomes false
Correct Answer: (A)
[EN] Java strictly separates boolean from integers; only the literals true and false or boolean expressions may be assigned to boolean.
[HI] जावा में boolean को पूर्णांकों से पूरी तरह अलग रखा गया है; boolean को केवल true, false या तार्किक अभिव्यक्ति ही दी जा सकती है।
Q9. Which primitive range is -32,768 to 32,767?
(किस प्रिमिटिव डेटा प्रकार की रेंज -32,768 से 32,767 होती है?)
(A) int
(B) byte
(C) short
(D) char
Correct Answer: (C)
[EN] short is a 16-bit signed integer covering -2^15 (-32,768) through 2^15 - 1 (32,767).
[HI] short एक 16-बिट साइन्ड पूर्णांक है जिसकी सीमा -2^15 (-32,768) से 2^15 - 1 (32,767) तक होती है।
Q10. What is the output of 'System.out.println(0.0 / 0.0 == Double.NaN);' in Java?
(जावा में 'System.out.println(0.0 / 0.0 == Double.NaN);' का आउटपुट क्या होगा?)
(A) Compile-time error
(B) false
(C) true
(D) ArithmeticException at runtime
Correct Answer: (B)
[EN] Under IEEE 754 rules implemented in Java, 0.0/0.0 yields Double.NaN, and any equality comparison involving NaN (even NaN == NaN) evaluates to false; use Double.isNaN() instead.
[HI] IEEE 754 नियमों के अनुसार 0.0/0.0 का मान Double.NaN होता है, और NaN की किसी भी तुलना (यहाँ तक कि NaN == NaN भी) का परिणाम हमेशा false आता है।
Q11. Which prefix represents a hexadecimal integer literal in Java?
(जावा में कौन सा उपसर्ग (prefix) हेक्साडेसिमल इंटीजर लिटरल को दर्शाता है?)
(A) Leading 0 alone
(B) 0x or 0X
(C) 0h or 0H
(D) 0b or 0B
Correct Answer: (B)
[EN] In Java, 0x/0X denotes hexadecimal (base 16), 0b/0B denotes binary (base 2, Java 7+), and a leading 0 alone denotes octal (base 8).
[HI] जावा में 0x/0X हेक्साडेसिमल (आधार 16), 0b/0B बाइनरी (आधार 2) तथा केवल शुरुआती 0 ऑक्टल (आधार 8) लिटरल को दर्शाता है।
Q12. What is the decimal value of the literal 'int num = 012;' in Java?
(जावा में 'int num = 012;' का दशमलव (decimal) मान क्या होगा?)
(A) Compile-time error
(B) 18
(C) 10
(D) 12
Correct Answer: (C)
[EN] An integer literal starting with a leading zero (012) is interpreted in base-8 (octal): 1 * 8 + 2 = 10.
[HI] शुरुआती शून्य से आरंभ होने वाला पूर्णांक लिटरल (012) ऑक्टल (आधार 8) में पढ़ा जाता है: 1 * 8 + 2 = 10।
Q13. Which primitive type has approximately 15 significant decimal digits of precision?
(किस प्रिमिटिव प्रकार में लगभग 15 सार्थक दशमलव अंकों की सटीकता (precision) होती है?)
(A) float
(B) short
(C) long
(D) double
Correct Answer: (D)
[EN] 64-bit IEEE 754 double has a 52-bit explicit significand (53 bits effective), providing roughly 15–17 decimal digits of precision versus ~6–7 for float.
[HI] 64-बिट IEEE 754 double में 53-बिट प्रभावी सिग्निफिकैंड होता है जो लगभग 15 सार्थक दशमलव अंकों की सटीकता देता है, जबकि float में ~6-7 अंक होते हैं।
Q14. What happens in Java when 'byte b = 127; b++;' is executed?
(जावा में 'byte b = 127; b++;' निष्पादित करने पर क्या होगा?)
(A) b wraps around to -128
(B) ArithmeticException is thrown at runtime
(C) Compile-time overflow error
(D) b becomes 128
Correct Answer: (A)
[EN] Adding 1 to Byte.MAX_VALUE (127 = 01111111 in binary) overflows into 10000000 in two's complement, which represents -128.
[HI] Byte.MAX_VALUE (127 = बाइनरी 01111111) में 1 जोड़ने पर टूज़-कॉम्प्लिमेंट ओवरफ़्लो होकर बाइनरी 10000000 बनता है, जो -128 का मान है।
Q15. Why is 'java.math.BigDecimal' preferred over 'double' for currency calculations?
(मुद्रा (currency) की गणनाओं के लिए 'double' के बजाय 'java.math.BigDecimal' को प्राथमिकता क्यों दी जाती है?)
(A) double does not support subtraction or division
(B) BigDecimal is a 16-bit primitive stored in CPU registers
(C) double uses binary floating-point and cannot represent fractions like 0.1 exactly
(D) double throws ArithmeticException on 0.1 + 0.2
Correct Answer: (C)
[EN] Binary IEEE 754 floating-point produces tiny rounding inaccuracies (e.g., 0.1 + 0.2 == 0.30000000000000004), whereas BigDecimal performs exact base-10 arithmetic.
[HI] बाइनरी IEEE 754 फ़्लोटिंग-पॉइंट में 0.1 + 0.2 जैसे योग में सूक्ष्म राउंडिंग त्रुटि (0.30000000000000004) आती है, जबकि BigDecimal सटीक बेस-10 गणना करता है।
Q16. Which statement regarding Java's 8 primitive data types is INCORRECT?
(जावा के 8 प्रिमिटिव डेटा प्रकारों के बारे में निम्नलिखित में से कौन सा कथन गलत है?)
(A) Underscores like 1_000_000 are valid in numeric literals since Java 7
(B) All 8 primitive types start with lowercase keywords
(C) A boolean field defaults to false when uninitialized
(D) The size of an int varies between 16 bits and 32 bits depending on the OS
Correct Answer: (D)
[EN] Unlike C/C++, Java strictly fixes int to 32 bits (4 bytes) on all 16-bit, 32-bit, and 64-bit operating systems.
[HI] C/C++ के विपरीत, जावा में int का आकार सभी ऑपरेटिंग सिस्टम पर सख्ती से 32 बिट्स (4 बाइट्स) निश्चित होता है।
Q17. Within Java Data Types: 8 Primitive Data Types (byte, short, int, long, float, double, char, boolean), which primitive type directly maps to: "8-bit (1 byte); -128 to 127"?
(Java Data Types: 8 Primitive Data Types (byte, short, int, long, float, double, char, boolean) में कौन सा Primitive Type सीधे "8-bit (1 byte); -128 to 127" से संबंधित है?)
(A) long
(B) byte
(C) char
(D) float
Correct Answer: (B)
[EN] In Java Data Types: 8 Primitive Data Types (byte, short, int, long, float, double, char, boolean), 'byte' handles '8-bit (1 byte); -128 to 127' (Smallest signed integer type; default value 0).
[HI] Java Data Types: 8 Primitive Data Types (byte, short, int, long, float, double, char, boolean) में 'byte' का कार्य/विवरण '8-bit (1 byte); -128 to 127' (Smallest signed integer type; default value 0) है।
Q18. Which option accurately describes 'long' in Java Data Types: 8 Primitive Data Types (byte, short, int, long, float, double, char, boolean)?
(Java Data Types: 8 Primitive Data Types (byte, short, int, long, float, double, char, boolean) के संदर्भ में 'long' की सही विशेषता कौन सी है?)
(A) 8-bit (1 byte); -128 to 127
(B) 64-bit (8 bytes); -2^63 to 2^63 - 1
(C) 32-bit (4 bytes); IEEE 754 single-precision
(D) 16-bit (2 bytes); 0 to 65,535 (unsigned UTF-16)
Correct Answer: (B)
[EN] 'long' provides '64-bit (8 bytes); -2^63 to 2^63 - 1' — key point: Requires 'L' suffix for values beyond int range.
[HI] 'long' का मुख्य विवरण '64-bit (8 bytes); -2^63 to 2^63 - 1' है (Requires 'L' suffix for values beyond int range)।
Q19. In Java Data Types: 8 Primitive Data Types (byte, short, int, long, float, double, char, boolean), identify the correct parameter for the specification: "32-bit (4 bytes); IEEE 754 single-precision".
(Java Data Types: 8 Primitive Data Types (byte, short, int, long, float, double, char, boolean) में "32-bit (4 bytes); IEEE 754 single-precision" विवरण किस विकल्प के लिए सही है?)
(A) byte
(B) float
(C) char
(D) long
Correct Answer: (B)
[EN] 'float' corresponds to '32-bit (4 bytes); IEEE 754 single-precision' (Requires 'f'/'F' suffix because 3.14 defaults to double).
[HI] 'float' का संबंध '32-bit (4 bytes); IEEE 754 single-precision' (Requires 'f'/'F' suffix because 3.14 defaults to double) से है।
Q20. Considering Java Data Types: 8 Primitive Data Types (byte, short, int, long, float, double, char, boolean), what key behavior defines 'char'?
(Java Data Types: 8 Primitive Data Types (byte, short, int, long, float, double, char, boolean) में 'char' की मुख्य भूमिका या मान क्या है?)
(A) 64-bit (8 bytes); -2^63 to 2^63 - 1
(B) 32-bit (4 bytes); IEEE 754 single-precision
(C) 16-bit (2 bytes); 0 to 65,535 (unsigned UTF-16)
(D) 8-bit (1 byte); -128 to 127
Correct Answer: (C)
[EN] 'char' represents '16-bit (2 bytes); 0 to 65,535 (unsigned UTF-16)' (Only unsigned primitive numeric type; default '\u0000').
[HI] 'char' का अर्थ/मान '16-bit (2 bytes); 0 to 65,535 (unsigned UTF-16)' है (Only unsigned primitive numeric type; default '\u0000')।
Java Data Types: 8 Primitive Data Types (byte, short, int, long, float, double, char, boolean) — Exam FAQs
Q1: Why is the size of a Java boolean said to be JVM-dependent?
जावा में boolean का मेमोरी आकार JVM पर निर्भर क्यों कहा जाता है?
[EN] The JVM has no dedicated 1-bit instructions. Instead, the JVM Specification encodes standalone boolean variables as 32-bit int slots on the stack/locals and maps boolean[] arrays to 8-bit byte arrays (1 byte per element) for compactness.
[HI] JVM में 1-बिट के अलग निर्देश नहीं होते। इसलिए JVM विनिर्देश स्टैक और लोकल वेरिएबल्स में अकेले boolean को 32-बिट int स्लॉट में तथा boolean[] एरे को मेमोरी बचत के लिए 1-बाइट प्रति तत्व के रूप में संग्रहीत करता है।
Q2: Why does Java still keep primitives instead of making everything an Object?
जावा ने सब कुछ Object बनाने के बजाय प्रिमिटिव डेटा प्रकारों को क्यों बनाए रखा है?
[EN] Primitives avoid heap allocation, object headers (12-16 bytes), pointer indirection, and garbage collection overhead, making tight numeric loops dramatically faster and more memory-efficient.
[HI] प्रिमिटिव डेटा प्रकार हीप एलोकेशन, ऑब्जेक्ट हेडर (12-16 बाइट्स), पॉइंटर इंडायरेक्शन और गार्बेज कलेक्शन ओवरहेड से बचाते हैं, जिससे संख्यात्मक लूप्स अत्यंत तेज़ और मेमोरी-कुशल बनते हैं।
Q3: When can you assign an int literal directly to a byte or char without a cast?
बिना टाइप कास्ट किए कब एक int लिटरल को सीधे byte या char को दिया जा सकता है?
[EN] When the right-hand side is a compile-time constant expression whose value fits within the target type's range (e.g., byte b = 100; or char c = 65;), Java performs an implicit narrowing conversion automatically.
[HI] जब दाईं ओर कोई कंपाइल-टाइम कांस्टेंट अभिव्यक्ति हो जिसका मान लक्ष्य प्रकार की सीमा के भीतर आता हो (जैसे byte b = 100; या char c = 65;), तब जावा स्वतः इम्प्लिसिट नैरोइंग रूपांतरण कर देता है।
Post a Comment
Post a Comment