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...

Here is a picture of what I have downloaded and what I could download instead...

enter image description here

link|improve this question

57% accept rate
1  
before 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 :) – Michael K Feb 1 at 13:40
The problem is I have already used javac. It still doesn't work on Ubuntu. – Jordan Feb 1 at 13:42
1  
ah 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 – Michael K Feb 1 at 13:45
Should I just uninstall java 7 if it isn't all that common anyways? – Jordan Feb 1 at 13:46
1  
you can keep it installed, but you might want to setup the version 6 as default by redirecting the symlinks javac and java – Michael K Feb 1 at 13:48
show 1 more comment
feedback

1 Answer

up vote 3 down vote accepted

Changes are that your collegues 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
link|improve this answer
I am in the correct directory, it just won't run for some reason. – Jordan Feb 1 at 13:43
Try 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) – Lekensteyn Feb 1 at 13:46
Yeah 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. – Jordan Feb 1 at 13:47
Using the sudo update-alternatives --config java command, you can choose your default java program. For javac, replace java by javac – Lekensteyn Feb 1 at 13:53
Java 6 works flawlessly! I guess it was just too updated haha. Thanks for the help! – Jordan Feb 1 at 13:54
feedback

Your Answer

 
or
required, but never shown

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