I guess my C++ training is still way too embedded, because I'm having trouble with the concept of always needing an ojbect upon which to invoke a method. Basically, I'm writing a section of a program that will read a config file and set its options. The C++ programmer in me wants to, once the file is loaded, loop through line by line, each time calling a setConfig(String value, int place) function, which would be just below the end of the function my loop is in. Sadly, I've found, I can't just say this.setConfig(blah, blah). It wouldn't make a lot of sense to instantiate an object of the class these functions are found in...or at least so I think. Putting my setConfig function in its own class and instantiating an object of that type is the only thing that seems logical...but to me, it also seems to make for difficult-to-manage code, while sapping system resources through constant object instantiation. What would be the best way to go about doing this -- best meaning easiest to manage and taking up the least system resources -- that you can think of? Alex Kirk
I guess my C++ training is still way too embedded, because I'm having trouble with the concept of always needing an ojbect upon which to invoke a method.
Actually, you don't always need an object...you always need a class. This is how you are able to call static methods without having an instance of the class, e.g.:
Sadly, I've found, I can't just say this.setConfig(blah, blah).
Have you tried just calling setConfig( blah, blah )?
Have you looked at the Properties class in java.util? Jason
Joined: Aug 13, 2001
Actually, I'd not just tried setConfig(blah, blah), as I'd had something akin to it cause an error for me yesterday. To my chagrin, though, it works. I took a quick look at the API documentation of java.util.properties, and I'm not quite sure how it would work (I have a lot of trouble extracting useful information from the API). Could you point me to any examples of its usage? Alex
I agree that the API is not a great resource for those who are still having fundamental questions about how to program in Java. I certainly found it very hard to use. I kept complaining "this sure isn't like MSDN".
On the other hand, once you are chugging along in Java, the API is a wonderful reference.
Joined: Aug 02, 2001
Read about Properties here. If you're uncomfortable with properties, just stick with what you're doing. I'm still getting used to the API. I'm getting familiar with exploiting classes that I find...my problem is discovering the class I'd like to use exists. My approach now is to assume that any really useful class has already been coded; all I have to do is look for it. Jason