I am new to java and was reading a book and came across these lines:
"The literals true
,false
and 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..?
The main difference between String Literal and String Object is that String Literal is a String created using double quotes while String Object is a String created using the new() operator.
A keyword contains only alphabetical characters. An identifier can consist of alphabetical characters, digits and underscores. They help to identify a specific property that exists within a computer language.
Keywords are predefined, reserved words used in Java programming that have special meanings to the compiler. For example: int score; Here, int is a keyword. It indicates that the variable score is of integer type (32-bit signed two's complement integer).
Keywords are words that are used as part of code structure, like for
or while
. They change the way a compiler handles a block of code, e.g. a for
tells the compiler to execute the code within the specified scope repeatedly, until the given exit condition is reached. The class
keyword 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
, false
and null
are 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 called true
or for
. They form parts of expressions, but don't change the way a compiler handles code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With