This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes defaul value for char????????????? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "defaul value for char?????????????" Watch "defaul value for char?????????????" New topic
Author

defaul value for char?????????????

amit vaid
Greenhorn

Joined: Oct 10, 2000
Posts: 7
hi!!
i'm a beginner on java. i've read some books but have not come across default value for a char.
if i declare a char without initialising the system exits at the point the value is get? what is the reason?
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Amit,
The default value for a char is <code>\u0000</code>, a Unicode 0.
Only class and instance variables are automatically initialized with their default values. If you are using an uninitialized local variable you will run into a compile error.
Hope that helps.
------------------
Jane


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
amit vaid
Greenhorn

Joined: Oct 10, 2000
Posts: 7
Thanks Jane
but why does the system exits at the point u try to get an unintialised char any body with answer's to that
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Amit,
Can you post a copy of the code?
------------------
Jane
Zeba Mojez
Greenhorn

Joined: Oct 25, 2000
Posts: 10
Originally posted by Jane Griscti:
Amit,
Can you post a copy of the code?

Here is the code which prints nothing (blank) for the default value of the char
class Xyz
{
private int x;
public void getX()
{
x = 10;
System.out.println(x);
}
}
public class Separation extends Xyz
{
/*private static int i;
private static short sh;
private static long l;
private static byte b;
private static boolean bl;
private static double d;
private static float f;
private static Separation s1;
*/
private char c;
private int i;
private short sh;
private long l;
private byte b;
private boolean bl;
private double d;
private float f;
private Separation s1;
public static void main ( String [] args )
{
Separation s = new Separation();
/*System.out.println ("Hello World");
System.out.println ("int i = "+i);
System.out.println ("short sh = "+sh);
System.out.println ("long l = "+l);
System.out.println ("byte b = "+b);
System.out.println ("boolean bl = "+bl);
System.out.println ("float f = "+f);
System.out.println ("double d = "+d);
ystem.out.println ("Object s = "+s1);
*/
int z=0;
System.out.println ("Object z = "+z);
s.getX();
s.abc();
s.getDefault();
}
public void getDefault()
{
System.out.println ("Hello World");
System.out.println ("int i = "+i);
System.out.println ("short sh = "+sh);
System.out.println ("long l = "+l);
System.out.println ("byte b = "+b);
System.out.println ("boolean bl = "+bl);
System.out.println ("float f = "+f);
System.out.println ("double d = "+d);
System.out.println ("Object s = "+s1);
System.out.println ("Char = "+c);
}
public void abc()
{
getX();
}
}

Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
It didn't exit because the char was uninitialized. It ended because it was over. The uninitialized char c printed as a blank and that was the last command.
Try adding this:
System.out.println ("Char = "+c);
System.out.println ("Unicode = "+"\u0000");

"JavaRanch, where the deer and the Certified play" - David O'Meara
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: defaul value for char?????????????