54

We use the Java preferences in some of our apps and haven't really noticed this since the utility that makes the calls is fairly old and was written in Windows XP days. But it seems the Java preferences are no longer stored in the registry in Windows 7 - or they are stored somewhere different.

I'm expecting it to be in:

HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Prefs

But I don't see it there.

What makes it wierder, is that when I run this app:

public static void main( final String[] args ) throws BackingStoreException {

    Preferences systemRoot = Preferences.systemRoot();
    Preferences preferences = systemRoot.node( "com/mycompany/settings" );

    systemRoot.put( "foo", "bar" );
    systemRoot.put( "baz", "lolz" );
    System.out.println( "-------------------------------" );

    String[] keys = preferences.keys();
    for( String key : keys ) {
        System.out.println( key );
    }

    System.out.println( "-------------------------------" );

    keys = systemRoot.keys();
    for( String key : keys ) {
        System.out.println( key );
    }
}

It actually writes (I can comment the put out and run it again and it works) but I don't see the new keys in the registry.

Also, I can't seem to see this documented anywhere. Thanks in advance.

EDIT #1 The only reason this matters is that the setting changes dependent upon which environment it is ran. This being said, it is often useful to simulate that environment by inserting the registry keys manually and then doing some checking.

I was running as admin, yet I did not see the keys in the registry where I expected them to be.

javamonkey79
  • 17,443
  • 36
  • 114
  • 172
  • 2
    You could use Sysinternals Process Monitor to see the registry and file system operations for that process and try to deduce where the reads/writes are going. – Sasha Goldshtein Feb 09 '11 at 16:22
  • 1
    Why should it store anything under `HKEY_LOCAL_MACHINE`? I'd expect it to live under [`HKEY_CURRENT_USER`](http://en.wikipedia.org/wiki/Windows_Registry#HKEY_CURRENT_USER_.28HKCU.29). Also: why do you care? It's undocumented for a reason: you should not rely on it and it can change at any time. – Joachim Sauer Feb 09 '11 at 16:25
  • must be there: btw are you running as administrator? – bestsss Feb 09 '11 at 16:27
  • Sorry, I didn't see that you were using the `systemRoot()` and not the `userRoot()`. – Joachim Sauer Feb 09 '11 at 16:28
  • I will add in edit's to clarify. – javamonkey79 Feb 09 '11 at 19:15

4 Answers4

65

They are under current user: HKEY_CURRENT_USER\Software\JavaSoft\Prefs

AlexR
  • 114,158
  • 16
  • 130
  • 208
  • Have you confirmed this? eg: Use the above code and then check your registry? It does not show up in regedit for me. – javamonkey79 Feb 10 '11 at 07:03
  • 2
    The user settings are under HKCU, the system settings under HCKS (unless you overwrite it with system variables). The path on 64bit windows with 32bit java however is under WoW64 like answered above. – eckes Feb 09 '15 at 04:04
26

for systemRoot:

HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\...

for userRoot:

HKEY_CURRENT_USER\SOFTWARE\JavaSoft\...
Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
bestsss
  • 11,796
  • 3
  • 53
  • 63
14

I had a similar problem when I worked with systemRoot preferences and with the help of a registry monitor I discovered that the location where they are stored changes depending on if the Windows operating system is 32-bit or 64-bit.

Under 32bit OS (Windows XP in my case) the systemRoot registry path was

HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Prefs

Under 64bit OS (Windows 7 in my case) the systemRoot registry path was

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft\Prefs

The same 32-bit JRE (JRE 1.6.0_20-b02) was used on both systems.

When running a 32-bit application (the JVM) on a 64-bit windows the registry automatically inserts the Wow6432Node path element to allow for applications compiled for either 32-bit or 64-bit to co-exist on the same machine while keeping their settings separate.

  • 1
    on windows 7 64-bit I don't see any prefs under HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft but I do see them at HKEY_CURRENT_USER\Software\JavaSoft\Prefs – sdjuan Jul 22 '16 at 14:40
1

Some preferences are stored in registry keys, while some others (now I'm going to check exactly which ones) seem stored in text files; for instance, the preference "Use certificates and keys in browser keystore" is stored in C:\Users\%USER%\AppData\LocalLow\Sun\Java\Deployment\deployment.properties :

#deployment.properties
#Thu Jun 12 15:26:53 CEST 2014

deployment.security.browser.keystore.use=false

deployment.modified.timestamp=1402579613914
deployment.version=7.21
deployment.browser.path=C\:\\Program Files\\Mozilla Firefox\\firefox.exe
#Java Deployment jre's
#Thu Jun 12 15:26:53 CEST 2014
deployment.javaws.jre.0.registered=true
deployment.javaws.jre.0.platform=1.7
deployment.javaws.jre.0.osname=Windows
deployment.javaws.jre.0.path=C\:\\Program Files\\Java\\jre7\\bin\\javaw.exe
deployment.javaws.jre.0.product=1.7.0_60
deployment.javaws.jre.0.osarch=x86
deployment.javaws.jre.0.location=http\://java.sun.com/products/autodl/j2se
deployment.javaws.jre.0.enabled=true
deployment.javaws.jre.0.args=

This was verified on Windows 7 pro / 32 bit - JRE 1.7.0_60 (i586)

sources:
Related question on this site
Oracle - Java SE documentation - Deployment Configuration File and Properties

Have a nice day

Community
  • 1
  • 1
Edgar Grill
  • 1,876
  • 2
  • 11
  • 7
  • 2
    That's most probably a "property file" managed with `java.util.Properties`, a very basic API introduced in Java 1.0. The topic of the question is the Preferences API, a much more sophisticated mechanism introduced in Java 1.4. Each has its own area of applicability, though. – Mario Rossi Mar 11 '15 at 15:40