aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Few question about source formatting/elements. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Few question about source formatting/elements." Watch "Few question about source formatting/elements." New topic
Author

Few question about source formatting/elements.

Adam Gmoch
Greenhorn

Joined: Jun 20, 2010
Posts: 4
Hi,
Last two days I was digging this forum but didn't found answers for my question, maybe somebody will help me ;)

The questions are:
I using checkStyle eclipse plugin & I got few warnings which annoys me:

1) Expression can be simplified.
It shows in any conditions in which I use true/false values for example:

I know that I can use form


or with ! mark instead of false, but I hate this form. Is it "error" in this exam, or can I lose points for it ?


2) Avoid inline conditions.

Should I remove all lines with something like this:


3) Missing package-info.java file.
This is really mistery for me, can somebody tell me what & where should I put ?

4) Redundant throws: 'xxx' is unchecked exception.
This is tricky because if I delete throws clausule from method definition then java doc is not happy about description to throw which is not declared... So should I delete this kind of throws & their descriptions or ignore this warning ?

Regards.
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2247

Howdy, Adam! Welcome to our JavaRanch and good luck with your assignment!

The most important thing is to follow code conventions proposed by Sun, which can be found here.

1) Expression can be simplified.


The conventions are not explicit about this, but I'd go with if (i). I don't think that you'll lose points for choosing the first or the second form.

2) Avoid inline conditions.


Hmm... I don't think that's necessary. You can keep the inline conditions (I myself used it).

3) Missing package-info.java file.


This is a file where you can keep information about your package. You can, for instance, declare your package in this file, add annotations to it and retrieve them at runtime with getClass().getPackage().getAnnotations()... when you define this file, you can add JavaDoc comments to it and they will appear in the "Packages" section of your comments. This is not necessary, even though it is a good idea to have one per package.

4) Redundant throws: 'xxx' is unchecked exception.


Well, honestly, I didn't keep them, but each one has it own @throws tag in the JavaDoc comments.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 4926
    
  10

Hi Adam,

Welcome to the JavaRanch!

I am not a huge fan of all these check code style plugins/tools, because they generate a whole lot of warnings which I don't agree with. Some of them I tested (after submitting) and here you can read my experiences.
For the assignment I just created a code formatter in Eclipse and that's the only thing I used during development. Just use a consistent way of coding through your complete application.

Regarding your questions:
0/ always use sun's (or is it oracle's) code conventions.
1/ I agree with Roberto: if (aBoolean) {} should be the way to go. And if aBoolean is not a primitive, but a wrapper object, you should go for if (Boolean.TRUE.equals(aBoolean)) {} (otherwise you could risk a NullPointerException during unboxing). If you write your own code, you should always opt for a primitive to avoid this unboxing issue.
2/ I used it myself too, so don't remove these lines.
3/ I didn't used such files and adding javadoc to the package section (like Roberto indicates) could also be done with adding an overview.html per package (that's what I did)
4/ I handled them the same way as Brazils SCJD guru

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Adam Gmoch
Greenhorn

Joined: Jun 20, 2010
Posts: 4
Thanks for fast reply I'll do as you say.
Adam Gmoch
Greenhorn

Joined: Jun 20, 2010
Posts: 4
One more question: empty lines between source sections...
is it ok ?



I'm read Code Conventions & check src formating in JDK. And to be honest they didn't follow rules which they desribed. I also check in "SCJD Exam with J2SE 5" book and there are little differences. So I'm more confused then before...
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2247

Well champ, try to stick to their rules as much as you can. In fact, there are some points where they are not very explicit, so try to have good sense and everything will be fine. I honestly don't believe that you'll lose points if they find one or two mistakes regarding code conventions. The things that can make you lose points considerably are the locking mechanism and not following any of the "musts" that are described in the assignment.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 4926
    
  10

Roberto Perillo wrote:I honestly don't believe that you'll lose points if they find one or two mistakes regarding code conventions.

If you just use the same conventions throughout your complete code, you won't lose points. Because if your code is consistent all the way, it will increase the readibility of your code. But you won't lose points because you added 1 blank line instead of 2. Just use a formatter, tweak it a bit and you'll be fine!
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2247

Roel De Nijs wrote:But you won't lose points because you added 1 blank line instead of 2. Just use a formatter, tweak it a bit and you'll be fine!


That's what I'm talking about!
Adam Gmoch
Greenhorn

Joined: Jun 20, 2010
Posts: 4
Thanks, I'll hope you right. I finally finished formatting code. In next 2-4 days I'll send it to Sun & go for beer ;)
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 4926
    
  10

Adam Gmoch wrote:Thanks, I'll hope you right.

I think my score speaks for itself
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Few question about source formatting/elements.
 
Similar Threads
java.io
Input/Output for SCJP.
about K&B book (SCJP 6)
Input/Output for SCJP.
Assertification problem