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.

A few questions about java

  • 23-02-2007 06:33PM
    #1
    Registered Users, Registered Users 2 Posts: 2,481 ✭✭✭


    I've been working with java as a student for a while, and I realised recently that there's a few areas which I just don't have a clue about.
    Ok, here goes:

    1/ Will including more packages than I need increase the memory footprint of my program and/or degrade its performance? (eg. import java.util.* instead of java.util.Vector)

    2/ I usually use eclipse (not sure if this is important). Why is it that my syntax errors are corrected on the fly in java, whereas in c++ I need to compile my program first to find out where I went wrong?

    3/ It seems to me that Vectors do everything arrays do and more. Why would anyone use arrays? (short of not having to do a typecast once you return an element from an array)


Comments

  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    Fremen wrote:
    1/ Will including more packages than I need increase the memory footprint of my program and/or degrade its performance? (eg. import java.util.* instead of java.util.Vector)

    It will increase compile time, but not affect runtime AFAIR. Someone correct me if I'm wrong. It's been a while.
    Fremen wrote:
    2/ I usually use eclipse (not sure if this is important). Why is it that my syntax errors are corrected on the fly in java, whereas in c++ I need to compile my program first to find out where I went wrong?

    This is just a nice feature of eclipse. It's effectively compiling on the fly. It's written in Java, so it's no surprise that it works better as a java editor.
    Fremen wrote:
    3/ It seems to me that Vectors do everything arrays do and more. Why would anyone use arrays? (short of not having to do a typecast once you return an element from an array)

    In c++, arrays are substantially faster (vectors are still fast mind you). I'd assume that Java arrays are implemented natively in a way that's closer to actual arrays than vectors. (this is just a guess).


  • Closed Accounts Posts: 619 ✭✭✭Afuera


    Khannie wrote:
    It will increase compile time, but not affect runtime AFAIR. Someone correct me if I'm wrong. It's been a while.
    I don't think that there's any discernable difference between those two ways of importing classes as the compiler only pulls in classes as and when it needs them anyway. I think it's rather a convention thing and makes for easier reading of code to see what classes are being used.
    Khannie wrote:
    In c++, arrays are substantially faster (vectors are still fast mind you). I'd assume that Java arrays are implemented natively in a way that's closer to actual arrays than vectors. (this is just a guess).
    Are Vectors not considered old school these days? An ArrayList can be used instead and because it's unsynchronized it should provide better speed.
    Like Khannie, I think that arrays are native and would explain the better performance from them.


  • Registered Users, Registered Users 2 Posts: 6,342 ✭✭✭OfflerCrocGod


    Vectors are for when you don't know how much and arrays for when you do. At least I think - it's all about performance as Vectors in Java are arrays that are dynamically increased in size as you add elements (I think that's it).


Advertisement