NAMING CONVENTION
The naming convention or rules in Java is classified
into two categories: Pascal Naming Convention (PNC) and Camel Naming Convention
(CNC). Generally, PNC method is used for classes whereas, CNC is applied for
methods and variables.
In PNC method, suppose if you want to
name your class with many words like ‘xoxo waves’, then you have to name the
first letter of each word in capital without leaving space.
Eg) public class XoxoWaves
In CNC method, when more words are used
in naming, the 1st letter should be small whereas the other 1st
letter of each word should be typed in capitals.
Eg) int
numberEleven=22;
This is the universal naming format
applied all over the world, so that people from anywhere can understand the
Java language.
Important
rules to remember
- · Semi-colon should be used at the end of each single statement
- ·
While
defining a method or class, semi-colon is not used but curly braces are used instead
- ·
The
statement after ‘//’ is not considered during compiler execution
- · For
single line comments, ‘//’is used and for multi-line comments it becomes
difficult to type ‘//’ at each line. Hence ‘/*’ is used at the starting line of
the comment and ‘*/’ is used at the end
- ·
Comments
are useful to recognize the code operation in future and it can also help others
to easily understand the code
- · Variable
names are case- sensitive in Java and hence must be carefully used to avoid
error conditions
- ·
Variable
names can have digits, letters and two signs ‘_’ (underscore) and ‘$’ symbols
are allowed
- · Variable
names can start with either an alphabet or sign but not with a numeral
- · Variable
name should not be a keyword used in Java like int, byte, long,etc…
Defining a
constant variable
Generally, the variables defined in Java can be subjected to several operations and can be varied. But a constant variable is one whose value is fixed throughout the entire programing. Changes made to this constant variable leads to error.
class
reference{
public static void main(String
args[]){
byte no_1=22;
no_1=33;
System.out.println(no_1);
}
}
In this code, the no_1 is initially assigned 22 but later it’s changed to 33. Hence while printing no_1, 33 is printed. Fixed constants should be declared with a key word ‘final’.
final
byte no_2=22;
no_2=33;
System.out.println(no_2);
Here, the Java compilation process results in the following error since the no_2 variable is a constant. Hence, it’s clear that modifying a constant result in error.
Output error



0 Comments