• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.)
 
Ranch Hand
Posts: 265
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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

c is >>
Process completed.
 
sridhar row
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is what you should be getting

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

Thanks to marc weber, sridhar row and Stevi Deter
 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
running perfectly fine in eclipse
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic