How to get the java compiler for ubuntu?
Chances are your colleagues are using Java 6. In that case, you have to install openjdk-6-jdk
.
Recall that single .java
source files are compiled using:
javac hello.java
.class
files are executed like:
java Hello
This expects a Hello.class
file in the current directory. If you're working in a different directory, you need to set the -classpath
(or -cp
) option:
java -cp /path/to/classes Hello
Related videos on Youtube
Jordan
Updated on September 18, 2022Comments
-
Jordan over 1 year
I am in a Java class in my college right now, and we have to be able to compile java programs via the terminal. I would like to keep using my Ubuntu installation for it though. whenever I try to compile something on Ubuntu, nobody can read the program. Says something about it not being able to read the program. I have installed the "openjdk-7-jdk" program, which might be the issue. Any help is appreciated, thanks! On a side note, I would like to mention that I need to compile my programs on OS X Lion or Windows 7 in order to run them correctly...
-
Michael K over 12 yearsbefore invoking java, you need to compile your program using javac: javac ToMyDearestRachel (you might need to add .java extension if you have one) - I guess Rachel will be the second happiest girl in the world (just after mine) once it works :)
-
Jordan over 12 yearsThe problem is I have already used javac. It still doesn't work on Ubuntu.
-
Michael K over 12 yearsah re read your posting - yes you should use java 6 as java 7 is not yet that common ;-) Or thell the others that java 7 is now available. The different versions of java are installed in the folder /usr/lib/jvm/whatever/bin/javac - if you intend to use another installed java compiler, just invoke the command using the complete path
-
Jordan over 12 yearsShould I just uninstall java 7 if it isn't all that common anyways?
-
Michael K over 12 yearsyou can keep it installed, but you might want to setup the version 6 as default by redirecting the symlinks javac and java
-
Jordan over 12 yearsAh well I just removed jdk7 and installed jdk6 and it works flawlessly right now! thanks you for the suggestions! :)
-
-
Jordan over 12 yearsI am in the correct directory, it just won't run for some reason.
-
Lekensteyn over 12 yearsTry using
openjdk-6-jdk
as I suggested. It's also very unusual to share.class
files in class. Usually, the .java source files must be submitted to the teacher (and collegues) -
Jordan over 12 yearsYeah we have to submit the .java files, but I can't even test on my machine if the programs are actually working. I'll try java 6.
-
Lekensteyn over 12 yearsUsing the
sudo update-alternatives --config java
command, you can choose your default java program. For javac, replacejava
byjavac
-
Jordan over 12 yearsJava 6 works flawlessly! I guess it was just too updated haha. Thanks for the help!