Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Portable Directory Meanings in Java SE

Thread Tools

Portable Directory Meanings in Java SE

Stefan Ram
Posts: n/a
I would like to collect some opinions and information about
the association between meanings of directory paths (i.e.,
what are the directories intended to be used for?) and Java SE
expressions for directory paths.

This is intended to answer questions like: Which directory
might be suggested to the user as a default for certain
operations, like storing a document file that was just created
and edited by the user?

The answer to such a question should be a Java SE expression
that gives an appropriate path under all possible environments
(like, for example, Windows or Linux).

So far, I have collected some Java expressions that can be
printed with the program below.

I would appreciate any comments about what others think that
each of those paths could or should be used for by a Java
application, even if someone only comments one or two paths,
but not all of them.

I also would like to know what this program prints on other
systems (especially on a Linux System, but also different
variants of Windows), but feel free to remove parts of the
output to protect privacy or security.

Of course, I also like to learn about other expressions that
might evaluate to other directory paths with a certain meaning.

A possible output of the program might look like: =
Windows 2000

os.version =

java.home =
C:\Program Files\JAVA\JRE1.7.0

user.home =

user.dir =
C:\dvl =

fileSystemView.getDefaultDirectory() =

fileSystemView.getHomeDirectory() =

getCodeSource().getLocation() =

class Main
public static void print( final java.lang.String string )
{ java.lang.System.out.println( string + " =" );
java.lang.System.out.println( System.getProperty( string ));
java.lang.System.out.println(); }

public static void print( final file )
{ java.lang.System.out.println( file.getAbsolutePath() );
java.lang.System.out.println( file.getCanonicalPath() );
java.lang.System.out.println(); }

public static void main( final java.lang.String[] args )
throws java.lang.Exception
print( "" );
print( "os.version" );

print( "java.home" );
print( "user.home" );
print( "user.dir" );
print( "" );

final javax.swing.filechooser.FileSystemView fileSystemView =
javax.swing.filechooser.FileSystemView.getFileSyst emView();

java.lang.System.out.println( "fileSystemView.getDefaultDirectory() =" );
print( fileSystemView.getDefaultDirectory() );

java.lang.System.out.println( "fileSystemView.getHomeDirectory() =" );
print( fileSystemView.getHomeDirectory() );

java.lang.System.out.println( "getCodeSource().getLocation() =" );
print( new Main.class.getProtectionDomain().getCodeSource().
getLocation().toURI() )); }}

Reply With Quote
Martin Gregorie
Posts: n/a
On Mon, 14 Jul 2008 11:13:35 +0000, Stefan Ram wrote:

> I also would like to know what this program prints on other
> systems (especially on a Linux System, but also different
> variants of Windows), but feel free to remove parts of the
> output to protect privacy or security.

Here you go:

$ java Main =

os.version = # I'm running RedHat Fedora 8

java.home =
/home/java/jdk1.6.0_05/jre # with Sun JDK 1.6.05

user.home = # My login directory when I ran it

user.dir = # My current working directory at the time
/home/kiwi/compiler_tests/environ = # default for FC8

fileSystemView.getDefaultDirectory() = # $HOME (see below)

fileSystemView.getHomeDirectory() = # $HOME (set when user logged in)

getCodeSource().getLocation() = # As for user.dir

Linux, like all Unices, has a number of additional defaults at both user
and system level that we'd normally expect to be set for the particular

- $PATH is where the OS looks for executables. It is typically something


which are (respectively) where os essentials, programs installed as part
of the distro, and locally installed and/or written executables live.
'.' (the current dir) isn't on the search path by default but is
reasonably commonly added, together directories containing major
3rd party packages such as Oracle.

These defaults can be customised at both user and system level. The OS
has facilities to make this easier and to let customisations survive
OS reinstalls and upgrades.

If the user is privileged, e.g. root, they will also have
/sbin, /usr/sbin and possibly /usr/local/sbin in $PATH

This shouldn't normally concern a Java application but its mentioned for

- unlike Windows, you'd normally expect to find config files for
standard packages in /etc and for locally installed/written packages
in /usr/local/etc, possibly with user specific configurations in hidden
files in $HOME. A 'hidden' file's name starts with '.' and isn't shown
in a directory listing or a wild carded list unless explicitly asked
for. This gives a little protection against accidental deletion etc.

This does have implications for Java apps. You might reasonably expect a
configurable Java app to search (in order) the current directory,
$HOME, /usr/local/etc and /etc for its config file/properties file and
use the first it found. Alternatively, if progressively localised
customisations are are to be applied to a default config, it would be
reasonable to do the search in the opposite order, and apply all files
in the order they are found to build up a final configuration for the
current user.

I think the way /etc and its siblings is used is the major difference from
Windows and its not really portable to another OS, except by coding the
search into the app and using the property to determine which
search strategy should be used.

One other point: many *nix utilities use a config file format that's
compatible with a properties file. Comments start with #, individual
parameters are written as "name = value".


martin@ | Martin Gregorie
gregorie. |
org | Zappa fan & glider pilot

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Meanings lissy6098 Cisco 3 08-15-2005 12:23 PM
meanings of dialets or implementation of a programming language Matt C++ 3 09-12-2004 05:56 AM
Exif fields meanings Ariel Dolan Digital Photography 2 05-18-2004 12:33 PM
meanings lallous Computer Support 4 01-19-2004 05:06 PM
RE: [OT] sentances with two meanings Harvey Thomas Python 45 07-23-2003 03:49 PM