Identifiers in JavaIdentifiers in Java are symbolic names used for identification. They can be a class name, variable name, method name, package name, constant name, and more. However, In Java, There are some reserved words that can not be used as an identifier. For every identifier there are some conventions that should be used before declaring them. Let's understand it with a simple Java program: From the above example, we have the following Java identifiers:
let's understand the rules for Java identifier: Rules for Identifiers in JavaThere are some rules and conventions for declaring the identifiers in Java. If the identifiers are not properly declared, we may get a compile-time error. Following are some rules and conventions for declaring identifiers:
Java Reserved KeywordsJava reserved keywords are predefined words, which are reserved for any functionality or meaning. We can not use these keywords as our identifier names, such as class name or method name. These keywords are used by the syntax of Java for some functionality. If we use a reserved word as our variable name, it will throw an error. In Java, every reserved word has a unique meaning and functionality. Consider the below syntax: in the above statement, double is a reserved word while marks is a valid identifier. Below is the list of reserved keywords in Java:
Although the const and goto are not part of the Java language; But, they are also considered keywords. Example of Valid and Invalid IdentifiersValid identifiers: Following are some examples of valid identifiers in Java:
Invalid identifiers: Below are some examples of invalid identifiers:
We should follow some naming convention while declaring an identifier. However, these conventions are not forced to follow by the Java programming language. That's why it is called conventions, not rules. But it is good to follow them. These are some industry standards and recommended by Java communities such as Oracle and Netscape. If we do not follow these conventions, it may generate confusion or erroneous code. See more about Java Naming Conventions. Next TopicInvocationTargetException |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India