Meaningless Drivel is fun!*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Sequencing Declarations Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Sequencing Declarations Question" Watch "Sequencing Declarations Question" New topic
Author

Sequencing Declarations Question

Marcelo Ruiz
Greenhorn

Joined: Dec 19, 2007
Posts: 25
Hi All!
I have a simple question about sequencing declarations in a Java Class. According to the information On Sierra&Bates book, the sequence should be:

  • class comments
  • package declaration
  • import statements
  • class declaration
  • static variables
  • instance variables
  • constructors
  • methods


  • What happens if I use a static factory method? Should it go before my private constructors?
    What about static methods in general? Should I put them also before the constructors?

    Thanks!

    Roel De Nijs
    Bartender

    Joined: Jul 19, 2004
    Posts: 5535
        
      13

    Hi Marcelo,

    I have first private constructor and then the static getInstance() method. In my utility classes I have first private constructor (prevent users from creating unnecessary instances) followed by all the static methods.

    Kind regards,
    Roel


    SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
    http://www.javaroe.be/
    Fernando Franzini
    Ranch Hand

    Joined: Jan 09, 2009
    Posts: 486
        
        2

    Hi Marcelo
    That's what page 4 and 5 on javadoc convention say about that it:
    7. Methods - These methods should be grouped by functionality rather than by scope or accessibility. For example, a private class method can be in
    between two public instance methods. The goal is to make reading and understanding the code easier.

    So...Marcelo your are free to put them where your functionality tell you to put, no matter what DP you are using.
    Regard.


    Fernando Franzini - Java Blog
    Marcelo Ruiz
    Greenhorn

    Joined: Dec 19, 2007
    Posts: 25
    Hi Fernando and Roel!

    Thanks for your answers... I was feeling a little confused about the topic...

    Marcelo
    Anne Crace
    Ranch Hand

    Joined: Aug 29, 2005
    Posts: 223
    Just curious on one point here. I had my class comments in the wrong place (right above the class declaration), so I moved them to before the package statement. Now my comments don't show up in the javadoc, whereas they used to. I just got permission to upload so I want to clarify this. It's probably minor, but I fixed it because every little bit helps!


    SCJP, SCJD
    Roberto Perillo
    Bartender

    Joined: Dec 28, 2007
    Posts: 2267
        
        3

    Howdy, Anne!

    So now your classes look like the DBFileReader class?


    Cheers, Bob "John Lennon" Perillo
    SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
    Anne Crace
    Ranch Hand

    Joined: Aug 29, 2005
    Posts: 223
    Yes, they do!
    Anne Crace
    Ranch Hand

    Joined: Aug 29, 2005
    Posts: 223
    Disregard my last post. They do not have the comments above the class declaration, so that would appear to be the problem. I'm having a hard time finding a good example online. I guess I'm uploading tonight when I get home so I can fix this. What's a few more hours??
    Roberto Perillo
    Bartender

    Joined: Dec 28, 2007
    Posts: 2267
        
        3

    Well... when I was developing the assignment, I looked at the How to Write Doc Comments for the JavaDoc Tool and the Code Conventions for the Java Programming Language pages. Another place I also looked was the source files that come along with the JDK. They are in a .zip file in the installation directory of your JDK.
    Anne Crace
    Ranch Hand

    Joined: Aug 29, 2005
    Posts: 223
    Thanks Roberto! The first one I found, but the other 2 were very helpful (especially looking at the source code from Sun ) I'll make the changes when I get home tonight and do my upload then.
    Roel De Nijs
    Bartender

    Joined: Jul 19, 2004
    Posts: 5535
        
      13

    I just looked at Roberto's test class and applied this structure to my own java files

    @Anne: finally submitting tonight? must be a great relief for you
    Anne Crace
    Ranch Hand

    Joined: Aug 29, 2005
    Posts: 223
    I almost don't want to do the fixes because I want to get rid of it so bad, but I've already spent so much time getting the javadocs at least close to being right, I'm going to do it
    Roberto Perillo
    Bartender

    Joined: Dec 28, 2007
    Posts: 2267
        
        3

    Howdy, Anne!

    I'd like to wish you good luck! Soon you'll also be a SCJD!!!
    Curse of the day: your score will be 400/400
    Anne Crace
    Ranch Hand

    Joined: Aug 29, 2005
    Posts: 223
    Curse of the day: your score will be 400/400
    I somehow doubt this will be the case, but I think I nailed locking, though! (thanks in part to your test)
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Sequencing Declarations Question