views:

202

answers:

4

If one adds many framework dependencies to a Java application, will this increase its memory footprint drastically, because it preloads all libraries at startup or is that a more lazy behaviour which would load only the needed classes when you actually need it (e.g. import statements or even later)?

Could adding many dependencies also have other negative side effects that a Java developer should be aware of?

+3  A: 

Classes will only be loaded as required (referenced by other classes via import etc.)

The headache with multiple frameworks is that you have to manage their shared dependencies. e.g. Framework A requires Logging Framework X, but Framework B requires Logging Framework Y.

These problems aren't insurmountable, but you have to keep track of them. When you upgrade Framework A, you may well end up with a ripple effect, in which you have to update a corresponding dependency. That then requires another framework component update, and so on.

e.g. Framework A gets upgraded, and requires an update to Log4J. THat then forces you to update Framework B to a version compatible with your new Log4J, and so on.

If you have multiple framework requirements, this may in fact point to a requirement to subdivide your application accordingly (into different deployables/services etc.).

Brian Agnew
The hardest thing here can be version dependencies. Not only do the frameworks depend on other frameworks/libs, but sometimes specific versions of those deps.
Scott Stanchfield
That's what I'm getting at (or trying to). Note the comment re Framework A and the ripple effect. I will edit to emphasise this, however.
Brian Agnew
Haven't viewed this under the aspect of indirect dependencies until now. A former software development leader of mine used to always be extremely critical (maybe a bit too much) when someone introduced a new dependency. The use of Maven helps a lot here. Thanks.
Markus Lux
+1  A: 

Conceptually you are probably also adding a large amount of overlapping functionality to your code base when you're adding a large number of frameworks. This overload can also get to be quite a headache, and you'll be having different people using different versions of the same features (from different frameworks) for no apparent reason. It can get messy.

krosenvold
A: 

If you are worried about the size of the distributed applications due to having loads of dependencies on third party jars you could always obfuscate/shrink it which usually reduces the size of the application by a signicifant amount. I've used Pro Guard in the past and it will also reduce the size of the dependencies that you have through obfuscation and removing unused classes/methods/fields etc.

willcodejavaforfood
A: 

Technically, if you are using more than one framework in java & your system is pretty large & if your framework will reduce the overhead of java code then it is fine to work with it. For e.g. if you system is so large then you can use Hibernate for Object Relation Mapping with database. It will reduce your code burden like insert, update, delete queries. But if your system is not so large, you can write above manually & it will not take as much time for processing as hibernate does. Same case in Spring or Struts2.

Nirmal