Using _ (underscore) as Variable Name in Java Last Updated : 21 Nov, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report As we do know variables in java or rather in any language is introduced to write a code where it is suggested to give meaningful names to the variables as per their usage in code and especially in object-oriented languages are supposed to be used locally wherever it is possible instead of just using them globally. It is a very essential property of variables that is been checked is enterprising domain as it helps us achieve cleaner and minimalistic code. Case 1: Using underscore as a variable name in Java 8 Although it is supported in Java 8, a mandatory warning is issued if you use _ as an identifier, telling you that "use of '_' as an identifier might not be supported in releases after Java SE 8". Example: Java // Java Program to Illustrate Usage of Underscore // As a Variable Name // Main class class GFG { // Main driver method public static void main(String args[]) { // Declaring underscore as variable // in java 8 only int _ = 10; // Printing the value stored in it System.out.println(_); } } Output: 10 With the advancement in the version of Java, Java 9 has made changes in features of the java language, and eliminating underscore from the legal name is a major change made by Oracle. The use of the variable name _ in any context is never encouraged. The latest versions of Java reserve this name as a keyword and/or give it special semantics. If you use the underscore character ("_") as an identifier, your source code can no longer be compiled. We will get a compile-time error. Case 2: Using underscore as a variable name in Java 9 Example: Java // Java program to illustrate Usage of Underscore // As Variable Name in Java9 // Main class class GFG { // Main driver method public static void main(String args[]) { // Declaring underscore as variable // in java9 and onwards int _ = 10; // Printing the value as stored in underscore System.out.println(_); } } Output: In Java 9, underscore as variable name won't work altogether. Below source code can no longer be compiled. Below are the following conclusions been drawn from the above examples as illustrated: Using underscore in a variable like first_name is still valid. But using _ alone as a variable name is no more valid.Even if you are using earlier versions of Java, using only underscore as a variable name is just a plain bad style of programming and must be avoided. Comment More infoAdvertise with us Next Article Scope of Variables in Java A Abhishek Verma 16 Improve Article Tags : Misc Java Practice Tags : JavaMisc Similar Reads Using predefined class name as Class or Variable name in Java In Java, you can use any valid identifier as a class or variable name. However, it is not recommended to use a predefined class name as a class or variable name in Java. The reason is that when you use a predefined class name as a class or variable name, you can potentially create confusion and make 5 min read Using underscore in Numeric Literals in Java When Java was introduced, use of underscore in numeric literals was not allowed but from java version 1.7 onwards we can use '_' underscore symbols between digits of numeric literals. You can place underscores only between digits. Do remember there are certain places where we can not place underscor 3 min read Using underscore in Numeric Literals in Java A new feature was introduced by JDK 7 which allows writing numeric literals using the underscore character. Basically, they are broken to enhance readability. This feature enables us to separate groups of digits in numeric literals, which improves the readability of code. For instance, if our code c 1 min read Unnamed Patterns and Variables in Java Java programming language offers multiple features that allow developers to write rich and concise code. Among these features, there are unnamed patterns and variables which enables developers to work with data in a more flexible and elegant way. In this article, we will study about unnamed patterns 4 min read Scope of Variables in Java The scope of variables is the part of the program where the variable is accessible. Like C/C++, in Java, all identifiers are lexically (or statically) scoped, i.e., scope of a variable can be determined at compile time and independent of the function call stack. In this article, we will learn about 7 min read Different name reusing techniques in Java Overriding An instance method overrides all accessible instance methods with the same signature in superclasses, enabling dynamic dispatch; in other words, the VM chooses which overriding to invoke based on an instanceâs run-time type. Overriding is fundamental to object-oriented programming and is 3 min read Like