Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What happens when we print null character '\u0000' ?

 
sachin verma
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you saying that your program exits before outputting "after print"? Does it output "c is"?

(It works fine for me, using Mac Terminal.)
 
Stevi Deter
Ranch Hand
Posts: 265
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sachin verma
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


try this and let us know what you think.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm... Are you using an IDE?
 
sachin verma
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I am using JCreator
 
sachin verma
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
output is still

c is >>
Process completed.
 
sridhar row
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is what you should be getting

c is >> <<
after print
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have reported a Bug

Thanks to marc weber, sridhar row and Stevi Deter
 
Rakesh Chaudhary
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.........
 
sachin verma
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
running perfectly fine in eclipse
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic