Is there a coding standard for Java?

后端 未结 4 912
小鲜肉
小鲜肉 2021-01-20 22:56

I can develop an application/project. But that is not in the correct coding standard. it takes large memory and others can not be understand it easily. What the General Stan

相关标签:
4条回答
  • 2021-01-20 23:00

    What you need are the best-practices (JAVA) and how it works.

    I will recommend an older post

    as Macarse said:

    Have you read Effective Java? http://java.sun.com/docs/books/effective/

    There is a good amount of good code in it.

    To learn how things are done (in the best way) I'll recommend to always check other people's code, especially the open source projects.

    You can always check the jdk source code, there are some good algorithms around it: http://java.sun.com/j2se/1.5.0/source_license.html

    Also, sometimes I use to research some good open source apps code...

    edited: Also is a good idea to participate in communities like this....

    Check this out: http://www.javadb.com/

    as Naiku said:

    The best option for you to study good code is to look at some popular open source projects. I think 2 years is good enough time to understand code in these projects. Some of the projects you could look at:

    * openjdk
    * apache tomcat
    * spring framework
    * apache commons (very useful)
    * Google collections
    

    Enough for you to study and understand a variety of concepts. I frequently study code in JDK catalina(tomcat), spring, jboss, etc.

    For Java Memory Management see this Question

    0 讨论(0)
  • 2021-01-20 23:00

    http://www.oracle.com/technetwork/java/codeconvtoc-136057.html

    If a project you're already working on has coding standards defined, use that. Otherwise, you can follow standards like the one I linked above and make sure you're consistent in using it. It'll help make your programs readable for yourself and others.

    0 讨论(0)
  • 2021-01-20 23:16

    There are many coding standards for Java. I.e.: OpenJDK (this is my preferred one) or Google ones.

    Unfortunately if you search Internet you will find the outdated Sun guidelines (Oracle still maintains that document online).

    It is wise to accommodate to platform coding standards the most you can. However they are a matter of style and thus, you can bend some rules to your (or your team) likings keeping them as a base.

    The most important things about having a coding standard are:

    1. All your code complies with it.
    2. It is clearly stated which are the rules, and they are easy to find in your code base (a good place would be the file README.*).

    In my case, my coding standards are something like: OpenJDK standard, except closing brackets in their own line.

    0 讨论(0)
  • 2021-01-20 23:26

    Here are few more links for Java coding standards. You will notice that it is not a hard and fast rule that these conventions needs to be followed, Developer community just adopts subset of these or whatever fits best as per their needs.

    http://www.ontko.com/java/java_coding_standards.html

    http://www.javarmi.com/2010/05/java-coding-standards-and-best-practices-2/

    0 讨论(0)
提交回复
热议问题