tags:

views:

110

answers:

2

And what are the pro's con's of using either?

I actually saw it in Netbeans under Project Properties > Libraries for Java Applications. We have two tabs, one for compile time libraries and run time libraries, and it looks like we can add a library to either independent of each other

+7  A: 

There is no such a thing as compile time libraries vs. runtime libraries

Perhaps your mixing some concepts.

In Java the libraries to be used are statically validated at compile time and also validated at runtime.

For instance if you want to use IterableMap specified in the Apache Collections library. The compiler validates "at compile time" you are invoking a method that exist in that class.

But the compiler doesn't link or do much anything with that library, you still need it at runtime. So, when your code executes, the java runtime, search for that class again, and invoke the method the compiler verified existed.

And that what there is.

OscarRyz
Thanks for the info. But what abt reflections? If we try to use a class using reflection, the compiler wont complain, right? Something like [this](http://www.java-tips.org/java-se-tips/java.lang.reflect/invoke-method-using-reflection.html)
bdhar
@bdhar - reflection is just a different way of doing things that moves the validation to even later than class loading. The compiler knows nothing about the typing of the methods that get invoked this way, but the runtime system (specifically the reflection APIs) ensures that nothing unsafe happens.
Stephen C
Thanks Stephen..
bdhar
A: 

As others have stated, you are confusing concepts. I think what you are really trying to understand is what Maven refers to as dependency scope. Sometimes you only need a dependency at compile time because you expect it to be provided at runtime, and sometimes you need it at runtime but not compile time.

dbyrne