-1

I'm trying to define something in my code, but there isn't any define in Java.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131

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 (i.e., can not be changed).

So something like:

final int NUMBER_OF_HOURS_IN_A_DAY = 24;

will create a "constant" integer with a value of 24.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tularis
  • 1,506
  • 1
  • 8
  • 17
1

Use:

final String key = Value;

For example,

final String MAX_VALUE = "9000";

And it's better to add static too:

static final String MAX_VALUE = "9000";
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
MSaudi
  • 4,442
  • 2
  • 40
  • 65