I am new to java and was reading a book and came across these lines:
“The literals true,falseand null are lowercase,not uppercase as in C++ language.Strictly speaking,these are not keywords but literals.”
why these are literals, and what requirements are needed for some keywords to be called literal..?
Keywords are words that are used as part of code structure, like
fororwhile. They change the way a compiler handles a block of code, e.g. afortells the compiler to execute the code within the specified scope repeatedly, until the given exit condition is reached. Theclasskeyword tells the compiler to treat everything within the specified scope to be part of a particular class. Keyword names are restricted, so you can’t use them as variable names.Literals like
true,falseandnullare values that can be assigned, but their names are restricted in the same way that keywords are, i.e. you can’t have a variable calledtrueorfor. They form parts of expressions, but don’t change the way a compiler handles code.