What is valid value range for char?
A char supports a 16-bit unicode character and is unsigned 2 byte integer. It can be assigned directly to an integer value but the integer value must be in its value range or you would get a compiler error.
The largest number it can hold is 216 which is 65535. The following value ranges are equivalent to represent the value range of char:
| 0 to 216-1 | dec |
| 0 to 65535 | dec |
| 00 to 0177777 | octal |
| 0x0 to 0xFFFF | hex |
| 0000 0000 0000 0000 to 1111 1111 1111 1111 | binary |
| '\u0000' to '\uFFFF' | unicode |
Any numeric assignment to a char could be cast to a char and get past the compiler in this case the char will only contain the right two bytes.
Most Recent java Faqs
- How to uncompress a file in the gzip format?
- How to make a gzip file in Java?
- How to use Java String.split method to split a string by dot?
- How to validate URL in Java?
- How to schedule a job in Java?
- How to return the content in the correct encoding from a servlet?
- What is the difference between JDK and JRE?
Most Viewed java Faqs
- How to read input from console (keyboard) in Java?
- How to use HttpURLConnection POST data to web server?
- How to add BASIC Authentication into HttpURLConnection?
- How to Retrieve Multiple Result Sets from a Stored Procedure in JDBC?
- What are class variables in Java?
- What are local variables in Java?
- How to Use Updatable ResultSet in JDBC?