SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:What if you need to change them? If you put them in a class or interface you would need to recompile not only that class, but the entire application because the constants are probably inlined* wherever they are used. By putting them in property files (or any other form of configuration files, e.g. XML) you can modify the file and restart your application, and all code will use the new values.
This also allows non-programmers to modify them if needed.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Rob Spoor wrote:What if you need to change them? If you put them in a class or interface you would need to recompile not only that class, but the entire application because the constants are probably inlined* wherever they are used. By putting them in property files (or any other form of configuration files, e.g. XML) you can modify the file and restart your application, and all code will use the new values.
I totally agree if you're talking about values that really are part of a configuration, or that might change (which, in effect, means that they're not constants); but things like π or e or 'epoch date' do belong in the program.
I also worry a bit about "XML configuration madness" these days with all these distributed 'enterprise' containers around. Why should I have to write pages of finicky (and, it seems to me, largely undocumented) XML to do what I could do in half a dozen lines of properties? It seems we're headed towards a whole new subculture of "configurators" that operate in a world that doesn't have the same controls as a proper programming language.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:What if you need to change them? If you put them in a class or interface you would need to recompile not only that class, but the entire application because the constants are probably inlined* wherever they are used. By putting them in property files (or any other form of configuration files, e.g. XML) you can modify the file and restart your application, and all code will use the new values. This also allows non-programmers to modify them if needed.
RajivAwadhesh kumar wrote:Whats the meaning of " constants may be probably inlined" as said above..
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
And as Rob said, the area of a circle is now 2πr[campbell@... java]$ javap -c Circle
Compiled from "Circle.java"
public class Circle {
public Circle(int);
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: aload_0
5: iload_1
6: putfield #2 // Field radius:I
9: return
public double getArea();
Code:
0: ldc2_w #3 // double 6.283185307179586d
3: aload_0
4: getfield #2 // Field radius:I
7: i2d
8: dmul
9: dreturn
}
[campbell@... java]$
RajivAwadhesh kumar wrote:also in case of properties file also we need to restart the application in order to reflect the changes, so is it a lot better than
maintaining those changes in a java file?
Hey, check out my mega multi devastator cannon. It's wicked. It makes this tiny ad look weak:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|