• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Coding convention for annotation

 
Vairoj Arunyaangkul
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question regarding coding convention for the SCJD project. The instruction tells me to adhere to Sun Java Coding Convention which unfortunately, last revised nine years ago. So there is no instruction on the convention for new Java language constructs such as annotation. Therefore, I would like to ask here what is the convention for declaring annotation?

What I have seen is:

@SuppressWarning
public void someMethod() {
}

What if there is two or more annotation to declare, and what about JavaDoc? Will it looks like this?

/**
* This is a javadoc
*/
@SuppressWarning
@SomeOtherAnnotation
public void someMethod() {
}

Speaking of annotation, will it be ok if I would like to have some non-standard annotations in my source code? For example, I use FindBugs as my static analysis tool and the use of annotations like @NotNull, @Nullable helps FindBugs on their job. Is this ok for SCJD submission or should I avoid using them?
 
Alex Belisle Turcot
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vairoj Arunyaangkul:
I have a question regarding coding convention for the SCJD project. The instruction tells me to adhere to Sun Java Coding Convention which unfortunately, last revised nine years ago. So there is no instruction on the convention for new Java language constructs such as annotation. Therefore, I would like to ask here what is the convention for declaring annotation?

What I have seen is:

@SuppressWarning
public void someMethod() {
}

What if there is two or more annotation to declare, and what about JavaDoc? Will it looks like this?

/**
* This is a javadoc
*/
@SuppressWarning
@SomeOtherAnnotation
public void someMethod() {
}

Speaking of annotation, will it be ok if I would like to have some non-standard annotations in my source code? For example, I use FindBugs as my static analysis tool and the use of annotations like @NotNull, @Nullable helps FindBugs on their job. Is this ok for SCJD submission or should I avoid using them?


Hi,

as no one answered, I'll give you my opinion.. I personally fixed my code so that the warnings were no longer displayed. And if that was not possible, I kept the warning and did not used the annotations. I just thought it wasn't a good practice to blind yourself from the errors/warnings, for no other reason than "not being annoyed by it"

Also, I wouldn't include third party annotation for this assignment, since the whole point is being judge on it by SUN. That's just me.. But in the end, if it helps you find bugs it's much better to do so. I very much doubt SUN is looking to subtract points for using annotations.

One more thought.. I haven't used findbugs's annotation... do you need to add any jar file in the classpath ? If So, then you must not use them! You must not depends on other libraries:

Quoted from the instructions:
The final program must have no dependencies on any libraries other than those of the Java 2 Platform.


bye,
Alex
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic