By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
Originally posted by Dale DeMott:
What is the difference between primatives and literals. (if that is a fair question) and how are both treated?
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
My understanding is: literal concept includes primative concept.
Francis Siu
SCJP, MCDBA
By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
"I'm not back." - Bill Harding, Twister
By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
Neither primitives not literals are subsets or supersets of each other. Examples:
Primitive literals:
1, 'a', false
Literal but not primitive:
"", "a", "This is a string literal", Object.class, ArrayList.class, int.class, int[].class
(*) Primitive but not literal:
Any variable with primitive type, e.g. int
Francis Siu
SCJP, MCDBA
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Francis Siu
SCJP, MCDBA
Originally posted by Don Liu:
I just have a small question:
int n = 23 ;
here, 'int', 'n', '=', and '23' are all literals. aren't they?
Originally posted by Joel McNary:
They are all tokens in the languange, not literals. Only 23 is a literal. (for that matter, ';' is a token, as well)
"I'm not back." - Bill Harding, Twister
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Originally posted by Jim Yingst:
Urm... I'm not sure what definition of "token" Joel is using. According to the JLS though, literals are a subset of tokens. Everything in a valid .java file is (or is part of) either a comment, a token, or whitespace. (Note that spaces inside comments or String literals are not considered "whitespace" in this context.) Tokens can be identifiers, keywords, literals, separators, or operators - these five groups do not overlap.
if 'int' is not reserved by system, i guess i can use it like '23' or 'moose'? am i right?
int is a keyword, therefore it cannot be used as an identifier. It can't be a literal unless it's enclosed in double quotes (since it's clearly not a numeric, boolean, or class literal).
23 is not a keyword; it can't be an identifier since it doesn't start with a letter; it's a numeric (int) literal.
moose is not a keyword; it can be an identifier; it can't be a literal unless surrounded with double quotes.
To be fair, I don't think it really matters whether you know what the definition of a token is, unless you're writing a compiler. But understanding the differences between identifiers, keywords, literals, separators, and operators is useful.
"I'm not back." - Bill Harding, Twister
Tokens can be identifiers, keywords, literals, separators, or operators - these five groups do not overlap.
By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
Originally posted by Dale DeMott:
Are we going to need this much detail for any of the tests (tokens etc)
By failing to prepare, you are preparing to fail.
Benjamin Franklin (1706 - 1790)
Tokens can be identifiers, keywords, literals, separators, or operators - these five groups do not overlap.
What is the difference between primatives and literals. (if that is a fair question) and how are both treated?
Originally posted by Dale DeMott:
What is the difference between primatives and literals. (if that is a fair question) and how are both treated?
"I'm not back." - Bill Harding, Twister
By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
Looky! I'm being abducted by space aliens! Me and this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|