3. Basic Language Elements

3.1. Identifiers

An identifier is name in a program. Identifiers can be used to denote classes, methods, variables, and labels. It can consist of letter or digit.

Rules:

			package javatutorial;

			/**
			 * Example of identifiers in Java
			 * 
			 * @author f5java.com
			 */
			public class IdentifierExample {

				public static void main(String[] args) {

					String name;
					String Name; 	// 1. Name and name are different identifiers
					String _Name; 	// 2. Valid identifier
					String $Name;	// 3. Valid identifier
					String Name123; // 4. Valid identifier

					// String 123Name; // 5. Not Allowed - compiler wont compile code,
					// Invalid identifier
					
					// Lets print the valid and invalid identifiers
					System.out.println("Following are valid identifiers");
					System.out.println("name");
					System.out.println("Name");
					System.out.println("_Name");
					System.out.println("$Name");
					System.out.println("Name123");

					System.out.println("Following are invalid identifiers");
					System.out.println("123Name");
				}

			}