• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java coding standards

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could not get

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

 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Will Revels
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[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.
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
please buy this thing and then I get a fat cut of the action:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic