Detect first time user in java app
Asked Answered
I

3

5

I want my java desktop application to know if the user is running it for the first time on that pc. Since the jar-file might be shared between users i don't want to write to a file inside the jar-file. There are obviously a lot of ways to do this but what would you recommend? (It has to be cross-platform). thanks

Iowa answered 29/11, 2011 at 18:43 Comment(0)
C
4

Try to use Preferences and its systemRoot() or userRoot() methods to obtain system-wide or user-specific preferences.

Currish answered 29/11, 2011 at 18:59 Comment(4)
This seems really neat, but maybe a bit dangerous? the system/user preferences can easily get cleared by another application or manually by the user, right? (perhaps that is very uncommon though..?)Iowa
As with any other solution preferences can be changed by the user/application that have permissions to do it. If you have to prevent conflicts between preferences of different applications, consider using systemNodeForPackage(Class) or userNodeForPackage(Class) methods.Currish
Here is also some information about where the preferences are typically stored in different systems. And here is a rather old but useful technical article about Preferences.Currish
Thanks a lot for these answers, didn't know about Preferences before and it seems great.Iowa
V
7

I would recommend using the users home directory where you can place a user specific settings file. This will allow you to detect first time users as well as remember any preferences they may choose.

System.getProperty("user.home"); // returns the home directory cross platform
Virtuosic answered 29/11, 2011 at 18:48 Comment(1)
This is an effective solution off course, maybe not very beautiful in this case though, because there are no user specific settings needed. Sure the app could place an empty file in the home directory (if the file exists it's not a first time user), but the user might get annoyed with such a file in the home folder and delete it.Iowa
C
4

Try to use Preferences and its systemRoot() or userRoot() methods to obtain system-wide or user-specific preferences.

Currish answered 29/11, 2011 at 18:59 Comment(4)
This seems really neat, but maybe a bit dangerous? the system/user preferences can easily get cleared by another application or manually by the user, right? (perhaps that is very uncommon though..?)Iowa
As with any other solution preferences can be changed by the user/application that have permissions to do it. If you have to prevent conflicts between preferences of different applications, consider using systemNodeForPackage(Class) or userNodeForPackage(Class) methods.Currish
Here is also some information about where the preferences are typically stored in different systems. And here is a rather old but useful technical article about Preferences.Currish
Thanks a lot for these answers, didn't know about Preferences before and it seems great.Iowa
S
0

Every OS has some specific directories where the user data is stored (/home, C:\Users, C:\Documents and settings). This value is usually available in the JVM with the "user.home" System property.

Store there some file to store your user configuration. Of course, each OS has its way of doing that ("Application Data" folder, folder with a name that begins with a dot), you should be sure that you comply with it.

Scevour answered 29/11, 2011 at 18:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.