Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

System.getProperty();

 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does this statement mean (see below)?
System.getProperty("java.io.tmpdir", "tmp");
I have checked the Java API:

getProperty(String key, String def)
Gets the system property indicated by the specified key.

Following the definition, "java.io.tmpdir" is a key. And "tmp" is the system property. However, tmpdir is not a class in the java.io package, and "tmp" looks an arbitrary String to me. How does "tmp" become a system property?
I know "tmp" is a String. And java.io is a package.
 
Jeff Langr
author
Ranch Hand
Posts: 799
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the Java API documentation for the System method getProperties, for a complete list of pre-defined properties. You'll find java.io.tmpdir in there. The second parameter to getProperty, "tmp", is the default value that you can provide if there happens to be no entry for java.io.tmp.
Note that you can create a "system" property by either adding to the map, or by specifying as a java command line option.
_Jeff_
[ February 05, 2004: Message edited by: Jeff Langr ]
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following the definition, "java.io.tmpdir" is a key. And "tmp" is the system property. However, tmpdir is not a class in the java.io package, and "tmp" looks an arbitrary String to me. How does "tmp" become a system property?
I know "tmp" is a String. And java.io is a package

"java.io.tmpdir" has nothing to do with the java.io package, nor with any class. It's just a key used in a Map data structure.
The "tmp" value likely meant something to the creator of this example. It may have been used as the name of a directory. According to the System class documentation, "tmp" would become the value of a system property when the line of code System.getProperty("java.io.tmpdir", "tmp"); runs and if "java.io.tmpdir" didn't already have a value - i.e. "tmp" would be used as a default value if one weren't already assigned to the specified key.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic