Results 1 to 4 of 4
  1. #1
    Mortanto is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default Need a little help

    Its been a few years since i've done any java at all so feel like a complete beginner. I'm currently making a program that will store a collection of different types of books, journals, atricles etc there 6 different types with different attributes but they all have 3 attributes in common so i know that's a good start for a base class.

    I have just completely forgot how to do any thing really so a few pointers would be helpful.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default Re: Need a little help

    Read about the Collections framework. (they're all in the API documentation).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Mortanto is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default Re: Need a little help

    Right will have a look into it. Its more I really cant figure out what classes im actually going to need. Once i figure this out I should be ok really

  4. #4
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Need a little help

    Well, you'll want to model your items first. You mentioned different types with common variables. Perfect example of inheritance - you can make an abstract class called something like "Media" which contains your shared fields and methods. From there, you can extend this class with your specialty classes: Journal, Paper, Letter, Book, etc... each with their own unique additions.

    From there, use the collections framework Jos mentioned to find a data structure suitable for what you want to do. For example, if you were storing millions of items and would frequently be looking them up using key values (like a bar code, or serial number) then a HashMap is awesome. If you need predictable iteration (sorted keys) you could use a LinkedHashMap. If you had a great deal of insertion and deletion and need to maintain a sorted list, you could use a binary tree structure (there are numerous options here). If you are relating items together with different types of abstract relationships, you could use a pure map structure.

    Each data structure has it's own pros/cons. The best one for the job depends on what you intend to do with the data on a daily basis. I'm a big fan of HashMap structures for their constant-time lookup performance.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •