3

i have one question. Does external JAR files that you import to main project runs in style of DLL's,in that way that main project will take them to operating memory only when they are used ,or are they in memory for whole run time of project ? I am asking cause i will be working one one project and i want it to be in Java but fast ,so i am looking for optimalizations of architecture of my project.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Ján Srniček
  • 505
  • 1
  • 10
  • 34
  • 1
    You're worrying about details far too early. Just follow best practices for code organization now and worry about speed later. Hint: it will have nothing to do with your organization of code. – Jonathon Reinhart Jan 20 '14 at 09:21
  • 1
    probably duplicate http://stackoverflow.com/q/4411028/1697099 – Premraj Jul 16 '15 at 07:38
  • Possible duplicate of [Difference between .jar and .dll file](http://stackoverflow.com/questions/4411028/difference-between-jar-and-dll-file) – RBT Mar 29 '17 at 02:44

2 Answers2

2

JARs contain classes (among other things) which are loaded in memory the first time they are used. Once they are loaded, they stay in memory (unless you specifically write some code to unload them).

So while that loading process may introduce some (small) lag at application startup, once everything is loaded you won't see any performance issue due to the way classes are loaded.

If you follow good coding practice, Java can allow you to create a high performance application.

assylias
  • 321,522
  • 82
  • 660
  • 783
  • Just to get a clarification - Loading a JAR file at start-up and loading a class later on when they are used for the first time have got different costs. Is that correct? At start-up of the application, the JAR file is loaded but not the classes. – RBT Mar 29 '17 at 02:51
0

From the article on Java Classloader in Wikipedia:

The Java Classloader is part of the JRE that loads classes dynamically into the JVM. Usually classes are only loaded on demand. The Java run time system does not need to know about files and file systems because of classloaders. Delegation is an important concept to understand when learning about classloaders.

When the JVM is started, three classloaders are started:

  1. Bootstrap class loader - loads the core Java classes Extensions

  2. class loader - code specified in extension directories

  3. System class loader - code in the classpath

All software libraries that do not get loaded by these class loaders (external jar files) are loaded on demand.

ucsunil
  • 7,378
  • 1
  • 27
  • 32