While I know there are several posts on gathering installed Java versions, I haven’t found one that give me the functionality I am looking for. I am hoping someone can help.
So you can get the installed versions from:
(names of keys of keys “HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment” of registry as string)
Which will return a response such as:
A: 1.7
A: 1.7.0_67
I need to display the latest version, removing the “1.” from the result. So using the current values as an example, the goal is to generate a response of:
following texts of firsts "." of (tuple string items (integers in (number of tuple string items of it - 1, number of tuple string items of it)) of concatenation ", " of unique values of((names of keys of key "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment" of registry as string )))
But as I know, the unique values can not be always trusted to sort the output in a correct ascending order.
If we convert the results into the “version” inspector, that might help us process the results.
However, I do notice that “1.7” is considered higher than “1.7.0_67”.
q: "1.7"; "1.7.0_67"
A: 1.7
A: 1.7.0_67
q: (it as version) of ("1.7"; "1.7.0_67")
A: 1.7
A: 1.7.0
q: maximum of (it as version) of ("1.7"; "1.7.0_67")
A: 1.7
q: minor revision of maximum of (it as version) of ("1.7"; "1.7.0_67")
A: 7
q: minor revision of maximum of (it as version) of ("1.7"; "1.7.0_67"; "1.8.2")
A: 8
unique values of names of keys of keys "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment" of (x32 registries; x64 registries)
This is how I would remove the “1.” from the front of it:
(following text of first "1." of it | it) of unique values of names of keys of keys "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment" of (x32 registries; x64 registries)
This is how I would get the max version (which seems like it won’t work quite right in this case:
maxima of (it as version) of (following text of first "1." of it | it) of unique values of names of keys of keys "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment" of (x32 registries; x64 registries)
Once you have the raw values, you need to do some manipulation in order to convert the underscore characters into dots, so you can cast the results as a “version” type. Additionally, the “version” type has a difficulty comparing versions of different “lengths”, so you can use "pad of " to convert “1.7” into “1.7.0.0”.
I don’t have a system with multiple Java versions installed handy, but once you have retrieved the string values from the Registry, you can convert them to “version” type by replace underscores with dots, place them in a set, pad the elements, and find the maximum of them. Here’s the basic logic -
q: ("1.7";"1.7.0_67";"1.7.0_81")
A: 1.7
A: 1.7.0_67
A: 1.7.0_81
T: 0.021 ms
I: plural string
q: versions ("1.7";"1.7.0_67";"1.7.0_81")
A: 1.7
A: 1.7.0
A: 1.7.0
T: 0.056 ms
I: plural version
q: (concatenation "." of substrings separated by "_" of it) of ("1.7";"1.7.0_67";"1.7.0_81") as string as version
A: 1.7
A: 1.7.0.67
A: 1.7.0.81
T: 0.171 ms
I: plural version
q: pads of ((concatenation "." of substrings separated by "_" of it) of ("1.7";"1.7.0_67";"1.7.0_81") as string as version)
A: 1.7.0.0
A: 1.7.0.67
A: 1.7.0.81
T: 0.180 ms
I: plural version
q: set of pads of ((concatenation "." of substrings separated by "_" of it) of ("1.7";"1.7.0_67";"1.7.0_81") as string as version)
E: class OperationNotDefined
--> Cannot have a "set of versions", so we have to leave them as strings for now
q: set of ((concatenation "." of substrings separated by "_" of it) of ("1.7";"1.7.0_67";"1.7.0_81") as string)
E: This expression evaluates to an unrepresentable object of type "string set"
T: 0.231 ms
I: singular string set
q: (maximum of pads of (elements of it as version)) of set of ((concatenation "." of substrings separated by "_" of it) of ("1.7";"1.7.0_67";"1.7.0_81") as string)
A: 1.7.0.81
T: 0.226 ms
I: singular version
maxima of (it as version) of ( (concatenation "." of substrings separated by "_" of it) | it ) of (following text of first "1." of it | it) of unique values of names of keys of keys "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment" of (x32 registries; x64 registries)
Using sets does make sense when building tuples. I’d be that is why.
It does seem to be a relatively fast operation:
Q: number of elements of set of elements of set of (integers in (0,10000))
A: 10001
T: 8520
Q: number of elements of set of (integers in (0,10000))
A: 10001
T: 7200
Windows definitely expects versions that are canonical unlike the other platforms.
Does anyone know how common this type of version number is on Windows? Does anyone outside of Java use a version number that is anything but number.number.number.number in form?
I’ll see about scheduling in an enhancement that would allow for the same type of version extensions the other platforms allow but no commitment as to when. If someone could create a formal RFE that would help
Sorry for jumping in so late, I’ve been buried in requests, and this one has found a new option. Using the code provided is a great option, but I found another way.
The issue is that I am apparently relevance illiterate in the most basic of functions. So if you take the value of key BrowserJavaVersion from HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment and minus 3 you get the current default installed value.
Sounds easy right? I’ve been working on it for some time, and finally admitted defeat and came here.
So I believe I have to cast the value to a string or integer and then -3 - So I’m looking for the relevance to do this. The core relevance is:
value “BrowserJavaVersion” of key “HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment” of registry
unique values of (it as string as trimmed string) of values "BrowserJavaVersion" of keys "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment" of (x64 registries; x32 registries)
This is how you would subtract 3 from the integer value, which might not actually make sense, since I don’t know what the raw values are:
(it as integer - 3) of unique values of (it as string as trimmed string) of values "BrowserJavaVersion" of keys "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment" of (x64 registries; x32 registries)
You should never reference Wow6432Node directly in a relevance statement. It will cause problems on 32bit systems, as well as not get both registry locations correctly and easily. The Wow6432Node is the 32bit registry software key location on 64bit windows.
Thanks James. When I run this query in FixletDebugger (even as local client) I get the following:
Q:(it as integer - 3) of unique values of (it as string as trimmed string) of values “BrowserJavaVersion” of keys “HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment” of (x64 registries; x32 registries)
E: Singular expression refers to nonexistent object.
Yet, getting the raw value works fine:
Q:(unique values of (it as string as trimmed string) of values “BrowserJavaVersion” of keys “HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment” of (x64 registries; x32 registries))
A: 10.67.2