Java – Keywords & Identifiers
Keywords/Reserved words are predefined, reserved words used in Java programming which have been described to the Java compiler already. We cannot use a keyword as a variable name or an identifier, as they are predefined in Java and using them will throw error.
Here, ‘int’ is a keyword. It indicates that the variable ‘value1’ (which is a identifier) is of integer type.
Here’s the complete list of all keywords in Java programming.
In total there are 50 + 03 (literals) keywords/reserved in Java.
Let us see in detail on some of the keywords and their functions in Java.
- break: It is used inside a loop to bring the program control out of the loop or to terminate the loop immediately.
- continue: The ‘continue statement’ in a loop ends the current iteration and forces the next iteration to take place bypassing any other statements inside.
- switch: The ‘switch’ keyword is used to perform a block of statements that is when you have to execute a different task for each choice.
- int: Keyword ‘int’ declares the data type integer. char: This keyword ‘char’ declares a character variable.
- if…else: In Java programming, the if and else are conditional statements used in decision making.
- goto: It is used when you have to transfer the program control to a particular label.
- return: The keyword ‘return’ terminates the function and returns a value.
- void: ‘Void’ means no value or null.
The names given to constants, variables, functions and user-define data are known as Identifiers. It is assigned by the user in the program.
There are a set of rules to frame an Identifier.
- An identifier can be of alphanumeric values only i.e letters and digits. (A-Z, a-z, 0-9)
- Underscore _ can be used in an identifier.
- Identifier names must be unique.
- Keywords/Reserved words cannot serve as an Identifier.
- No special character is allowed.
- The first character of an identifier must be an alphabet or underscore.
- Identifiers are case-sensitive.
- sNo white spaces are allowed.
Examples for identifiers: