Java Programming - Language Fundamentals - Discussion
Discussion Forum : Language Fundamentals - General Questions (Q.No. 14)
14.
What is the numerical range of a char?
Answer: Option
Explanation:
A char is really a 16-bit integer behind the scenes, so it supports 216 (from 0 to 65535) values.
Discussion:
19 comments Page 1 of 2.
Sri said:
6 years ago
What is the numerical range for other data types?
Prajakta said:
8 years ago
What's the difference between 0 to 32767 and 0 to 65535? Please explain it.
(1)
M. Sheliga said:
8 years ago
As long as you are converting char (16bits) to int (32 bits), the range is 0 to 65535.
If you convert char to short (which requires a cast), the range is -32K to +32K.
public class CharToInt
{
public static void main(String[] args)
{
int i = '\u0000';
System.out.println("bs u 0000 is: " + i);
i = 'A';
System.out.println("A is: " + i);
i = 'B';
System.out.println("B is: " + i);
i = '\uffff';
System.out.println("bs u ffff is: " + i);
short s = (short) '\uffff'; // compiler error without cast
System.out.println("bs u ffff short is: " + s);
s = (short) '\u8000'; // compiler error without cast
System.out.println("bs u ffff short is: " + s);
}
}
-----------------------------------
bs u 0000 is: 0
A is: 65
B is: 66
bs u ffff is: 65535
bs u ffff short is: -1
bs u ffff short is: -32768
If you convert char to short (which requires a cast), the range is -32K to +32K.
public class CharToInt
{
public static void main(String[] args)
{
int i = '\u0000';
System.out.println("bs u 0000 is: " + i);
i = 'A';
System.out.println("A is: " + i);
i = 'B';
System.out.println("B is: " + i);
i = '\uffff';
System.out.println("bs u ffff is: " + i);
short s = (short) '\uffff'; // compiler error without cast
System.out.println("bs u ffff short is: " + s);
s = (short) '\u8000'; // compiler error without cast
System.out.println("bs u ffff short is: " + s);
}
}
-----------------------------------
bs u 0000 is: 0
A is: 65
B is: 66
bs u ffff is: 65535
bs u ffff short is: -1
bs u ffff short is: -32768
(1)
Sagar said:
8 years ago
@Debasish.
In Java all the datatypes are signed, so is character datatype exempted from this rule.
Which I think is correct because ASCII value for any character cannot be negative. Please correct me, if I am wrong.
In Java all the datatypes are signed, so is character datatype exempted from this rule.
Which I think is correct because ASCII value for any character cannot be negative. Please correct me, if I am wrong.
Abu Dhabi said:
9 years ago
@Ieo.
Volatile Keyword is used in synchronization to tell that method is to be shared method.
Volatile Keyword is used in synchronization to tell that method is to be shared method.
Ieo said:
9 years ago
What is a volatile keyword in Java?
Dushyant said:
9 years ago
Hello, can you describe sop?
Rahul Kirpekar said:
1 decade ago
Static means when we create object static things create one copy generate for One Class. For (Each class).
Static things means we can access without create object we can access static Variable with class name dot operator and we also can access same methods. ! we also can create class as a static in Inner class. I hope you understand static keyword of JAVA. !
Static things means we can access without create object we can access static Variable with class name dot operator and we also can access same methods. ! we also can create class as a static in Inner class. I hope you understand static keyword of JAVA. !
V.srinivasreddy said:
1 decade ago
What is static and non-static declaration? how it will be instantiated?
M.Srikanya said:
1 decade ago
The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65,535 inclusive). So Char range is 65535.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers