Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

For example, I have OpenJDK 6 and 7 both installed. If I run javac foo.java will is compile my program as a Java 6 program or a Java 7 program?

share|improve this question
    
Multiple duplicates, i.e.: install jre-7 how to install java –  user unknown Jan 24 '12 at 0:01
add comment

3 Answers

up vote 4 down vote accepted

Debian-based distributions have so-called "alternatives" system, which allows to have more than one program installed which perform the same function (this also includes different versions of the same program, like Java 6 and Java 7). As @user15936 points out, the system works by manipulating symlinks, so "javac" can point to the executable either from OpenJDK 6 or from OpenJDK 7

The command to manipulate the above mentioned symlinks (the process is in fact more complex than that as it includes some configuration, for example manpages change too etc.) - is called update-alternatives. You can learn how to use it by typing man update-alternatives in terminal.

To directly answer your question, another way to determine which javac executable will be invoked is by doing

update-alternatives --display javac
share|improve this answer
1  
There is even the specialized update-java-alternatives. –  user unknown Jan 23 '12 at 23:50
add comment

The answer is whichever is linked to /usr/bin/javac

That will be executed.

You can see this by going to /usr/bin/ and see the link javac is connected by doing ls -l javac.

share|improve this answer
add comment

You should type in a terminal javac -version and there you will get your answer...

share|improve this answer
    
There is nothing wrong with this answer, particularly for users where Oracle Java (JVM/JDK) is no longer provided as a .deb & they manually installed. Highly recommended reading, especially about the 'update java' script' which will set the various alternatives - webupd8.org/2011/09/how-to-install-oracle-java-7-jdk-in.html –  doug Jan 23 '12 at 23:52
    
I didn't vote down, but java and javac might belong to different versions. –  user unknown Jan 23 '12 at 23:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.