File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt on char default value... 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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt on char default value..." Watch "doubt on char default value..." New topic
Author

doubt on char default value...

Konda Golamaru
Ranch Hand

Joined: Dec 12, 2005
Posts: 36
Hi,

I am little confused how the "ch" value is being calculated at #2,#3.
When I print the "ch" value at #1, it prints nothing.

My doubt is when i print ba[ch] at#3 it should take as ba[null].Not
sure how it is taking the index value for ch is 0 and printing false.

I know that the default value for char is \u0000 (null character).

Any inputs?? Thanks..

import static java.lang.System.*;
public class TestClass12
{
static boolean b;
static int[] ia = new int[1];
static char ch;
static boolean[] ba = new boolean[1];

public static void main(String args[]) throws Exception
{
out.println(" ch :"+ch);//1
boolean x = false;
if( b )
{
out.println("1");
x = ( ch == ia[ch]);
}
else x = ( ba[ch] = b );//2
System.out.println(x+" "+ba[ch]);//3
}
}
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Konda Golamaru:
...My doubt is when i print ba[ch] at#3 it should take as ba[null]. Not sure how it is taking the index value for ch is 0 ...

A Java char is really a numeric value that corresponds to a character symbol (see ASCII table). The "null char" has a numeric value of zero. A Java int can obviously have a zero value, but it does not have a "null" value.

An array index is an int. So in the expression ba[ch], ch is converted to type int with a numeric value of zero.
[ June 09, 2007: Message edited by: marc weber ]

"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
Konda Golamaru
Ranch Hand

Joined: Dec 12, 2005
Posts: 36
Hi Marc,

Thank You. I think I am clear now.

--Konda Golamaru.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt on char default value...