| Author |
What happens when we print null character '\u0000' ?
|
sachin verma
Ranch Hand
Joined: Mar 25, 2008
Posts: 177
|
|
HI I am finding it strange when I am trying to print default value of char type. public class AClass { public static void main(String[] args) { char c='\u0000'; System.out.println("c is "+c); \\IT is working like I have written System.exit(0) here System.out.println("after print "); } } [ May 06, 2008: Message edited by: sachin verma ]
|
SCJP || SCWCD
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
Are you saying that your program exits before outputting "after print"? Does it output "c is"? (It works fine for me, using Mac Terminal.)
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
Stevi Deter
Ranch Hand
Joined: Mar 22, 2008
Posts: 265
|
|
Sachin, I'm not sure why you're having problems. I was able to run the code (once i removed the invalidly escaped comment, should start with "//") just fine. Are you seeing any other errors when you run this code? Also, please use the UBB code tag when posting code.
|
There will always be people who are ahead of the curve, and people who are behind the curve. But knowledge moves the curve. --Bill James
|
 |
sachin verma
Ranch Hand
Joined: Mar 25, 2008
Posts: 177
|
|
Originally posted by: marc weber Are you saying that your program exits before outputting "after print"? Does it output "c is"?
Yes it is working like that printing "c is" and nothing after that Not printing "after print" neither there is any kind of exception propagated [ May 06, 2008: Message edited by: sachin verma ]
|
 |
sridhar row
Ranch Hand
Joined: Jan 16, 2008
Posts: 162
|
|
try this and let us know what you think.
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
|
Hmmm... Are you using an IDE?
|
 |
sachin verma
Ranch Hand
Joined: Mar 25, 2008
Posts: 177
|
|
|
Yes I am using JCreator
|
 |
sachin verma
Ranch Hand
Joined: Mar 25, 2008
Posts: 177
|
|
output is still c is >> Process completed.
|
 |
sridhar row
Ranch Hand
Joined: Jan 16, 2008
Posts: 162
|
|
this is what you should be getting c is >> << after print
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
How a null char is displayed depends on the environment that's displaying it, but I would expect nothing (not even a space) to be displayed. Try the same code outside of JCreator, and I think you will find it works. (I recommend not using an IDE while preparing for the SCJP exam.)
|
 |
sachin verma
Ranch Hand
Joined: Mar 25, 2008
Posts: 177
|
|
originally posted by: marc waber Try the same code outside of JCreator, and I think you will find it works. (I recommend not using an IDE while preparing for the SCJP exam.)
Is is working fine on command line thankyou sir I will not use JCreator anymore
|
 |
sachin verma
Ranch Hand
Joined: Mar 25, 2008
Posts: 177
|
|
I have reported a Bug Thanks to marc weber, sridhar row and Stevi Deter
|
 |
Rakesh Chaudhary
Ranch Hand
Joined: Feb 19, 2008
Posts: 118
|
|
I tried the following on the code the output is 0 after print but if I write a string and then try to print value of c...the output is changed i.e... The Output is The Value of C: ............. Another Code with the Same output SomeBody Clear it Please....thanks.........
|
Acquire the unexpected.......
Preparing for SCJP 6
|
 |
sachin verma
Ranch Hand
Joined: Mar 25, 2008
Posts: 177
|
|
Don't use IDE to run these type of program. Run on command line and see the output. It is a bug in JCreator.I don't know about other IDE [ May 07, 2008: Message edited by: sachin verma ]
|
 |
Sanjit Kumar
Ranch Hand
Joined: Dec 04, 2006
Posts: 35
|
|
|
running perfectly fine in eclipse
|
 |
 |
|
|
subject: What happens when we print null character '\u0000' ?
|
|
|