• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what does "true" belong to?

 
William Yan
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,
i am new here. i saw "true" and "false" do not belong to the keywords of JAVA while i cannot use them for variable names. So i wonder what do the "true" and "false" belong to? Are they just used for boolean-values and cannot be used anywhere else? And is there a naming rule says you cannot use them for names? Thanks
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
true and false are boolean literals.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by William Yan:
...is there a naming rule says you cannot use them for names? Thanks

Welcome to JavaRanch!

"An identifier cannot have the same spelling (Unicode character sequence) as a keyword (�3.9), boolean literal (�3.10.3), or the null literal (�3.10.7)." Ref: JLS - 3.8 Identifiers.
 
William Yan
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Marc.
Definitely clear.
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

true, false and null are 3 reserved literals in Java.

Regards,
Jothi Shankar Kumar. S
 
Rajesh Kadle
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a question on boolean type.

I read that 'boolean' doesnt have a size (like int-4, long-8 etc). So how does the compiler store these values in the class file or on the stack/heap.

Can someone throw light on this.

Thanks in advance,
-Raj
 
William Yan
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As "Head First Java" says, variables are stored in heap/stack according to whether it is used as instance variable(in class) or local variable(in method). But i dunno the size, and i think that does not matter much.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic