Java coding convention
3 posters
Page 1 of 1
Java coding convention
Today I'm going to share some Java coding convention. In this text I'll describe few of them and it will be continued. First let get some importance of Java coding convention.
Why Java coding convention?
There are numbers of reason behind coding convention and its now well known. You know in a software development, 80% of cost is maintenance and hardly any software is maintained by its original authors. So code should be readable to others. Code convention improves the readability, and therefore, maintainability of code and allows engineers to understand code more quickly. It enables code review easier. It saves development time and once it is the guidelines of learners. Java coding convention can be put into different groups. Today I'll discuss about naming convention:
Naming convention:
General convention:
Meaningful names:
all name used in code should be meaningful, methods name should be like what they do, for say calculate() which perform some calculation. And naming should be in English spelling. Naming should be avoid abbreviations. Should use meaningful name while naming class name, variable name, constant name.
Like -
class name → AddressDetails
method name → addAddressDetails
variable name → username
constant name → DEAFULT_VALUE
Familiar Names : existing terminology should be used like customer, clients etc
Case : Java is case sensitive. So username and Username is different. But it should no use same name that differs only in case.
Package name: package name must be lower case. Like → iit.bit.rokon.com
Class name: class name must be start with upper case. Class name should be noun.
Class name can contain multiple words. This case they are linked like → AddressDetails. Every word should start with upper case letter.
Interface name: interface name should be like class name. And should use none or
adjective while naming interface.
Method name: first letter must be lower case and capitalize first letter of each subsequent word that appears in a method name. And method name should be verb. In the case of accessor method, we should use javaBean convention. Like getter and setters.
Example -
Variable name: Variable name should be noun and should be start with lowercase and
capitalize first letter of each subsequent word that appears.
Constant Name: Constant name should use uppercase letters for each word and separate each pair of words with and underscore. Example -
References: http://www.oracle.com/technetwork/java/codeconvtoc-136057.html
It will be continued, Stay tuned.....
Why Java coding convention?
There are numbers of reason behind coding convention and its now well known. You know in a software development, 80% of cost is maintenance and hardly any software is maintained by its original authors. So code should be readable to others. Code convention improves the readability, and therefore, maintainability of code and allows engineers to understand code more quickly. It enables code review easier. It saves development time and once it is the guidelines of learners. Java coding convention can be put into different groups. Today I'll discuss about naming convention:
Naming convention:
General convention:
Meaningful names:
all name used in code should be meaningful, methods name should be like what they do, for say calculate() which perform some calculation. And naming should be in English spelling. Naming should be avoid abbreviations. Should use meaningful name while naming class name, variable name, constant name.
Like -
class name → AddressDetails
method name → addAddressDetails
variable name → username
constant name → DEAFULT_VALUE
Familiar Names : existing terminology should be used like customer, clients etc
Case : Java is case sensitive. So username and Username is different. But it should no use same name that differs only in case.
Package name: package name must be lower case. Like → iit.bit.rokon.com
Class name: class name must be start with upper case. Class name should be noun.
Class name can contain multiple words. This case they are linked like → AddressDetails. Every word should start with upper case letter.
Interface name: interface name should be like class name. And should use none or
adjective while naming interface.
Method name: first letter must be lower case and capitalize first letter of each subsequent word that appears in a method name. And method name should be verb. In the case of accessor method, we should use javaBean convention. Like getter and setters.
Example -
- Code:
class User{
private String username;
public void setUsername(String username){
this.username = username;
}
public String getUsername(){
return username;
}
}
Variable name: Variable name should be noun and should be start with lowercase and
capitalize first letter of each subsequent word that appears.
Constant Name: Constant name should use uppercase letters for each word and separate each pair of words with and underscore. Example -
- Code:
public static final int DEAFULT_VALUE = 1;
References: http://www.oracle.com/technetwork/java/codeconvtoc-136057.html
It will be continued, Stay tuned.....
Re: Java coding convention
hmm.....nicely done , but i think if u practice more, then the conventions
will automatically appear to yr code....
though, rep++...for making us aware of it, who are so lazy in coding...
will automatically appear to yr code....
though, rep++...for making us aware of it, who are so lazy in coding...
BIT0125-Tauhid- Club Moderator
- Posts : 113
Points : 176
Re: Java coding convention
for the record,
when you are saying
MyClassName, it is in short called Pascal notation.
when you are saying myFunction, it is in short called Camel Notation
when you are saying
MyClassName, it is in short called Pascal notation.
when you are saying myFunction, it is in short called Camel Notation
Re: Java coding convention
BIT0122-Amit wrote:for the record,
when you are saying
MyClassName, it is in short called Pascal notation.
when you are saying myFunction, it is in short called Camel Notation
can you please elaborate about the notation ? what is the reason of naming pascal notation or Camel notation?
Re: Java coding convention
well, camel notation or camelcase is something like this:
see? it goes down, it goes up.
Actually, camel case notation is of two types.
one is the upper camel case, the other is lower camel case.
Most people use the camel case name while actually meaning the lower case notation.
And Anders Heilsberg was the person who originally designed the turbo pascal.
Probably it came from the time of designing the .net framework as he was in the designer team, and other languages adopted it.
BTW, i picked up this link about coding conventions. It is a summary type, won't take much time to read.
http://www.oracle.com/technetwork/java/codeconventions-135099.html
see? it goes down, it goes up.
Actually, camel case notation is of two types.
one is the upper camel case, the other is lower camel case.
Most people use the camel case name while actually meaning the lower case notation.
And Anders Heilsberg was the person who originally designed the turbo pascal.
Probably it came from the time of designing the .net framework as he was in the designer team, and other languages adopted it.
BTW, i picked up this link about coding conventions. It is a summary type, won't take much time to read.
http://www.oracle.com/technetwork/java/codeconventions-135099.html
Similar topics
» Java Tutorial: Using Two Java Reference Keywords, this and super
» Java Swing Example
» Inheritance in Java
» PDF Generation in Java
» Java 7
» Java Swing Example
» Inheritance in Java
» PDF Generation in Java
» Java 7
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Tue Sep 29, 2015 2:45 pm by Sophiawood
» Cisco EHWIC SFP/GE WAN Card
Mon Sep 07, 2015 11:08 am by Sophiawood
» Huawei S1700-28GFR-4P-AC Price
Thu Jun 25, 2015 2:31 pm by Sophiawood
» teach yourself C++ / Herbert Schildt Solutions
Wed Jun 03, 2015 1:52 pm by Abdullah Al Noman
» teach yourself c by herbert schildt pdf
Wed May 13, 2015 11:01 pm by Raquib Ridwan
» ASA 5506X With Firepower ASA5506-K9
Fri Apr 10, 2015 4:31 pm by Sophiawood
» New Trends in Deal Business
Tue Feb 03, 2015 9:38 pm by nersoa
» PoE Power Allocation for WS-C2960S-24PS-L
Wed Nov 05, 2014 11:12 am by Sophiawood
» How to cure back pain
Fri Oct 31, 2014 7:15 pm by Bergen Guildford