aspose file tools*
The moose likes Beginning Java and the fly likes System.getProperty(); Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "System.getProperty();" Watch "System.getProperty();" New topic
Author

System.getProperty();

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
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

Joined: May 14, 2003
Posts: 762
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 ]

Books: Agile Java, Modern C++ Programming with TDD, Essential Java Style, Agile in a Flash. Contributor, Clean Code.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
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.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: System.getProperty();