Praveen
Praveen

Reputation: 91175

Is there a coding standard for Java?

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 Standard to for coding. I have a question like how to name the variables methods & what is the best way to package the classes. like that?

For that, is there any tutorial or example please share .

Thanks in Advance.

Upvotes: 3

Views: 1646

Answers (4)

jaguililla
jaguililla

Reputation: 2086

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.

Upvotes: 0

Garis M Suero
Garis M Suero

Reputation: 8169

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

Upvotes: 8

YoK
YoK

Reputation: 14505

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/

Upvotes: 0

Coding District
Coding District

Reputation: 11931

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.

Upvotes: 6

Related Questions