IITDU Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Java coding convention

3 posters

Go down

Java coding convention  Empty Java coding convention

Post by BIT0112-Rokon Fri Jul 30, 2010 7:24 pm

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 -

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.....
BIT0112-Rokon
BIT0112-Rokon
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : O+
Posts : 673
Points : 1269

http://blog.codexplo.org

Back to top Go down

Java coding convention  Empty Re: Java coding convention

Post by BIT0125-Tauhid Sun Aug 08, 2010 6:52 pm

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...
BIT0125-Tauhid
BIT0125-Tauhid
Club Moderator
Club Moderator

Posts : 113
Points : 176

Back to top Go down

Java coding convention  Empty Re: Java coding convention

Post by BIT0122-Amit Mon Aug 09, 2010 12:53 am

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
BIT0122-Amit
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

https://iitdu.forumotion.com

Back to top Go down

Java coding convention  Empty Re: Java coding convention

Post by BIT0112-Rokon Fri Aug 20, 2010 3:44 pm

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?
BIT0112-Rokon
BIT0112-Rokon
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : O+
Posts : 673
Points : 1269

http://blog.codexplo.org

Back to top Go down

Java coding convention  Empty Re: Java coding convention

Post by BIT0122-Amit Fri Aug 20, 2010 4:17 pm

well, camel notation or camelcase is something like this:

Java coding convention  250px-CamelCase.svg

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


BIT0122-Amit
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

https://iitdu.forumotion.com

Back to top Go down

Java coding convention  Empty Re: Java coding convention

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum