Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

char simple initialisation problem !!

 
Neeraj Vasudeva
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

hi abhinav,

i am a new bie, i wrote this very simple program, when i compile this program on Dos then it is displaying the value of f and q as "a" why is this so...acc. to me it should have been displayed as NULL, when the same program i run in Kawa editor it is not showing anything ..why is this so..please compile this program in Dos prompt..and tell me why char f and q are being initialised to 'a'

class tryProgram
{
static char f;
static char q;
static short s;

public static void main(String args[])
{
System.out.println("short s is "+s);
System.out.println("char f is "+f);
System.out.println("char q is "+q);
System.out.println();

}
}

bye

Neeraj Vasudeva
------------------
Come to my site...http://www.sunjavacertification.com & explore the things..i am a new bie in java.
 
Pat Barrett
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Neeraj,
I can't explain what is happening on your DOS compiler. When I compiled your program f + q were not initialized to 'a'. It worked as expected for me.
Pat B.
 
Neeraj Vasudeva
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, After reading your view , i ran the same program on diff. machine in my office & the same out put i am getting that i value is displayed as 'a', why is the happening, & what is the meaning of '\u0000'
bye
Neeraj Vasudeva http://www.sunjavacertification.com
Originally posted by Pat Barrett:
Hello Neeraj,
I can't explain what is happening on your DOS compiler. When I compiled your program f + q were not initialized to 'a'. It worked as expected for me.
Pat B.


------------------
Come to my site...http://www.sunjavacertification.com & explore the things..i am a new bie in java.
 
Pat Barrett
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Class variables, if not explicitly initialized in your code, are given default values. In the case of a char, this value is \u0000 which I believe is the unicode value of null. I can't explain why you'd see the letter 'a', which has a unicode value of \u0061.

Hope this helps...
Pat B.
 
Neeraj Vasudeva
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is that i ran the same program on diff machine in office then also it's giving me as 'a' as output.........please tell me that unicode means Ascii value ?
------------------
Come to my site...http://www.sunjavacertification.com & explore the things..i am a new bie in java.
 
Jasbir Hara
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I have a look at your class file.
The add is jasbir123@glide.net.in.

As expected I did not encounter any problems while executing that code
 
Neeraj Vasudeva
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have sended the file at your e-mail id, both the files r included in an attachment in the e-mail.
bye
Neeraj Vasudeva

------------------
Come to my site...http://www.sunjavacertification.com & explore the things..i am a new bie in java.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic