Results 1 to 7 of 7
  1. #1
    ajeeb is offline Member
    Join Date
    Dec 2008
    Posts
    30
    Rep Power
    0

    Default Java coding Best Practices

    Can anyone point me to some best practices for java coding?
    Pracices following which will make codes more robust.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  3. #3
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    Along with that, I would suggest doing things in a consistent manner. Choose an approach for routine things, and always do it the same way. Basically, avoid taking coding short cuts. Consistency allows others to get a feel for your style, and it also helps you to avoid making trivial mistakes that are sometimes hard to find.

  4. #4
    Tshegofatsom is offline Member
    Join Date
    Apr 2009
    Location
    Pretoria, Gauteng, South Africa
    Posts
    43
    Rep Power
    0

    Default

    Stevie, could you please give an example of what you mean about consistency? I do not really follow.
    Tshegofatso Manakana
    a.k.a Untouchable

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    I think he's talking about a common ways all others following. Same design pattern may be, which most people do.

  6. #6
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    Here is a good example. You can write an "if" statement two ways:

    if (condition) method();

    if (condition) {
    method();
    }

    Both are correct, but the first way only works if you only want to execute one statement after the "if". The second way always works. I *always* put braces after an "if", even when it is not necessary.

    This sounds trivial, but my point is that there are many little things like this. If you do these many little things each in a consistent manner, then your coding style will appear consistent to others. Not to mention, when you come back to something you wrote after two years, you will be able to figure out what you did ;-)

    Another good habit is to write brief, meaningful comments *while* you code. A good comment should be a short as possible, but no shorter. Explain *why* you are doing something; the code should be clear enough to to say *what* you are doing.

    If you are a professional programmer, then other people will work on the code you write. Remember to treat them the way you want to be treated.

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Steve11235 View Post
    If you are a professional programmer, then other people will work on the code you write. Remember to treat them the way you want to be treated.
    Thumbs up lol for this comment.

    Most of the time, in a single project large number of people are working on. If your code cannot read and understood in easy way, most common way for others.. it may going to your last project. ;)

Similar Threads

  1. Coding an FTP server in java
    By Zucheto in forum Networking
    Replies: 3
    Last Post: 06-22-2008, 05:24 AM
  2. Java Coding Competition
    By nbrain in forum Java Software
    Replies: 0
    Last Post: 05-22-2008, 06:38 PM
  3. Coding Java on a Mac
    By Menre in forum New To Java
    Replies: 5
    Last Post: 05-06-2008, 06:49 AM
  4. best practices guide to Java/J2EE web aps
    By javaforme44a in forum New To Java
    Replies: 7
    Last Post: 07-18-2007, 08:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •