Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Beginning Java and the fly likes Character (primitive type) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Character (primitive type)" Watch "Character (primitive type)" New topic

Character (primitive type)

Varun Goenka
Ranch Hand

Joined: Mar 09, 2009
Posts: 37
Does a char variable have some default value? Like garbage value?

From The Demon,
with love.
Henry Wong

Joined: Sep 28, 2004
Posts: 18498

Varun Goenka wrote:Does a char variable have some default value? Like garbage value?

The default value for a char is a nul character -- which has an ascii value of zero.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Rob Spoor

Joined: Oct 27, 2005
Posts: 19649

It's '\0', or simply 0 (as an integer literal).

How To Ask Questions How To Answer Questions
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 37884
That is the default value for a field; all fields have default values of 0, which is interpreted as the null character for a char, false for a boolean, and null for all reference types.

Local variables and parameters do not have default values at all.
It is sorta covered in the JavaRanch Style Guide.
subject: Character (primitive type)
Similar Threads
How To Put Some Text In the Text Field?
What the hell is a serialized object?
Java uses Pass By Value or Reference
logic:iterate inside logic:equal
WA #1.....word association