Java on the desktop: Which paths to use?

Discussion in 'Java' started by Stefan Ram, Jul 30, 2008.

  1. Stefan Ram

    Stefan Ram Guest

    Applications (like a word-processor) sometimes need to store
    or access files. To help users with little computer
    experience, there should be safe defaults for the paths,
    because not all users can find the best paths themselve.

    One can not assume that a Java application is running under a
    type of UNIX/Linux or Windows, so one only is allowed to rely
    on the standard methods and classes of Java SE, not to use
    code for specific host operating systems (at least, assume
    this for this question).

    How is the path to store the following type of files determined
    within such a Java applicataion?

    - User documents (the user can choose any path, but the
    application should suggest a reasonable default)

    - read-only data (The word-processor might use a file with data
    for a spell-checker that is not user specific)

    - User specific program configuration (like the background
    color of program's main window or user-specific extensions
    for the spell-checker)

    - log files (The word-processor keeps records of who edited which
    document at which time), this might be inspected by the user

    - debug log files (The word processor writes reports about
    abnormal program endings to a log file that is not intended
    to be read by users, but can be send to the manufacturer of
    the program as a bug report)

    - backup files (The word-processor keeps some old versions of a
    document, so the user can restore them later)

    - databases (The words processor supports sending form letters
    and can be used to maintain a database of customers, which
    eventually is stored in a file)

    - (meta) user specific settings for all of the above:
    The user can overwrite the defaults for all of the
    above paths, and these overwrite settings needs to be stored
    somewhere, too.

    ~~

    A footnote to anticipate answers involving »user.home«:

    The documentation says this:

    »This set of system properties always includes values for
    the following key: [...]

    user.home User's home directory
    user.dir User's current working directory«

    http://download.java.net/jdk7/docs/api/java/lang/System.html

    »java.lang.System.getProperty( "user.home" )« might sound
    good, but gives »C:\WINDOWS« on Windows 9x, which might not be
    the best place for user documents.

    It is not only broken on Windows 9x, but also on Windows NT:

    »We made a conscious decision to change the definition of
    the "user.home" property on Win32; see 4100238 for more
    info. This is not a bug.«

    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4162112

    (If Sun Microsystems, Inc. is free to make such a decision,
    but why don't they document it at the appropriate place, that is, in
    http://download.java.net/jdk7/docs/api/java/lang/System.html?)

    It also is broken on Vista:

    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6519127

    And also Microsoft®'s VM does it wrong:

    http://support.microsoft.com/kb/221206

    So we know now that there is a conspiracy among JVM producers
    to make »java.lang.System.getProperty( "user.home" )« unusable.
    (When it can not be used on Windows, it can not be used in a
    portable desktop Java program generally, because this should run
    under /all/ supported platforms.)

    The question still is, what to use instead.

    I already had posted my idea for an answer recently myself,
    but would not like to mention this now, so that I can get
    your unbiased opinion about this.
    Stefan Ram, Jul 30, 2008
    #1
    1. Advertising

  2. Stefan Ram

    Stefan Ram Guest

    Stefan Ram, Jul 30, 2008
    #2
    1. Advertising

  3. Stefan Ram wrote:
    > Applications (like a word-processor) sometimes need to store
    > or access files. To help users with little computer
    > experience, there should be safe defaults for the paths,
    > because not all users can find the best paths themselve.
    >
    > One can not assume that a Java application is running under a
    > type of UNIX/Linux or Windows, so one only is allowed to rely
    > on the standard methods and classes of Java SE, not to use
    > code for specific host operating systems (at least, assume
    > this for this question).
    >
    > How is the path to store the following type of files determined
    > within such a Java applicataion?
    >
    > - User documents (the user can choose any path, but the
    > application should suggest a reasonable default)


    Unfortunately, this one is a problem, but there's one way that I'll get to.

    > - read-only data (The word-processor might use a file with data
    > for a spell-checker that is not user specific)


    If it's truly read-only, put it in the JAR.

    > - User specific program configuration (like the background
    > color of program's main window or user-specific extensions
    > for the spell-checker)


    Use java.util.prefs. That's what it's for.

    > - log files (The word-processor keeps records of who edited which
    > document at which time), this might be inspected by the user


    Put a pointer in the preferences. See below for the initial value.

    > - debug log files (The word processor writes reports about
    > abnormal program endings to a log file that is not intended
    > to be read by users, but can be send to the manufacturer of
    > the program as a bug report)


    Put a pointer in the preferences. See below for the initial value.

    > - backup files (The word-processor keeps some old versions of a
    > document, so the user can restore them later)


    Put a pointer in the preferences. See below for the initial value.

    > - databases (The words processor supports sending form letters
    > and can be used to maintain a database of customers, which
    > eventually is stored in a file)


    Use SQL and let the database software worry about it. If you can't do
    that, assume it's in the same directory as the file until the user
    changes it.

    > - (meta) user specific settings for all of the above:
    > The user can overwrite the defaults for all of the
    > above paths, and these overwrite settings needs to be stored
    > somewhere, too.


    With the other preferences.

    >
    > ~~
    >
    > A footnote to anticipate answers involving »user.home«:
    >
    > The documentation says this:
    >
    > »This set of system properties always includes values for
    > the following key: [...]
    >
    > user.home User's home directory
    > user.dir User's current working directory«
    >
    > http://download.java.net/jdk7/docs/api/java/lang/System.html
    >
    > »java.lang.System.getProperty( "user.home" )« might sound
    > good, but gives »C:\WINDOWS« on Windows 9x, which might not be
    > the best place for user documents.
    >
    > It is not only broken on Windows 9x, but also on Windows NT:
    >
    > »We made a conscious decision to change the definition of
    > the "user.home" property on Win32; see 4100238 for more
    > info. This is not a bug.«
    >
    > http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4162112
    >
    > (If Sun Microsystems, Inc. is free to make such a decision,
    > but why don't they document it at the appropriate place, that is, in
    > http://download.java.net/jdk7/docs/api/java/lang/System.html?)
    >
    > It also is broken on Vista:
    >
    > http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6519127
    >
    > And also Microsoft®'s VM does it wrong:
    >
    > http://support.microsoft.com/kb/221206
    >
    > So we know now that there is a conspiracy among JVM producers
    > to make »java.lang.System.getProperty( "user.home" )« unusable.
    > (When it can not be used on Windows, it can not be used in a
    > portable desktop Java program generally, because this should run
    > under /all/ supported platforms.)
    >
    > The question still is, what to use instead.
    >
    > I already had posted my idea for an answer recently myself,
    > but would not like to mention this now, so that I can get
    > your unbiased opinion about this.


    The answer to all this? Don't try to make the downloadable application
    absolutely portable -- you still need an installer, after all, and
    either a system-appropriate GUI icon or a system-appropriate Java
    bootstrap, not to mention an optional included JRE. So, during the
    install, put the information somewhere (perhaps a Java properties file)
    where it A) doesn't get in the way -- in MacOS X, you would certainly
    want it to be in the Package -- and B) can be obtained, directly or
    indirectly, by ClassLoader.findResource.

    --
    John W. Kennedy
    "There are those who argue that everything breaks even in this old
    dump of a world of ours. I suppose these ginks who argue that way hold
    that because the rich man gets ice in the summer and the poor man gets
    it in the winter things are breaking even for both. Maybe so, but I'll
    swear I can't see it that way."
    -- The last words of Bat Masterson
    John W Kennedy, Jul 30, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TC
    Replies:
    4
    Views:
    645
    JohnnyAppleseed
    Feb 7, 2005
  2. Noah
    Replies:
    5
    Views:
    769
  3. Helmut Jarausch

    ctypes CDLL - which paths are searched?

    Helmut Jarausch, Jan 21, 2008, in forum: Python
    Replies:
    4
    Views:
    1,362
    Thomas Heller
    Jan 22, 2008
  4. Ohad Lutzky

    Paths, gentleman, paths

    Ohad Lutzky, Nov 6, 2006, in forum: Ruby
    Replies:
    2
    Views:
    185
    David Vallner
    Nov 7, 2006
  5. iMath
    Replies:
    7
    Views:
    1,163
    iMath
    Nov 10, 2013
Loading...

Share This Page