*
The moose likes Java in General and the fly likes Help with static method issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Help with static method issue" Watch "Help with static method issue" New topic
Author

Help with static method issue

Mike Kremer
Greenhorn

Joined: Mar 18, 2009
Posts: 2
Hi,

I am seeing something strange and I don't see how or why it could happen. If someone can help 'enlighten' me, it would be very appreciated.

I have an abstract class, Product, that contains a static public void method, createPrototypes(). I am calling Product.createPrototypes() during my application bootup but the code in the method is not reached or processed. The application just hangs up when ran without any errors. Do to this app being ran on an old device I am using jdk1.1.8.

***
Scenario 1: If I run the code below, I get the console output:
>Before method call.

I do not get any errors or any other output to the console; the app just hangs up there.
***
Scenario 2: If I run the code and uncomment the section that I have commented below, it runs fine.....why???
>Before method call.
>In Product.createPrototypes()
>After method call.
***


Thanks in advance!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38467
    
  23
Welcome to JavaRanch
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38467
    
  23
I copied and pasted your code without any changes and got this output
[Campbell@localhost java]$ java DeviceSession
Before method call.
In Product.createPrototypes()
After method call.
I can't find anything wrong with it, apart from trying to call a non-static method from main().
Mike Kremer
Greenhorn

Joined: Mar 18, 2009
Posts: 2
Did you compile and run the code with jdk 1.1.8? I get the correct results when compiling and running with jdk 1.3.1 but I have to use 1.1.8 because that is the jre that is on the device that I'm programming on.

If you did use jkd 1.18, are there compiler settings or something that can cause static methods to not be loaded or linked until an instance of the class that contains the method is created. That is what seems to be happening to me. The static method is not 'present' during runtime until an instance of the class is created.
 
 
subject: Help with static method issue