• 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

Few question about source formatting/elements.

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Adam Gmoch
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for fast reply I'll do as you say.
 
Adam Gmoch
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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


I think my score speaks for itself
 
reply
    Bookmark Topic Watch Topic
  • New Topic