![]() |
startup code
Is there any way to add code to a class that will get executed whenever the program starts up?
(i.e. without explicitly calling into it) |
Re: startup code
On Tue, 28 Aug 2012 11:48:41 -0700 (PDT), bob smith
<bob@coolfone.comze.com> wrote, quoted or indirectly quoted someone who said : >Is there any way to add code to a class that will get executed whenever the program starts up? You can put in it the main method or in a static init block. See http://mindprod.com/jgloss/static.html -- Roedy Green Canadian Mind Products http://mindprod.com A new scientific truth does not triumph by convincing its opponents and making them see the light, but rather because its opponents eventually die, and a new generation grows up that is familiar with it. ~ Max Planck 1858-04-23 1947-10-04 |
Re: startup code
On 08/28/2012 02:48 PM, bob smith wrote:
> Is there any way to add code to a class that will get executed whenever the program starts up? > > (i.e. without explicitly calling into it) <http://www.nofluffjuststuff.com/blog/vladimir_vivien/2011/10/loader_launcher__a_pattern_to_bootstrap_java_appli cations> |
Re: startup code
On Tuesday, August 28, 2012 11:53:34 AM UTC-7, Roedy Green wrote:
> bob smith wrote, quoted or indirectly quoted someone who said : >>Is there any way to add code to a class that will get executed whenever the program starts up? > > You can put in it the main method or in a static init block. > See http://mindprod.com/jgloss/static.html The main method technique will happen whenever the program starts up. The class init block won't run until the class is initialized (not necessarily when it's loaded). This can be quite a while after the program starts "up". It can even be quite a while after the class is loaded. -- Lew |
Re: startup code
On 28.08.2012 23:00, Lew wrote:
> On Tuesday, August 28, 2012 11:53:34 AM UTC-7, Roedy Green wrote: >> bob smith wrote, quoted or indirectly quoted someone who said : >>> Is there any way to add code to a class that will get executed whenever the program starts up? >> >> You can put in it the main method or in a static init block. >> See http://mindprod.com/jgloss/static.html > > The main method technique will happen whenever the program starts up. > > The class init block won't run until the class is initialized (not necessarily > when it's loaded). This can be quite a while after the program starts "up". > It can even be quite a while after the class is loaded. Still it is often early enough, i.e. before instances of the very class get to do their work. Bob, what are you trying to accomplish? Or is this more like a homework question? Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ |
Re: startup code
Robert Klemme wrote:
> Lew wrote: > ... >> The class init block won't run until the class is initialized (not necessarily >> when it's loaded). This can be quite a while after the program starts "up". >> It can even be quite a while after the class is loaded. > > Still it is often early enough, i.e. before instances of the very class > get to do their work. "Early enough" depends on whether the OP wants what they literally asked for, something that happens at program start, or the more relaxed requirement of before the class is otherwise used. > Bob, what are you trying to accomplish? Or is this more like a homework > question? Bob, this is a key question Robert asks. -- Lew |
Re: startup code
On 8/28/2012 2:48 PM, bob smith wrote:
> Is there any way to add code to a class that will get executed whenever the program starts up? > > (i.e. without explicitly calling into it) Create a new class with a main that: - does whatever you want done - calls the original main and run that. Arne |
Re: startup code
On 8/28/2012 2:53 PM, Roedy Green wrote:
> On Tue, 28 Aug 2012 11:48:41 -0700 (PDT), bob smith > <bob@coolfone.comze.com> wrote, quoted or indirectly quoted someone > who said : >> Is there any way to add code to a class that will get executed whenever the program starts up? > > You can put in it the main method or in a static init block. That does not run code when the program startup. It will run the code when the class is first loaded. Which may not even happen. Arne |
Re: startup code
Arne Vajhøj wrote:
> Roedy Green wrote: >> bob smith wrote, quoted or indirectly quoted someone who said : >>> Is there any way to add code to a class that will get executed wheneverthe program starts up? > >> You can put in it the main method or in a static init block. > > That does not run code when the program startup. > It will run the code when the class is first loaded. No. It will run the code when the class is initialized, which might be considerably after the class is first loaded. > Which may not even happen. Same with initialization - a class might be loaded and never initialized. -- Lew |
Re: startup code
On Tue, 28 Aug 2012 14:00:47 -0700 (PDT), Lew <lewbloch@gmail.com>
wrote, quoted or indirectly quoted someone who said : > >The class init block won't run until the class is initialized I think he means by "the program" the class name invoked on the command line. In that case the static init blocks in that class will execute even before the main method. Under what conditions does a class load without running the static init blocks? -- Roedy Green Canadian Mind Products http://mindprod.com A new scientific truth does not triumph by convincing its opponents and making them see the light, but rather because its opponents eventually die, and a new generation grows up that is familiar with it. ~ Max Planck 1858-04-23 1947-10-04 |
| All times are GMT. The time now is 05:13 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.