This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Applets and the fly likes static properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "static properties file" Watch "static properties file" New topic
Author

static properties file

Robert Kennedy
Ranch Hand

Joined: Jun 27, 2008
Posts: 63
In my class I have declare a properties file with static:
private static Properties resource = new Properties();

I instantiate this class when my applet is loaded (init method) and in turn this class loads the properties file.

So far is this correct?

Now I wish to call myResourceClass.getProperty(key) from other classes in the applet.

If I simply import the ResourceClass can i resuse it without having to instantiate the class?

Is this correct?

Thanks
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
You've declared the Properties field as private. That will prevent other classes from accessing it. You could provide a public method to access it that other classes could call. Or you could change it to public.
To access a static field in a class you code the classname followed by the field name: YourClass.resource would allow another class to get to the resource field (if its not private).

Not sure what you mean by "import the ResourceClass". Is that the class with the field resource? The import statement in a source program is there to help the compiler find a class definition when the file is being compiled. That's not related to instantiation which takes place at execution time.
Depending on the relationship between your classes, you may need the import statement to compile them when you use a reference to a static field as above.
After you compile the code, the one instantiation that sets the static field will be all that's needed. Other classes will be able to use it.
Robert Kennedy
Ranch Hand

Joined: Jun 27, 2008
Posts: 63
Thank you. Your reply clears it up.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static properties file
 
Similar Threads
Running EJB Client
OO Best Practices - Properties
implement singleton pattern on reflected class
Calling a static method of another class from an applet
AccessControlException