File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Java coding style Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Java coding style" Watch "Java coding style" New topic
Author

Java coding style

Martin Rea
Greenhorn

Joined: May 04, 2004
Posts: 12
This is a simple questions (and I should probably know the answer :roll: ):

When declaring a member final it is good java coding style to use UPPER_CASE_NAME (true?)

- but what about when declaring final references:

public static final dataClass Data;

- is the coding style also: DATA_CLASS or as above?

- Do anyone have a good reference to a java coding style guide (I have one from Sun but it's pretty old and surfacic) ?

- Are there points to loose on bad coding style?

Thanx in advance
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1064
When declaring a member final it is good java coding style to use UPPER_CASE_NAME (true?)
- TRUE

but what about when declaring final references:
public static final dataClass Data;
is the coding style also: DATA_CLASS or as above?

- I haven't used much final object references, so cannot comment.
Will wait for the others to respond.

Do anyone have a good reference to a java coding style guide (I have one from Sun but it's pretty old and surfacic)?
- It is only the JDK version and the associated API that has changed over the past years, not the java language. So Sun's old coding standards would suffice.If you think you need to get hold of something more recent, then I think Max's book contains coding convention tips in his first chapter and also Kathy's SCJP guide.(the last 2 chapters are meant for SCJD).

- Are there points to loose on bad coding style?
- Yes. I think so. Coding styles exist for better readability and maintainence.
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Martin,

When declaring a member final it is good java coding style to use UPPER_CASE_NAME (true?)


True. It's a coding habit inherited from C/C++ (at least) where constants are uppercased.


but what about when declaring final references:

public static final dataClass Data;

- is the coding style also: DATA_CLASS or as above?


I'm not sure I understand you, except to change the question as follows:

public static final DataClass DATA

- is the coding style also: DATA as above?


No for sure. But why? Here is my interpration: the final keyword will prevent you to reassign another DataClass object to your data reference, but the final keyword won't prevent the object itself to be modified. And as for most readers of Java code, the reference *is* the object ( ), uppercasing the reference would be misleading. Just my opinion.

Regards,

Phil.
Martin Rea
Greenhorn

Joined: May 04, 2004
Posts: 12
Thanks for the responses.
I just got hold of Max' Book today.

There is a link to a place on Javasoft homepage (if someone else are interested) that explains it all:

Code Conventions for the Java Programming Language
 
 
subject: Java coding style