Results 1 to 7 of 7
  1. #1
    Quentin's Avatar
    Quentin is offline Member
    Join Date
    Oct 2014
    Posts
    6
    Rep Power
    0

    Default Loading classes at program startup

    Hello,

    I'm reading Core Java and in the section about reflection there is a following tip:

    At startup, the class containing your main method is loaded. It loads all classes that it needs. Each of those loaded classes loads the classes that it needs, and so on. That can take a long time for a big application, frustrating the user. You can give users of your program the illusion of a faster start with the following trick. Make sure that the class containing the main method does not explicitly refer to other classes. In it, display a splash screen. Then manually force the loading of other classes by calling Class.forName.
    I'm not sure if I got this right - the tip amounts to suggesting to load all the classes altogether in the main method while displaying the splash screen?

    Second, how can the main method not refer explicitly to other classes? It has to create some objects after all...

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,993
    Rep Power
    9

    Default Re: Loading classes at program startup

    I am sure there is a point of truth in this, but I would think a modern day classloader would have some smart stuff built in to prevent loading the entire JRE and custom classes all at startup. Even if you would do this, I doubt you would get a real better startup performance.

    What year is this book from?
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Loading classes at program startup

    That sounds like a tip specifically for applets when using the "old" plugin.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Loading classes at program startup

    Quote Originally Posted by Quentin View Post
    I'm not sure if I got this right - the tip amounts to suggesting to load all the classes altogether in the main method while displaying the splash screen?
    I do not believe the intent here is to load classes faster. It is to prevent the user from thinking that things have gone wrong. For example, Eclipse takes a while to start up. So it uses a splash screen and actually shows the classes being loaded. This gives the user a sense that thinks are progressing and the app is not hung up.

    Perception is key in a lot of user situations. I was talking to a colleague about this years ago. His company had some old CRT's that wold slowly display the text. It took about 5-10 seconds to fill a screen. The users complained. So they changed the code to buffer the output and display it in a single flash. Still took the same amount of time but the users thought that it was so much faster.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Loading classes at program startup

    Pacifiers ... in the (very) old days, they used to give a piece of cloth, soaked in Jenever, to little babies. to keep them quiet; those were the days. ;-)

    kind regards,

    Jos
    Last edited by JosAH; 11-29-2014 at 07:35 PM. Reason: typos ...
    Build a wall around Donald Trump; I'll pay for it.

  6. #6
    Quentin's Avatar
    Quentin is offline Member
    Join Date
    Oct 2014
    Posts
    6
    Rep Power
    0

    Default Re: Loading classes at program startup

    Quote Originally Posted by SurfMan View Post
    What year is this book from?
    From 2012, it describes Java 7.

    Quote Originally Posted by jim829 View Post
    I do not believe the intent here is to load classes faster. It is to prevent the user from thinking that things have gone wrong. For example, Eclipse takes a while to start up. So it uses a splash screen and actually shows the classes being loaded. This gives the user a sense that thinks are progressing and the app is not hung up.
    That's exactly what I meant.

  7. #7
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Loading classes at program startup

    Quote Originally Posted by jim829 View Post
    For example, Eclipse takes a while to start up. So it uses a splash screen and actually shows the classes being loaded.
    Eclipse is a bit of an odd example since it doesn't even load classes in the conventional way but rather through a complicated module system that goes way beyond a regular classloader. Its not only loading classes, its also 'discovering' all the thousands of classes in the dozens of plugin jars, doing integrity checks on them and on most systems also making sure they're still up to date. In all that process its also processing dozens upon hundreds of XML files.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Multiple classes in a program help
    By Lorelei7 in forum New To Java
    Replies: 4
    Last Post: 11-23-2013, 07:23 PM
  2. Loading classes based on name and superclass
    By jsobel in forum Advanced Java
    Replies: 1
    Last Post: 10-25-2012, 11:36 PM
  3. Loading an old file into an updated program
    By crivers in forum New To Java
    Replies: 2
    Last Post: 06-10-2011, 06:34 AM
  4. which classes to write..how to program this?
    By sony1 in forum New To Java
    Replies: 7
    Last Post: 09-04-2010, 07:12 PM
  5. Java program is not loading
    By shoeb83 in forum New To Java
    Replies: 2
    Last Post: 12-29-2009, 03:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •