What does this mean if a byte has single quotes ('') around a number?

One of the questions I had for my computer science class asked this question.

byte fun = '0';
System.out.println(fun);

The answer is 48, but no one in my class knows how it works, or what it means. We know what bytes are, but what does it mean to have single quotes around them?

+4
source share
3 answers

The value in single quotes is not byte, it is a literal char. Java translates it into its UNICODE-16 numeric value for assignment.

, , , , , , Java , , , . , short byte:

byte b = 100;

, 100 int, , byte, , byte.

: UNICODE-16 128, .

,

byte a = '';

: : char

+2

.

'0' - 0 ( char), 48. byte , 48 a byte.

+2

char Java.

, '0' char;

(. Java - char ( ) , ?, )

+1

All Articles