Advertisement

Keyword / Reserved words in Java Programming | this, final and super Keywords in Java

Keywords in Java

Keywords are predefined reserved words used in Java programming which have been described/told to the Java compiler already. We can't use a keyword as a variable name, class name or an identifier, as they are predefined in Java and using them will throw error.

For example:
int value1;

Here, "int" is a keyword. It indicates that the variable ‘value1’ is of integer type.

Below is the complete list of all keywords/reserved words in Java programming.

keywords in java

In java there are total 50 + 03 (literals) keywords/reserved words in Java.

Let us see in detail on some of the keywords/reserved words 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 after some condition got true.
  • continue: The ‘continue keyword’ in a loop ends the current iteration and forces the next iteration to take place bypassing any other statements inside.
  • switch: We use ‘switch’ keyword to perform a block of statements/code that is when you have to execute/run a different task for each choice.
  • int: Keyword/reserved word ‘int’ declares the data type integer. 
  • char: This keyword/reserved word ‘char’ declares a character variable.
  • if…else: In Java programming, the if and else are conditional statements used in decision making scenery.
  • goto: we use "goto" keyword when we have to transfer the program control to a particular label.
  • return: it is used to terminates the function and returns a value.
  • void: ‘Void’ means null or no value
  • this keyword: Java defines the this keyword. It is used inside any method to refer to the current object. That is, this is always a reference to the object on which the method was invoked/called. You can use this anywhere in  a reference to an object of the current class.
  • final keyword: If we make any variable final then we are not allowed to change its value later.It will be a constant.If we try to change value, then compiler will give us error.
  • super keyword: Super keyword/reserved word in Java is simply a reference variable. It refer to the immediate parent class object.

Identifiers in Java

Names given to constants, functions, variables and user-define data are known as Identifiers. It is assigned by the user.

There are a set of rules to frame/make an Identifier.

  • An identifier must 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 in the program.
  • Keywords/Reserved words cannot be an Identifier.
  • No special character is allowed in identifier.
  • The first character of an identifier must be an alphabet or underscore only.
  • Identifiers are case-sensitive.
  • No white spaces are allowed in a identifier name.

Post a Comment

0 Comments