Are true and false keywords in java?


Keywords − Keywords in Java convey a special meaning to the compiler therefore, these cannot be used as identifiers. Java provides a set of 50 keywords.

abstractcontinuefornewswitch
assertdefaultgotopackagesynchronized
booleandoifprivatethis
breakdoubleimplementsprotectedthrow
byteelseimportpublicthrows
caseenuminstanceofreturntransient
catchextendsintshorttry
charfinalinterfacestaticvoid
classfinallylongstrictfpvolatile
constfloatnativesuperwhile

Reserved words − Among the list of key words list mentioned above the key words goto and const are currently not in use. They are reserved words (for the future use).

The true false and null − True, false and null represents certain values in Java, they are used as literals. They are not considered as keywords.

Still, you cannot use them as identifiers in Java if you try to do so, a compile time error will be generated.

Example

public class Example {
   public static void main(String args[]) {
      int true = 20;
      int false = 30;
      float null = 23.6f;
   }
}

Output

Example.java:3: error: not a statement
   int true = 20;
   ^
Example.java:3: error: ';' expected
   int true = 20;
       ^
Example.java:4: error: not a statement
   int false = 30;
   ^
Example.java:4: error: ';' expected
   int false = 30;
       ^
Example.java:5: error: not a statement
   float null = 23.6f;
   ^
Example.java:5: error: ';' expected
   float null = 23.6f;
         ^
6 errors

Updated on: 30-Jul-2019

819 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements