I am very new to Raspberry PI. I noticed that you could get anything on Raspberry PI including Java. So using this command:

sudo apt-get update && sudo apt-get install oracle-java7-jdk

I installed JDK 7 on my Raspberry PI.

The problem is, I don't know how to compile. I opened the leaf editor, wrote the usual HelloWorld code in it and saved it as HelloWorld.java. However, from there I was stuck. How do I compile this?


To compile a java program use javac. It should be installed already. You can double check by using javac -version.

Once installed, use command javac 'filename' to compile. And the class file will be output in the same directory.

You can then use the command java to execute the class.

  • I tried javac Hello.java however, it keeps saying javac: file not found error. – Steven Jul 3 '15 at 19:40
  • You will need to make sure that bash is in the same directory as the file location before using javac. Otherwise try using the full file path e.g. c:/usr/home/Desktop/myfile – axwege Jul 3 '15 at 19:46
  • @Steven your question says the file name is HelloWorld.java, so trying to compile Hello.java would naturally result in a file not found error. – Bex Jul 3 '15 at 21:36

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