Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Quick basic java questions!!

  • 07-05-2004 02:43PM
    #1
    Registered Users, Registered Users 2 Posts: 947 ✭✭✭


    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, Registered Users 2 Posts: 947 ✭✭✭LanceStorm


    Ah, most helpful thanks!!


  • Registered Users, Registered Users 2 Posts: 27 Harry Lime




  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭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, Registered Users 2 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, Registered Users 2 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