0% found this document useful (0 votes)
5 views

02 Variables Rules

The document outlines the rules for declaring variables in Java, emphasizing that variable names are case sensitive, can contain letters, numbers, underscores, or dollar signs, and must start with a letter, underscore, or dollar sign. It also states that variable names cannot be keywords or class names, have no length limit, and should follow camel casing conventions. Examples are provided for clarity on each rule.

Uploaded by

Avinash Nair
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

02 Variables Rules

The document outlines the rules for declaring variables in Java, emphasizing that variable names are case sensitive, can contain letters, numbers, underscores, or dollar signs, and must start with a letter, underscore, or dollar sign. It also states that variable names cannot be keywords or class names, have no length limit, and should follow camel casing conventions. Examples are provided for clarity on each rule.

Uploaded by

Avinash Nair
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Java

Rules for variables

1. Case Sensitive

Ex :

int amount;
int Amount;

• These both are di erent variables

2. Contains Alphabets , Numbers _ or $

Ex :

int room1;
int cabin51;
int room_number
oat total$amount
fl
ff
3. Starts with Alphabet _ or $

Ex :

byte x1;
byte _x;

4. Should not be keyword

Ex : These are the keywords which we cannot use while declaring a


variable
5. Should not be class name , if class is also in use

Ex :

• If string class is used then the variable cannot have the


same name as the class

string

int string

6. No limit on length on names

• You can declare a variable name as small as possible or


as large as possible

7. Follows camel casing

The rst letter of a word must be capital except for the rst
word

Ex :

byte rollNumber;
fi
fi

You might also like