This week's book giveaway is in the Agile and Other Processes forum. We're giving away four copies of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java and have Dr. Raoul-Gabriel Urma & Richard Warburton on-line! See this thread for details.
I have a guess, but I suggest that you comment out that line and see if it compiles and runs. I bet the System.out.println() immediately afterwards will give you a clue to why you are getting this compiler error. Specifically, what character does \400 represent?
I just don't understand why you would use such confusing syntax? Are you trying to make the code as difficult to read as possible?
posted 14 years ago
Ok Bell I simplified the code, and I want to learn java through SCJP orient(Preparing for SCJP). Ok and my problem is:
char c='\400'; reprsents octal notation which is equal to 256 decimal notation.(that one is beyond ASCII limit). char c='\145'; -->Eqaul to 101 in Decimal notation. As java uses UNICODE character set, why i am UNABLE to access above 255 character..What's my mistake
The only mistake is that you can only escape octal constants up to '\377'. I don't know why really other than that octal escapes were originally provided for compatibility with C.
Unicode escapes (e.g., '\u0400') are the preferred way of expressing Unicode values.
posted 14 years ago
I tried by this statement : c='\u0400'; As i know that one is Hexadecimal notation, which is equal to 1024 in decimal..My Problem is::::: I just want to print character beyond ASCII range i.e above 255. But on my system all characters above no:255 smiply outputs a (question mark) '?'.
What I have to do .. to Print any UNICODE character.
I had a hunch and went down this trail... I think this is it (the problem, not the solution).
You are trying to System.out.println() the unicode character that is > 255, right?
First, look up System.out - it's a static member variable of System, of type PrintStream.
So then look up PrintStream.println(char x) - it says it behaves like print(char), followed by println().
So then, looked at print(char) - It says "Print a character. The character is translated into one or more bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method"
So then I looked at write(int) - and it says it writes the byte "as given", and that if you want it encoded into the platform's default character encoding, use print(char) or println(char)...
But the point is, you don't want it encoded - you want it printed as is.
So I think what you're looking for is:
for me, that didn't end up displaying anything (it's supposed to be a french lowercase y, with two dots, or "diaeresis", over it). I tried the following, to try printing all the characters "in the neighborhood" of '\u00FF':
One seemed to be a bell, another seemed to be a backspace character... Which sounded to me like the beginning of the ASCII sequence, so I tried it again with the loop going from '\u0000' to '\u000F', and it was nearly (interestingly, it was not exactly) the same sequence of gibberish - dark smiley face, light smiley face, heart, diamond, club, spade...
And then I looked back at that method definition for PrintStream.write(int) again:
write(int) - ...writes the byte "as given"...
so even though you supply an int, it's going to interpret it (must be an explicit cast) as a byte... which means that after 255, we wrap around to 0. I found in the source for PrintStream that it's calling OutputStream.write(int), which is abstract, but the doc says:
"The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored."
Bottom line, I think you're out of luck trying to use System.out with anything bigger than a byte.
I considered looking into whether there was a way to write to a file instead, without the encoding, etc. And then I realized it was late, and I need to quit stalling, and get back to studying for SCJP, since my voucher expires on the 30th. Good luck from here ;-)
posted 14 years ago
Thanx For your BIG reply ...As i am New to JAVA, So please Suggest me some good Stuff for SCJP...