aspose file tools*
The moose likes Beginning Java and the fly likes Compile time Difference between // and /* */ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Compile time Difference between // and /* */" Watch "Compile time Difference between // and /* */" New topic
Author

Compile time Difference between // and /* */

Ramakrishna Nalla
Ranch Hand

Joined: Apr 21, 2005
Posts: 61
Hi...
what is the difference between two type of comment lines between // and /*..*/
Check below code...and give me detail discription...



No errors If I use /*...*/ type comment....please...help
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
It's not the comments that are causing the problem it's the unicode character.

The first thing the compiler does is replace all unicode characters with their value so the line:

becomes

When you use /*...*/ The line becomes:


understand?
[ April 21, 2005: Message edited by: Steven Bell ]
Ramakrishna Nalla
Ranch Hand

Joined: Apr 21, 2005
Posts: 61
Thanks.. ...One more doubt



As quoted in comments Compile time errors are comming.. Please explain...
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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?

Layne


Java API Documentation
The Java Tutorial
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
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?
Ramakrishna Nalla
Ranch Hand

Joined: Apr 21, 2005
Posts: 61
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
Edwin Keeton
Ranch Hand

Joined: Jul 10, 2002
Posts: 214

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.


SCJP, SCWCD
Ramakrishna Nalla
Ranch Hand

Joined: Apr 21, 2005
Posts: 61
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.
Jon Egan
Ranch Hand

Joined: Mar 24, 2004
Posts: 83
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 ;-)

-- Jon
Ramakrishna Nalla
Ranch Hand

Joined: Apr 21, 2005
Posts: 61
Thanx For your BIG reply ...As i am New to JAVA, So please Suggest me some good Stuff for SCJP...
Stuart Gray
Ranch Hand

Joined: Apr 21, 2005
Posts: 410
I'm wondering if there isn't anything in the new java.util.Formatter class in 1.5 that might help (haven't had time to check these new features out myself yet).
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Compile time Difference between // and /* */