Java is a case sensitive language and to build Java programs you need to use a lot of Built-in API classes and methods. And beginners find it really hard to memorize the method names and Class names exactly without changing the case.
But actually you need not remember the case. It would be overkill to memorize it. But if you follow the Java Naming conventions, then you need not memorize the case of the methods and classes that you will be using. 99% of the classes in the JAVA API follow this naming convention. Only 1% of the names break this rule and that is also due to programmers forgetting to name it properly (its true!). So here we goes…
1. Classes:
Class names always begin with a capital letter (eg. java.util.Scanner). And if there are mutiple words in the class name then each word must also begin with a capital letter (eg. java.util.GregorianCalendar). Also package names always start with lowercase characters (util, lang, io, etc). And if there are multiple words in the package name, then you need to use uppercase for all words except for the starting word. This naming method is popularly called as UpperCamelCase which is a type of CamelCase! Interfaces also use same convention.
1
class MyClass {
2
}
2. Objects/Variables:
Java Naming convention specifies that instances and other variables must start with lowercase and if there are multiple words in the name, then you need to use Uppercase for starting letters for the words except for the starting word. This is called as lowerCamelCase.
1
String myName;
2
MyClass myObject;
3
Scanner scannerObject = new Scanner(System.in);
3. Methods:
Methods in Java also follow the same lowerCamelCase convention like Objects and variables.
1
void myMethod() {
2
}
3
String myName = scannerObject.nextLine();
4. Constant Variables:
In Java constant variables are declared using “static final” modifiers. And such variables must contain only UpperCase charachters and multiple words must be seperated using ‘_’.
1
static final char END_OF_FILE = 'e';
2
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Well thats it. Again, all these conventions were created just to improve readability of code. So its your choice to use them or leave them. But if you do use them, your code will look professional. Java Compiler does expect you to use these conventions.
But actually you need not remember the case. It would be overkill to memorize it. But if you follow the Java Naming conventions, then you need not memorize the case of the methods and classes that you will be using. 99% of the classes in the JAVA API follow this naming convention. Only 1% of the names break this rule and that is also due to programmers forgetting to name it properly (its true!). So here we goes…
1. Classes:
Class names always begin with a capital letter (eg. java.util.Scanner). And if there are mutiple words in the class name then each word must also begin with a capital letter (eg. java.util.GregorianCalendar). Also package names always start with lowercase characters (util, lang, io, etc). And if there are multiple words in the package name, then you need to use uppercase for all words except for the starting word. This naming method is popularly called as UpperCamelCase which is a type of CamelCase! Interfaces also use same convention.
1
class MyClass {
2
}
2. Objects/Variables:
Java Naming convention specifies that instances and other variables must start with lowercase and if there are multiple words in the name, then you need to use Uppercase for starting letters for the words except for the starting word. This is called as lowerCamelCase.
1
String myName;
2
MyClass myObject;
3
Scanner scannerObject = new Scanner(System.in);
3. Methods:
Methods in Java also follow the same lowerCamelCase convention like Objects and variables.
1
void myMethod() {
2
}
3
String myName = scannerObject.nextLine();
4. Constant Variables:
In Java constant variables are declared using “static final” modifiers. And such variables must contain only UpperCase charachters and multiple words must be seperated using ‘_’.
1
static final char END_OF_FILE = 'e';
2
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Well thats it. Again, all these conventions were created just to improve readability of code. So its your choice to use them or leave them. But if you do use them, your code will look professional. Java Compiler does expect you to use these conventions.
No comments:
Post a Comment