Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Quick basic java questions!!

Options
  • 07-05-2004 2:43pm
    #1
    Registered Users Posts: 940 ✭✭✭


    Whats the difference between

    private variables
    and
    public variables?

    Also

    What the hell is linear searching??


Comments

  • Closed Accounts Posts: 142 ✭✭lukeUCD


    public can be accessed by any class whereas private variables can only be accessed by subclasses or classes in the same package.

    think linear search is something like searching an array for the smallest value


  • Registered Users Posts: 940 ✭✭✭LanceStorm


    Ah, most helpful thanks!!


  • Registered Users Posts: 27 Harry Lime




  • Moderators, Music Moderators Posts: 1,481 Mod ✭✭✭✭satchmo


    Originally posted by lukeUCD
    public can be accessed by any class whereas private variables can only be accessed by subclasses or classes in the same package.
    It's protected variables that can only be accessed by subclasses or classes in the same package. Private variables can be accessed only by that class.


  • Registered Users Posts: 3,548 ✭✭✭Draupnir


    linear search sucks cos you go through each individual item looking for what you want. thats linear search.

    not a patch on a good old binary search


  • Advertisement
  • Registered Users Posts: 15,443 ✭✭✭✭bonkey


    Originally posted by Draupnir
    linear search sucks cos you go through each individual item looking for what you want. thats linear search.

    not a patch on a good old binary search

    Depends on the size of your dataset, and whether or not it is already sorted, actually.

    For a single search on unsorted data, a linear search will generally beat the living crap out of a binary search - or any other non-random search method for that matter - as the binary search (and others) will require a sort beforehand, and that sort will typically be more expensive than the linear search itself.

    This might seem overly pedantic, but its not really.

    Its important to realise that there are plenty of situations where implementing "good old binary search" is not your friend, whereas implementing one of the "suckier" methods will be. The trick comes in spotting what is useful when.

    jc


Advertisement