Search

Saturday, March 27, 2021

Java Keywords and identifiers



Java Keywords 


In Java language, Keywords have some special purpose. They are reserved to do some specific job and thats why they cannot be used as variable names. And if you use them as variable names, then Java will give you error.

Its better not to use them as variable names. Some of the examples of Java keywords are

int, float, char, if, for, while, else etc

One thing is important to know regarding Keywords in Java that they are in lower case.

Java keywords are also known as reserve words


Java Identifiers

In Java programming, when a programmer writes a program and gives some name to class, variable, or a method to identify it. That name is known as Java identifier.

They are used to refer variables, methods, class etc. And they can be combination of alphabets and numbers, but there are some rules to define them. They are as follow

To define a valid identifier in Java, it should start with some alphabet or it can be start with an underscore, but it should not start with a number

There should not be two underscores continuously

Java keywords or reserved words should not be used as java identifiers, else you will get error
They should not contains any spaces

Examples

someVariable, someVar, a, b, _a,_b etc

Following are invalid identifiers in Java

1a, a b, int etc

No comments:

Post a Comment