Skip to main content

Java variable or Java identifier

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.
       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
                    
              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

Popular posts from this blog

Yahoo! Calendar "Add Event" Seed URL Parameters

I can't seem to find any official documentation on this, so here are my notes. Some information gathered from  http://richmarr.wordpress.com/tag/calendar/ Other information gathered through trial and error, and close examination of the "Add Event" form on Yahoo!'s site. Yahoo! Calendar URL Parameters Parameter Required Example Value Notes v Required 60 Must be  60 . Possibly a version number? TITLE Required Event title Line feeds will appear in the confirmation screen, but will not be saved. May not contain HTML. ST Required 20090514T180000Z Event start time in UTC. Will be converted to the user's time zone. 20090514T180000 Event start time in user's local time 20090514 Event start time for an all day event. DUR value is ignored if this form is used. DUR 0200 Duration of the event. Format is HHMM, zero-padded. MM may range up to 99, and is converted into hours appropriately. HH values over 24 hours appear to be modulated by 24. Durations t...

HTML5 30-Day Course Outline

  🗓️ Week 1: HTML5 Fundamentals and Structure 🎯 Goal: Understand the structure of HTML5 and core elements. Day 1: Introduction to HTML5 ✅ Concepts What is HTML5 and its role in web development <!DOCTYPE html> declaration Basic HTML structure ( <html> , <head> , <body> ) Character encoding ( UTF-8 ) ✅ Example Code html <!DOCTYPE html > < html lang = "en" > < head > < meta charset = "UTF-8" > < title >My First HTML5 Page </ title > </ head > < body > < h1 >Hello World! </ h1 > </ body > </ html > ✅ Task: 👉 Create a basic HTML page with a title and h1 element. Day 2: HTML Elements and Semantics ✅ Concepts Block vs Inline Elements <div> , <span> , <article> , <section> , <aside> , <main> , <footer> Importance of semantic HTML for SEO ✅ Example Code html < article > < header > ...

Java KeyWords

Java Keywords Some identifiers are reserved in Java which has separate functionality and meaning such type of reserved identifiers are called reserved words. Java has 54 reserved keywords. We can divide them into the following categories. Primitive types and void : 9 keywords boolean : creates a boolean variable. The only possible values are true and false and the default value is false. byte : creates a byte variable. A byte takes 8-bits and ranges from -128 to 127. char : used to create a character variable. It takes 2-bytes and it’s unsigned. The value ranges from 0 to 65,536. short : create a short variable of 2-bytes. The value ranges from -32,768 to 32,767. int : create an integer variable, takes 4-bytes and the range is from -2,147,483,648 to 2,147,483,647 long : creates a long variable, takes 8-bytes and the range is from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. float : creates a signed floating point variable using 4-bytes. double ...