This discussion is archived
5 Replies Latest reply: Mar 5, 2013 9:46 AM by 939520 RSS

Organizing my Project - Help!

994434 Newbie
Currently Being Moderated
Hey guys,

So it's been a while since I've worked with Java and while I know the language well enough (syntax-wise), I am somewhat lost when it comes to organization of a project (i.e. when I should be creating a class, where methods should be going, etc.). Here's what I'm trying to do:

In one of my classes we're working with FAT data structures in (root directory entries, FAT tables, etc.). I'm working on writing a program that will accept, as input, a 32-byte long hexadecimal root directory entry and spit out metadata about that entry (i.e. when the file was created, accessed, modified, file size, etc.). I have a portion of this working - as of right now my program can take a 4-byte long hexadecimal input and convert that to a date, which is great. There are a few issues however:

I wrote this program in Blue Jay and am now realizing that I should probably be using Eclipse or NetBeans (I'm hearing NetBeans is better??). I want to continue work on the program but don't want to continue writing in Blue Jay as I feel it will only be harder to bring it all into NetBeans or Eclipse later on.

Additionally, I feel like my formatting for the entire project is just way off. I don't really know when to create a class - as of right now my entire program is operating within one class, called Convert and everything happens within that class (it has methods such as: convertHextoDecimal, convertHexToBinary, convertHextoDate, etc.). Should I be structuring this differently? I'm thinking maybe I should be creating a Date class that handles all date information, a time class that handles all time information, a size class that handles all file size information, and so on. Would this be better? I really don't know where to go from here and don't want to do any more work on it until I feel like I'm not using the most roundabout way to get things done.

Any help would be appreciated!
  • 1. Re: Organizing my Project - Help!
    TPD-Opitz-Consulting-com Expert
    Currently Being Moderated
    991431 wrote:
    In one of my classes we're working with FAT data structures in (root directory entries, FAT tables, etc.). I'm working on writing a program that will accept, as input, a 32-byte long hexadecimal root directory entry and spit out metadata about that entry (i.e. when the file was created, accessed, modified, file size, etc.). I have a portion of this working - as of right now my program can take a 4-byte long hexadecimal input and convert that to a date, which is great. There are a few issues however:

    I wrote this program in Blue Jay and am now realizing that I should probably be using Eclipse or NetBeans (I'm hearing NetBeans is better??). I want to continue work on the program but don't want to continue writing in Blue Jay as I feel it will only be harder to bring it all into NetBeans or Eclipse later on.
    Never mind.
    The tricky part is to take over 3rd party lib-dependencies.
    Take a look at maven or gradle how they can assist you with handling the dependencies.

    Your own code lives in a folder called <tt>src</tt> (or something alike). Its content can simply be copied to where the other IDE (or maven/gradle) expects source files.
    Additionally, I feel like my formatting for the entire project is just way off. I don't really know when to create a class - as of right now my entire program is operating within one class,
    That's a bad approach.

    The rule of thumb is: make your classes as small as possible. The same applies to the methods.
    Don't be afraid to have to many classes. just start to organize them in packages as soon as possible.
    Clases should have a narrow scope of responsibility. eg.: Your "Converters" You mention 3 of them. This could be 3 classes of their own implementimng a "Converter" interface. This would turn out that all three classes have the same public method. e.g.:
    interface Converter<T> { <T> convertFromHex(String theHexString);}
    class DateConverter <java.util.Date> {
      @Override public java.util.Date convertFromHex(String theHexString){
             // conversion code here
        }
    }
    class BigDecimalConverter <BigDecimal> {
      @Override public BigDecimal convertFromHex(String theHexString){
             // conversion code here
        }
    }
    I'd suggest to read "Clean Code" by "Uncle BoB" before proceeding.
    http://www.amazon.de/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882

    bye
    TT
  • 2. Re: Organizing my Project - Help!
    939520 Explorer
    Currently Being Moderated
    I suggest you provide javadoc comments above each class and each function within the class so someone after you can easily understand the program. It will also help you organize your thoughts and stop adding functionality to a class that rightfully belongs in some other class.
    For instance, convertHextoDecimal() means nothing to me, as does 'a 32-byte long hexadecimal root directory entry'.
    As for organizing your program, you might want to look up MVC (model view controller) concept. As for Eclipse vs Netbeans, either one is ok. I personally suggest Eclipse since its too tempting to let Netbeans generate code for you via wizards rather then reason it out yourself.

    Example:
     
    
    /** provides all the functionality to read/write to a file and obtain metadata about a file */ 
    public class FileInformation{ 
    
      /** constructor */ 
      public FileInformation(String filePath, String fileName){ 
      } 
    
      /** returns file file content as a list of lines */ 
      public List<String> getLines(){ 
    
      } 
    
    
    } 
  • 3. Re: Organizing my Project - Help!
    gimbal2 Guru
    Currently Being Moderated
    Documentation is good. Too much documentation is very bad. Self-documenting code is what you should aim for. As long as you're not playing captain obvious or adding comments just so you have nice color dividers in an IDE. Let me cast an example:
    /** constructor */
    public MySuperDuperConstructor(){
    
    }
    Captain obvious. The only people who need that comment is people who don't know squat about Java. It may seem petty to fall over that - before you know it your code is weeded over with non-information.
  • 4. Re: Organizing my Project - Help!
    TPD-Opitz-Consulting-com Expert
    Currently Being Moderated
    There are roughly 2 places where you should add comments:
    <ul><li>in the Header of public calsses if their use needs some explanation. (be verbose here)</li>
    <li>at any other place to tell why the code is this way in case it is not obvisous.</li></ul>

    bye
    TPD
  • 5. Re: Organizing my Project - Help!
    939520 Explorer
    Currently Being Moderated
    Addendum:
    Your documentation should say what (service) the class/function provides, not how it does it. Also, what any input arguments for a function are if not obvious (same thing with the return value). You can add additional documentation within the body of a function if that code is not clear in what it does.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points