-1

I'm trying to define something in my code, but there is no define in Java.

Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126

2 Answers2

1

JAVA as such does not exactly "have" constants (which is what you define using the define() function in PHP). Rather, you can make the variable final. This way, it behaves like a constant value (ie. can not be changed).

So something like:

final int NUMBER_OF_HOURS_IN_A_DAY = 24;

will create a "constant" int with a value of 24

Tularis
  • 1,505
  • 1
  • 8
  • 17
1
final String key = Value;

e.g.

final String MAX_VALUE = "9000";

and it's better to add static too

static final String MAX_VALUE = "9000";
MSaudi
  • 4,012
  • 2
  • 36
  • 61