telling if a class is loaded

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • drsmooth
    New Member
    • Oct 2007
    • 112

    #1

    telling if a class is loaded

    if i use this:

    Code:
    Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
    how can i tell later on that it is loaded...im not sure i totally understand what the .forName does...

    thanks alot,
    ken
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by drsmooth
    if i use this:

    Code:
    Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
    how can i tell later on that it is loaded...im not sure i totally understand what the .forName does...

    thanks alot,
    ken
    If the method returns the class is loaded (and linked). If it throws an exception
    at you, you can be sure it isn't loaded nor linked. Read the API documentation.

    kind regards,

    Jos

    Comment

    • drsmooth
      New Member
      • Oct 2007
      • 112

      #3
      ok now i understand what it is, but i was wondering if theres a way of checking at a later time than when it is called if it was loaded...

      Comment

      • BigDaddyLH
        Recognized Expert Top Contributor
        • Dec 2007
        • 1216

        #4
        Originally posted by drsmooth
        ok now i understand what it is, but i was wondering if theres a way of checking at a later time than when it is called if it was loaded...
        Are you sure you need to know that? What are you trying to do? What is your goal?

        Comment

        • drsmooth
          New Member
          • Oct 2007
          • 112

          #5
          Originally posted by BigDaddyLH
          Are you sure you need to know that? What are you trying to do? What is your goal?
          im trying to eliminate multiple calls to it, i wrote a class to read/write info from/to a databse, but the methods are static and im not sure how to tell if the class is already loaded...i believe i have figured it out, i put an init() method that i call when the program is loaded so i suppose that will work, havent really tested it yet though

          thanks alot,
          ken

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by drsmooth
            im trying to eliminate multiple calls to it, i wrote a class to read/write info from/to a databse, but the methods are static and im not sure how to tell if the class is already loaded...i believe i have figured it out, i put an init() method that i call when the program is loaded so i suppose that will work, havent really tested it yet though

            thanks alot,
            ken
            The 'forName()' method doesn't reload a class once it is loaded and returns quite
            quickly. IMHO it isn't worth the trouble to guard against multiple calls but if you
            must, create a simple singleton that only calls this method when the singleton
            itself is created.

            kind regards,

            Jos

            Comment

            • drsmooth
              New Member
              • Oct 2007
              • 112

              #7
              Originally posted by JosAH
              The 'forName()' method doesn't reload a class once it is loaded and returns quite
              quickly. IMHO it isn't worth the trouble to guard against multiple calls but if you
              must, create a simple singleton that only calls this method when the singleton
              itself is created.

              kind regards,

              Jos
              yeah..it seemed to be taking the time everytime i called it...possible because of the fact i was working off a flash drive lol...

              thanks alot,
              ken

              Comment

              Working...