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

A few questions about java

Options
  • 23-02-2007 6:33pm
    #1
    Registered Users 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 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 Posts: 6,316 ✭✭✭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