
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
What is the use of underscore keyword in Java 9?
In earlier versions of Java, the underscore ("_") has used as an identifier or to create a variable name. Since Java 9, the underscore character is a reserved keyword and can't be used as an identifier or variable name. If we use a single underscore character as an identifier, the program fails to compile and throws a compile-time error because now it is a keyword and can't be used as a variable name in Java 9 or later versions.
Example
public class UnderscoreKeywordTest { public static void main(String args[]) { int _ = 50 System.out.println(_); } }
Output
UnderscoreKeywordTest.java:3: error: as of release 9, '_' is a keyword, and may not be used as an identifier int _ = 50; ^ UnderscoreKeywordTest.java:4: error: as of release 9, '_' is a keyword, and may not be used as an identifier System.out.println(_);
- Related Articles
- What is the use of "is" keyword in C#?
- What is the use of the Cleaner class in Java 9?
- What is the use of the toEpochSecond() method in Java 9?
- What is the use of the jdeprscan tool in Java 9?
- What is the use of ‘new’ keyword in C#?
- What is the use of this keyword in TypeScript?
- What is the use of the Optional.stream() method in Java 9?\n
- What is the use of the Tab key in JShell in Java 9?
- What is the use of the LIMIT keyword in MySQL query?
- What is the use of a multi-version compatible jar in Java 9?
- What are the 6 ways to use this keyword in Java?
- What is the native keyword in Java for?
- What is the use of the "requires" clause in a module-info file in Java 9?
- What is the use of the "export" clause in a module-info file in Java 9?
- What is the use of MySQL BINARY keyword while performing string comparison?

Advertisements