My personal recommendation is to go for option #1 because option #2 will make the sessions heavy weight. Also, it is not possible to create everything in advance and keep it when you are working on large projects. For example: I have thousands of different screens and they are getting loaded from the database via a special class loader.
I mix both #1 and #2. Some main parts of application that are don’t change in UI design but display this or that data are pre-created as views and then I simply switch to the view I need, passing the reference of data to load and display, so view simply updates it’s widgets states and values.
I have also used option #3: Lazy-loading UI classes when first accessed.
The basic idea is to have a menu of some kind to hold the class name of the (Custom-)Component class implementing the view. Then on menu selection we call Class.forName() to actually load the class before we instantiate it.
This combined with some View-ViewManager pattern and you can have virtually unlimited number of views in you application without sacrificing the initial application load time. Also this way the Views themselves can more likely to be populated using scheme #1 as they tend to be smaller.
(A side note: This was some time ago with JDK 1.4. We found out that eager Java class loading itself took some resources in large systems - not only the class instantiation. This may have changed in newer Java versions / app servers)
Sami,
I have used this technique in almost all my applications. Instead of Class.forName(), I used a customized class loader that load bytecodes from the database itself. This is how I keep logic in most of the applications. The application jar file is just for loading a small initial set of “boot” classes and the rest is all loaded dynamically from the database.
I have been using this technique from JDK1.1.6 onwards and never faced with any issues.