1

Is it OK to use xxx.equals(System.getProperty(key)) as a condition? Or Am I supposed to use the properties for some other purposes?

I have been reading these;

http://download.oracle.com/javase/tutorial/essential/environment/sysprop.html

http://download.oracle.com/javase/6/docs/api/java/lang/System.html

however, I'm a little confused on its usage. Some more links or some code samples would be very helpful.

Thank you...

  • 2
    I don't see why not...it's entirely up to you what you want to do with the retrieved value, and performing a simple comparison is perfectly legit. – mre Jul 11 '11 at 17:03
  • 1
    you can use them for whatever purpose they are useful to your application. It IS OK to use them in conditional statements. (just make sure you are either handling nulls or are using the overloaded getProperty(key, default)) – Amol Katdare Jul 11 '11 at 17:05
  • @amol the form in the OP is already null safe. – Matt Ball Jul 11 '11 at 17:09
  • @Mehmet Yesin, if you have found your answer accept the one that helped you the most so others can learn – RMT Jul 12 '11 at 14:10

4 Answers4

3

Yes it's ok you use them. (example: os.name to figure out what operation system)

RMT
  • 7,040
  • 4
  • 25
  • 37
2

Sure it's OK. Whether it's true will obviously depend on the value in xxx though.

Mark Peters
  • 80,126
  • 17
  • 159
  • 190
2

I think that when you really need you can use it :)

zacheusz
  • 8,750
  • 3
  • 36
  • 60
2

As everybody said yes you can do this.

Regarding:

however, I'm a little confused on its usage. Some more links or some code samples would be very helpful.

try this link, you might find it helpful.

Asad Rasheed
  • 518
  • 5
  • 13