File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes char simple initialisation problem !! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "char simple initialisation problem !!" Watch "char simple initialisation problem !!" New topic
Author

char simple initialisation problem !!

Neeraj Vasudeva
Greenhorn

Joined: Feb 07, 2001
Posts: 12

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.


Come to my site...http://www.sunjavacertification.com & explore the things..i am a new bie in java.
Pat Barrett
Ranch Hand

Joined: Jan 03, 2001
Posts: 63
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

Joined: Feb 07, 2001
Posts: 12
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

Joined: Jan 03, 2001
Posts: 63
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

Joined: Feb 07, 2001
Posts: 12
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

Joined: Jan 06, 2001
Posts: 2
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

Joined: Feb 07, 2001
Posts: 12
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: char simple initialisation problem !!