Re: [OT] a java question

2005-01-28 Thread Eddie Bush
Smooth, Frank :-) -- Eddie Bush - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: [OT] a java question

2005-01-28 Thread fzlists
The only thing with that is if you might need to change those constants while the application is running, you won't be able to this way. Of course, you could argue they aren't constants then, and i'd tend to agree! :) For instance, in one application I wrote, I read in an application configura

Re: [OT] a java question

2005-01-28 Thread Eddie Bush
I'll probably get called insane ... :-) Generally, when I have a class that contains constants, I do make them final, but I set their value in a static initializer. Inside of this static initializer, I will load the values from a properties file and then assign them. This way, my values are easi

RE: [OT] a java question

2005-01-27 Thread Sunil Sahu
Title: RE: [OT] a java question No Problem ashish, you can do one thing, don't initialize it, only declare the variable as final and assign the value at run time but you can assign Only one time means subsequent attempts to assign a value to a Final variable result in a compiler

Re: [OT] a java question

2005-01-26 Thread Rick Reumann
Erik Weber wrote the following on 1/26/2005 2:44 PM: It is useful to note that it is theoretically possible for two competing Threads to enter the setData method and get past the "if (! isInitialized)" statement before one of them changes the value to true, causing possible data corruption. This

Re: [OT] a java question

2005-01-26 Thread jlopez
Well, i put the main for the example... but you need the class Perro before you get the constant value i Hope some like this. Perro.setLoadMethod(theInitval); then su can obtain Perro.CONSTANT.uni.. Cordial Saludo John J López > Hi > how will this class work if there is no public sta

Re: [OT] a java question

2005-01-26 Thread PA
On Jan 26, 2005, at 21:34, Ashish Kulkarni wrote: how will this class work if there is no public static void main method and have to be initialized by some other class Hmmm... syntax error... question does not compute... What are you trying to do? Your original question was about setting and acces

Re: [OT] a java question

2005-01-26 Thread Ashish Kulkarni
Hi how will this class work if there is no public static void main method and have to be initialized by some other class Ashish --- [EMAIL PROTECTED] wrote: > i don't not it this is a good practice. . Maybe it's > a bad practice > but.. but this work > and int this way you can mantain the cons

Re: [OT] a java question

2005-01-26 Thread jlopez
i don't not it this is a good practice. . Maybe it's a bad practice but.. but this work and int this way you can mantain the constants public static and final . the other problem is tha if you get the value of the constant before yo initialize you allways obtain a null value well sorry fo

Re: [OT] a java question

2005-01-26 Thread PA
On Jan 26, 2005, at 20:37, Erik Weber wrote: By the way, real nice site you have there (I'm assuming it is yours). Great design. The design came with the stock content management system I'm using: http://www.textpattern.com/ Which perhaps not accidentally looks very much like the one of its creat

Re: [OT] a java question

2005-01-26 Thread PA
On Jan 26, 2005, at 20:20, Cedric Levieux wrote: if (! isInitialzed) Shouldn't you throw one exception or two for good measure? Cheers -- PA http://alt.textdrive.com/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional c

Re: [OT] a java question

2005-01-26 Thread Erik Weber
ot; <[EMAIL PROTECTED]> To: "Struts Users Mailing List" Sent: Wednesday, January 26, 2005 8:15 PM Subject: Re: [OT] a java question so it will be some thing like this public MyClass { private static String data; public static String getData() { return data; } publ

Re: [OT] a java question

2005-01-26 Thread PA
On Jan 26, 2005, at 20:28, Ashish Kulkarni wrote: that is what i am going to do, Gotta do what you gotta do. But at least don't use any spurious boolean to keep track if a variable has or has not been set. After all, Java doesn't define 'null' for nothing. Cheers -- PA http://alt.textdrive.com/

Re: [OT] a java question

2005-01-26 Thread Erik Weber
Yeah, in "bootstrapping" I often run a static initializer right off the bat that loads bootstrap properties from the jar, then I set constants using private static getters that access the loaded properties underneath. Don't know where I picked that up (it's more useful in Swing), but it makes i

Re: [OT] a java question

2005-01-26 Thread Will Stranathan
Or, keep all your static shared junk in your initializer class, then make the mutator private, accessor public. w On Wed, 26 Jan 2005 11:29:53 -0800 (PST) [EMAIL PROTECTED] wrote: However, as another poster said, why not just set the value in a static initializer block, and only expose a getter

Re: [OT] a java question

2005-01-26 Thread fzlists
Are you saying that some other initialization class will call your setter to initialize it? And you only want that class to be able to call it? If so, there's no standard way to do it, but... you could pass in an instance of Class to the setter, and check that it's only your initializer class.

Re: [OT] a java question

2005-01-26 Thread PA
On Jan 26, 2005, at 20:16, Erik Weber wrote: There is more than one approach. Alternatively you can still use a final, but only assign a value to it upon initialization. No further change will be allowed after that. So many obscure ways to shot yourself in the foot :o) Cheers -- PA http://alt.te

Re: [OT] a java question

2005-01-26 Thread Ashish Kulkarni
"Struts Users Mailing List" > > Sent: Wednesday, January 26, 2005 8:15 PM > Subject: Re: [OT] a java question > > > > so it will be some thing like this > > > > public MyClass > > { > > private static String data; >

Re: [OT] a java question

2005-01-26 Thread Cedric Levieux
Message - From: "Ashish Kulkarni" <[EMAIL PROTECTED]> To: "Struts Users Mailing List" Sent: Wednesday, January 26, 2005 8:15 PM Subject: Re: [OT] a java question > so it will be some thing like this > > public MyClass > { > private static Stri

Re: [OT] a java question

2005-01-26 Thread PA
On Jan 26, 2005, at 20:15, Ashish Kulkarni wrote: public static setData(String input) By making it private perhaps? Alternatively, I would recommend some readings: http://java.sun.com/docs/books/tutorial/java/index.html Cheers -- PA http://alt.textdrive.com/ --

Re: [OT] a java question

2005-01-26 Thread Erik Weber
There is more than one approach. One is this: public static final SOME_STRING_VALUE = someStaticMethodThatLoadsValueFromPropertiesFile(); Another is to use a static getter rather than using a constant at all. Erik Ashish Kulkarni wrote: Hi If we need a variable which can be accessed from any clas

Re: [OT] a java question

2005-01-26 Thread Ashish Kulkarni
so it will be some thing like this public MyClass { private static String data; public static String getData() { return data; } public static setData(String input) { data = input; } } this will work, but how to make sure that setData is called only from initalization class, a

Re: [OT] a java question

2005-01-26 Thread fzlists
You want a private variable and a public static accessor/mutator pair: public class test { private static int var; public static void setVar(int i) { var = i; } public static int getVar() { return var; } } -- Frank W. Zammetti Founder and Chief Software Architect Omnytex Te

Re: [OT] a java question

2005-01-26 Thread PA
On Jan 26, 2005, at 20:08, Ashish Kulkarni wrote: how do i protect it from updated by any other class. Just don't. Use a static accessor method instead. Cheers -- PA http://alt.textdrive.com/ - To unsubscribe, e-mail: [EMAIL PROTEC

[OT] a java question

2005-01-26 Thread Ashish Kulkarni
Hi If we need a variable which can be accessed from any class, then we set this variable as static and access it as MyClass.Variable, this variable can be modified from any class if we dont set this variable as final like public static final String Variable = "ABC"; here is the problem, i cannot se