This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Java coding standards Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java coding standards" Watch "Java coding standards" New topic
Author

Java coding standards

Will Revels
Greenhorn

Joined: Jan 19, 2007
Posts: 7
Is there an easy way to remember what statements are suggested to use spaces and which are not ? For some programming languages there usually is an acronym that makes it easy to remember.

Thanks..... confused.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Could not get

Is there an easy way to remember what statements are suggested to use spaces and which are not ?


Rahul Bhattacharjee
LinkedIn - Blog
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14278
    
  21

Thanks..... confused.

Well, I'm confused by your question. Could you explain more clearly and in more detail what exactly you want to know?

Coding standards are ofcourse arbitrary. For Java, Sun has suggested code conventions long ago, which seem to be used by almost everybody who's programming in Java. You can find them here: Code Conventions for the Java Programming Language


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Will Revels
Greenhorn

Joined: Jan 19, 2007
Posts: 7
Originally posted by Jesper Young:

Well, I'm confused by your question. Could you explain more clearly and in more detail what exactly you want to know?

Coding standards are ofcourse arbitrary. For Java, Sun has suggested code conventions long ago, which seem to be used by almost everybody who's programming in Java. You can find them here: Code Conventions for the Java Programming Language


Thanks. I noticed looking at the style guide there are different suggestions about spacing.

Binary operators should have a space on either side
Unary operators should be immediately preceded or followed by their operand
Commas and semicolons are always followed by whitespace
The keywords if, while, for, switch, and catch must be followed by a space

I was trying to think is there an easy way to remeber all these rules.

Thanks Will
Will Revels
Greenhorn

Joined: Jan 19, 2007
Posts: 7
Originally posted by Jesper Young:

Well, I'm confused by your question. Could you explain more clearly and in more detail what exactly you want to know?

Coding standards are ofcourse arbitrary. For Java, Sun has suggested code conventions long ago, which seem to be used by almost everybody who's programming in Java. You can find them here: Code Conventions for the Java Programming Language


Thanks for the link, atually that seemed to be arranged a lot better than what I had in class. For me it makes it easier to remember with the formatting of this pdf.

Will
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[Jesper]: which seem to be used by almost everybody who's programming in Java.

Ummm... sort of. Kind of. Not really. Even Sun employees don't seem to follow this strictly, although they do follow most of it. However many people outside Sun do things differently - sometimes a little differently, sometimes very differently. The most obvious example is brace placement - plenty of people put '{' on a new line, and plenty of people don't. I have no problem with recommending Sun's standard in general (except for their advocacy of using tabs, and an idiotic rule about declaring local variables at the beginning of a block). But it would be naive to think that everyone uses them -- or even "almost" everybody. A good programmer needs to be fairly flexible about programming styles, I think.


"I'm not back." - Bill Harding, Twister
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14278
    
  21

Ofcourse, I didn't want to imply that you must use the Sun standard. It just seems to be the de-facto standard. I've done lots of projects for different clients, and sometimes they have their own coding standards, but most of the time they don't. My own personal coding style is close to the Sun standards, but probably not exactly to the letter.

If you're starting to work on a project that already has a lot of code, it's important to adapt to the coding conventions that are already used there. In my opinion, it's important to have a consistent coding standard across the whole project - that makes the code more readable and maintainable.

Good IDEs include tools to automatically format code to your preferences. In Eclipse for example you can configure a lot of details of yout coding standard and have Eclipse format your source file to those settings automatically.
Will Revels
Greenhorn

Joined: Jan 19, 2007
Posts: 7
Originally posted by Jesper Young:
Ofcourse, I didn't want to imply that you must use the Sun standard. It just seems to be the de-facto standard. I've done lots of projects for different clients, and sometimes they have their own coding standards, but most of the time they don't. My own personal coding style is close to the Sun standards, but probably not exactly to the letter.

If you're starting to work on a project that already has a lot of code, it's important to adapt to the coding conventions that are already used there. In my opinion, it's important to have a consistent coding standard across the whole project - that makes the code more readable and maintainable.

Good IDEs include tools to automatically format code to your preferences. In Eclipse for example you can configure a lot of details of yout coding standard and have Eclipse format your source file to those settings automatically.


I havent actually done any coding for business, mostly scripting for network management. So this is my first stab at Java. Which is needed now that I am in a Architech position that maintains standards for the company. So projects we get, I must approve. Thanks for the input, it gives me some ideas.
Will
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java coding standards