aspose file tools*
The moose likes Java in General and the fly likes Simple doubt for you guys, about static class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Simple doubt for you guys, about static class" Watch "Simple doubt for you guys, about static class" New topic
Author

Simple doubt for you guys, about static class

Vinicius Souza
Ranch Hand

Joined: May 18, 2011
Posts: 45

Hi guys, I'm creating a version of my microinterpreter in java and I need to know about some few things. The program in java is working nicely but because my lack of knowledge in java properly, I added the tokens on my tokenizer manually. I want to create a table where I can add new tokens easly without need to add it manually.
So, I created a util class where I putted??? some utility functions and where I putted?? my token table. See below:

See, so, how can I put this in a static table? I was thinking in Hashtable class but how can I add information to it statically? I dont want to instanciate the ScriptCommon class, I tryed this:

But this code doesnt compile...
Any sugestions ? Remember, I want it statically... a vector???
Thanks in advance!


Java is the best (I love C too) heehhh
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2286
    
  49
You would probably be better off putting them in a properties file and then loading the properties file at runtime into a Properties Object. A Properties object extends Hashtable so you would be able to access the key values pairs in the same way you do now but the key value pairs would be in a text file so you can add new values without having to recompile your code.

If you really want to do it in a static class then use a static initializer to load the values into the Hashtable which BTW should really be a HashMap.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3646
    
  16

Why does it have to be static? Why are you hardcoding values? Why are you using legacy classes?

Just pass a Map<String, String> to your interpreter constructor. No static data, no legacy classes and you can read key-value pairs from a file to fill the map.
Vinicius Souza
Ranch Hand

Joined: May 18, 2011
Posts: 45

Thanks guys, I will try this Properties object and I got my code working using a static function to initialize my static Hashtable.
Flws!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simple doubt for you guys, about static class