473,226 Members | 1,305 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

When are classes loaded by other classes?

If I have a class like this:

public class Tester {

ObjectType1 ot1;
ObjectType2 ot2;
ObjectType3 ot3;

public void main(String args) {
//Preliminary checking, resulting in bRun being
//true or false -- true means we continue, false, we quit:
if (bRun) {
Tester t = new Tester();
t.doStuff();
}
System.exit(0);
}

public Tester() {
//do stuff to create an instance of this class
ot1= new ObjectType1;
ot2= new ObjectType2;
ot3= new ObjectType3;
return;
}

public void do Stuff() {
//main processing routines to do stuff in this object
return;
}
}

Does this class load the files for the classes ObjectType1, 2, and 3 when
this class is first called from the command line, or does it wait and load
those classes from disk when the main() method calls Tester() to create an
object? In other words, if bRun is false, and the main() method never
creates an object of type Tester, are the other classes ever loaded?

I'm concerned about speed and trying to create a small class to determine
whether another class, that uses a good number of objects (like
ObjectType1, 2, & 3 are used above) needs to run. I won't have to create
an extra class if I can keep a long list of objects from loading until the
main() method actually creates the object.

Thanks!

Hal
Jul 17 '05 #1
2 1978
Hal Vaughan <ha*@thresholddigital.com> wrote:
Does this class load the files for the classes ObjectType1, 2, and 3 when
this class is first called from the command line, or does it wait and load
those classes from disk when the main() method calls Tester() to create an
object?
See section 12.4.1 of the Java 2 Language Specification
http://java.sun.com/docs/books/jls/s...doc.html#57946

The executive summary is that Java requires "lazy loading": a class
must never be loaded until the JVM absolutely needs it.
I'm concerned about speed


Class-loading is a one-time thing; a class is only loaded once per JVM
execution (unless you fool around with classloaders). It's pretty hard
to get any leverage out of optimizing a one-time thing.

===

Now for my occasional reminder to everyone that comp.lang.java is not
an "official" newsgroup, and that you'll probably get a lot better
response using one of the worldwide Java newsgroups.

comp.lang.java was retired in 1996, replaced by a number of more
specific newsgroups. Most people don't see postings on comp.lang.java,
because only a few news servers still carry it. Google Groups carries
it for its historical value, and a few ISPs (mainly U.S.
cable-Internet providers) seem to carry it out of ignorance :-)

The current worldwide Java newsgroups are:

comp.lang.java.3d 3D Graphics API's for the Java language
comp.lang.java.advocacy Support for and criticism of the Java System
comp.lang.java.announce Announcements re the Java System (Moderated)
comp.lang.java.beans Java software components (JavaBeans)
comp.lang.java.corba Topics relating to Java and CORBA
comp.lang.java.databases Databases, java.sql, JDBC, ODBC
comp.lang.java.gui GUI toolkits and windowing: AWT, IFC etc
comp.lang.java.help Set-up problems, catch-all first aid
comp.lang.java.machine JVM, native methods, hardware
comp.lang.java.programmer Programming in the Java language
comp.lang.java.security Security issues raised by Java
comp.lang.java.softwaretools IDEs, browsers, compilers, other tools.
Jul 17 '05 #2
Doug Pardee wrote:
Hal Vaughan <ha*@thresholddigital.com> wrote:
Does this class load the files for the classes ObjectType1, 2, and 3 when
this class is first called from the command line, or does it wait and
load those classes from disk when the main() method calls Tester() to
create an object?
See section 12.4.1 of the Java 2 Language Specification

http://java.sun.com/docs/books/jls/s...doc.html#57946
The executive summary is that Java requires "lazy loading": a class
must never be loaded until the JVM absolutely needs it.


Actually, this helps a LOT. I want to be able to have a class run, check
ONE setting in a one line file and, if it's true, then run. If it's false,
don't run. If it runs, it'll start an entire system, with something like
20-30 classes. I wanted to be able to check the one setting and exit
quickly if the system was not supposed to run. If the JVM were to load all
the classes as soon as it was aware of them, then I'd have to do something
different to make a small class that would perform a "fast check".

Thanks!

Hal
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Craig Ringer | last post by:
Hi folks I'm a bit of a newbie here, though I've tried to appropriately research this issue before posting. I've found a lot of questions, a few answers that don't really answer quite what I'm...
6
by: Outshined | last post by:
I have a class library where just about every class uses its static initializer to register with a central registry object in the same assembly. I am hoping for some sort of Assembly.Load event...
45
by: Steven T. Hatton | last post by:
This is a purely *hypothetical* question. That means, it's /pretend/, CP. ;-) If you were forced at gunpoint to put all your code in classes, rather than in namespace scope (obviously classes...
3
by: toki | last post by:
public class Form1 : System.Windows.Forms.Form { MyClass myclass; public Form1() { myclass = new MyClass(); } }
5
by: John Hardin | last post by:
All: Is it possible at runtime to determine the names of all classes derived from a given class? -- John Hardin KA7OHZ <johnh@aproposretail.com> Internal Systems...
6
by: sylcheung | last post by:
Hi, How can I be notified when the document load is complet in JavaScript? I am referring to the whold document load is complete, mean all images/external files/frame/iframes have been loaded. ...
3
by: ImOk | last post by:
In Smalltalk I can get the list of the classes, methods and global variables by querrying a global dictionary. In addition you can get the arguments. I know in PHP one can get the list of...
2
by: wzhao2000 | last post by:
Back in COM time, it's possible to use #import statement in cpp to load COM object type info and use it at coding time. When the application is started, the underlying COM DLL will not be loaded...
5
by: | last post by:
I am having problems with casting or converting a class to to an interface from which it derives. I'm certain that it's due to how it's being loaded, but I'm not sure how to get past the problem....
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.