wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what does Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what does "true" belong to?" Watch "what does "true" belong to?" New topic
Author

what does "true" belong to?

William Yan
Ranch Hand

Joined: Sep 26, 2006
Posts: 69
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


Java is better and better, yet bitter and bitter.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
true and false are boolean literals.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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.


"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
William Yan
Ranch Hand

Joined: Sep 26, 2006
Posts: 69
Thank you, Marc.
Definitely clear.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9399
    
    2

Hi,

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

Regards,
Jothi Shankar Kumar. S


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Rajesh Kadle
Greenhorn

Joined: Sep 06, 2004
Posts: 26
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

Joined: Sep 26, 2006
Posts: 69
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.
 
 
subject: what does "true" belong to?