package com.javaexample4u.identifiers;
public class JavaIdentifiers {
/* A name in a java Program is called an Identifier.Which can be used for representing classes,methods , variables and labels.
Rules:
1.Java Identifier is composed of a sequence of characters,
Which each character may be a letter from a to z or A to Z or digit from 0 to 9 or currency symbol ($) or connecting symbol (_). i.e only a-z,A-Z,0-9,$ and _
If we use other character we will get compile time error saying illegal character.
If we use other character we will get compile time error saying illegal character.
2.No identifier starts with the digit.
3.There is no length limit for java identifier ,but SUN highly recommended up to 15 characters .
4.Identifier in java are case sensitive.
5.we are not allowed to use reserved words as identifier.
6.All predefined java class and interface names ,you are allowed to use as identifiers.*/
public static void main(String[] args) {
String JAVA;//Correct
String java;//Correct
String Java225; //Correct
String java1$;//Correct
String _java; //Correct
String javal_examples;//Correct
String Runnable;//Correct and it is predefined interface name
String Seriliazable;//Correct and it is predefined interface name
String String ="Sekhar4j";//Correct and it is predefined java class String
System.out.println(String);//it prints Sekhar4j if you comment below identifiers
System.out.println(String);//it prints Sekhar4j if you comment below identifiers
String first-example;//Syntax error on token "first", = expected after this token
//example cannot be resolved to a variable
String 225java2; //Syntax error on token "225", delete this token
String second1#;// Syntax error on token "Invalid Character", delete this token
}
}
/*
* OputPut after compilation:
* Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Syntax error on token "first", = expected after this token
example cannot be resolved to a variable
Syntax error on token "225", delete this token
Syntax error on token "Invalid Character", delete this token
at com.javaexample4u.identifiers.JavaIdentifiers.main(JavaIdentifiers.java:24)
)*/
Comments
Post a Comment