Back to Java Course
Java Course
- Identifiers can include a-z (or) A-Z (or) 0 to 9 (or) _ (or) $
- Identifiers must start with an alphabet (or) _ (or) $ for example, age, $salary, _value, __1_value.
- Identifiers cannot have other symbols, keywords, start with number for example, 123abc, -salary.
- Most importantly, identifiers are case sensitive.
Let's see some example,
package com.praveen.identifiers; public class IdentifierDemo { public static void main(String[] args) { int abc = 992; int 1bc = 22; // compiler error as identifier cannot start with number byte Abc = 10; float $xyz = 10.2f; double _xyz = 10.21d; int #xyz = 989; // compiler error as identifier must start with an alphabet (or) _ (or) $ int this = 212; // compiler error as identifier cannot have keywords } }
As a Developer, we need to follow the below coding conventions:
-
Class Names:
- Use
PascalCase(capitalize the first letter of each word) for class names. - Example:
UserAccount,OrderDetails.
- Use
-
Variable Names:
- Stick to
camelCase(start with a lowercase letter and capitalize subsequent words) for variables. - Example:
userId,orderAmount,isActive.
- Stick to
-
Constants:
- Use
ALL_CAPSwith underscores to separate words for constants. - Example:
MAX_RETRIES,API_TIMEOUT,DEFAULT_VALUE.
- Use