Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Help with static method issue

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Marshal
Posts: 74059
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch
 
Campbell Ritchie
Marshal
Posts: 74059
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic