Since Java 9, the purpose of using ‘Underscore’ has been changed. With any version before Java 9, It can be used to create a variable or as an identifier. But, NO MORE. In Java 9, ‘Underscore’ is a keyword. In this article, we are going to see how it’s usage changed through various versions. 

Underscore_Keyword_Java9_Featured_Image_Techndeck

Check out: Iterate / ofNullable operations in Java 9 Stream

Underscore is a KEYWORD now since Java 9...!!! Click To Tweet

Usage in Java 7

In Java 7, it could be used to used as an identifier or creating variable. Below code will compile & execute completely fine.

Output:

Usage in Java 8

In Java 8, Oracle developers added the warning message that will be displayed when we execute the below code. Below code will compile perfectly fine but will show the warning message on execution.

Output:

Usage in Java 9

In Java 9, ‘Underscore’ is a keyword therefore below code won’t compile and will throw the error message. 

Output:

Underscore is a KEYWORD now since Java 9...!!! Click To Tweet

Do you like this Post? – then check my other helpful posts:

Other Useful References: