different java version between java_home and popen - java

In python IDE, i run these two code snippets and get different output for the java version:
stdout,stderr = Popen(['java','-version'], shell=False, stderr=PIPE).communicate()
print(stderr)
java version "1.7.0"
Java(TM) SE Runtime Environment (build pwi3270sr8fp10-20141219_01(SR8 FP10))
IBM J9 VM (build 2.6, JRE 1.7.0 Windows 7 x86-32 20141216_227497 (JIT enabled, AOT enabled)
J9VM - R26_Java726_SR8_20141216_0955_B227497
JIT - r11.b07_20141003_74578.05
GC - R26_Java726_SR8_20141216_0955_B227497
J9CL - 20141216_227497)
JCL - 20141217_01 based on Oracle jdk7u75-b12
os.system("java -version")
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
Why do i get a different java version inside my python IDE (PyCharm)? How can i change it?

I think this is because os.system() uses the shell (so will pick up any changes in .bashrc / .profile etc... Are you setting a different Java location in your $PATH / $JAVA_HOME in any of those?
I believe Popen doesn't invoke a shell (unless you set shell=true).
Disclaimer: Not tested this.

Related

How switch java version (SOLVE)

Hi right now on my PC works java 17
C:\Users\Dom>java -version
java version "17.0.4.1" 2022-08-18 LTS
Java(TM) SE Runtime Environment (build 17.0.4.1+1-LTS-2)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.4.1+1-LTS-2, mixed mode, sharing)
I want swap on Java 8 for it in windows environment variables i change path on C:\Program Files\Java\jdk1.8.0_341\bin (like on one guide) but thats not help.
verison java in my pc
- jdk-17.0.4.1
- jdk1.8.0_202
- jdk1.8.0_341
How i can change my java version on Java 8 ?
SOLUTION
in file i type it:
#echo off
echo Setting JAVA_HOME
set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_341
echo setting PATH
set PATH=C:\Program Files\Java\jdk1.8.0_341\bin;%PATH%
echo Display java version
thats change java version

Check the if version of JDK installed on macOS is the correct one

I have a macbook with latest HighSierra installed and from System Preferences / Java Panel. It says that i have got latest Java version installed: java 8 update 181.
From the "Java" tab of the aforementioned "Java settings" dialog i can see that the version 181 it is referring to is installed in /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java
If i try to execute that binary (i.e. java -version) i actually get:
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build
1.8.0_181-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
however when i try to launch "java" from a generic prompt or if i try to execute javac i get a different result:
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
this latter java is installed in /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/
So it seems to me that i have got a jre (181) and a jdk (40) is this correct?
if so, is this the correct setup on mac? i started to wonder when forticlient analyzer showed up a bunch of CVE security issues related to JDK that are fixed in update 181.

java version and PATH on OS X

I'm not sure why my PATH is not being respected regarding where to find java on my MAC OS X 10.9.5.
After searching around I found that the Java version referenced from the command line was at /usr/bin/java, while the Java version referenced by Oracle's tools used by browsers and visible at System Preferences > Java, Open the Java Control Panel, click on Java tab at top, click on View... button, check both User and System tabs for Path, showing in both:
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java
The command line picks up 1.6.0_65 even though that is for the version at /usr/bin rather than the one at /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin earlier in the path.
Joes-MacBook-Pro:~ josephmurray$ java -version
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)
Joes-MacBook-Pro:~ josephmurray$ which java
/usr/bin/java
Joes-MacBook-Pro:~ josephmurray$ echo $PATH
/Applications/tr-sub.app/Contents/MacOS:/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin:~/civix:/usr/local:/usr/local/bin:/Applications/MAMP/Library/bin:/Applications/MAMP/bin/php/php5.4.19/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/usr/local/git/bin:/usr/X11/bin:/Library/PostgreSQL/9.3/bin/
Joes-MacBook-Pro:~ josephmurray$ /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
Joes-MacBook-Pro:~ josephmurray$ /usr/bin/java -version
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)
Joes-MacBook-Pro:~
This is preventing me from installing eclipse because it needs Java to be at least 1.7. How can I fix this?
If you want to work with Eclipse, you need to install a full JDK, not use a JRE. The installed JRE is lacking debug symbols etc.
You can install it from Oracle's Java SE Development Kit download page.
You will then also be able to use command line tools such as javac.
The problem turned out to be using a backslash to escape the space in the path. While using it is necessary when entering a command on the commandline, it should not be included when setting PATH in ~/.bash_profile:
export PATH="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin:~/civix:/usr/local:/usr/local/bin:/Applications/MAMP/Library/bin:/Applications/MAMP/bin/php/php5.4.19/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/usr/local/git/bin:/usr/X11/bin"
export PATH=/Applications/tr-sub.app/Contents/MacOS:$PATH:/Library/PostgreSQL/9.3/bin/
NB: Each time you edit ~/.bash_profile you need to refresh the environment variables in the shell by running:
$ source ~/.bash_profile

No Java runtime present, requesting install

I have java JDK installed sucessfully in my mac os 10.9 ..
$ java -version
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
But when i try to run eclipse it asks me to jave SE 6 Runtime again !!!
It looks like eclipse is unable to locate the installed java. You can tell eclipse to point to this version of java by modifying eclipse.ini file
In eclipse.ini file, we need to add -vm option to point to the java8 location:
See: http://wiki.eclipse.org/Eclipse.ini#-vm_value:_Mac_OS_X_Example

Setting HotSpot(TM) Server VM in Java 1.6 environment

I have a question related to setting Java hotspot server VM in java 1.6
is there any way to set Java HotSpot Server VM in java 1.6 environment? When i run following command
java -version
it's showing as below,
java version "1.6.0_16"
Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
Java HotSpot(TM) Client VM (build 14.2-b01, mixed mode, sharing)
I want this has to be displayed as below in third line.
Java HotSpot(TM) Server VM (build 14.2-b01, mixed mode, sharing)
Is there any command so that whenever we run java -version, it will always show Hotspot Server VM rather Client VM??
Thanks
Robert.
Add the -server flag:
java -version -server
outputs
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b06)
Java HotSpot(TM) Server VM (build 17.0-b16, mixed mode)
You should try 'java -server -version' instead. You will need to have the server hotspot compiler installed or use that on the JRE that comes bundled with the JDK (which comes with server hotstpot).
I seem to remember reading somewhere that the JVM will start in server mode automatically if the system meets certain specifications in terms of number of processes and amount of memory. Can't remember the details or find the info though.
Edit: Found some info here
http://download.oracle.com/javase/6/docs/technotes/guides/vm/server-class.html
Server class machine is > 2Gb RAM and > 2 processors.
Simply add the '-server' flag !

Categories