The are so many ways to compile java files. You only need to install JDK in your system
You can install openJDK or the official libraries from Oracle.
To know if you have already installed JDK in your system open a terminal and type:
If you get a response with your version you can skip the next steps
But if you see something like "The program 'java' can be found in the following packages... " you can just type:
sudo apt-get install openjdk-6-jdk
If you want the official packages from Oracle you have to write:
- First, grab Oracle Java 7 directly from Oracle Java download page:
- Make sure you download 32 bit (Linux x86 ~ jdk-7u21-linux-i586.tar.gz) or 64 bit (Linux x64 ~ jdk-7u21-linux-x64.tar.gz) JDK version in .tar.gz format.
- Open a terminal and type the following command to list your files
sudo mkdir -p /usr/lib/jvm/
sudo tar xvf ~/Downloads/jdk-[YOUR JDK VERSION]-linux-x64.tar.gz -C
- Set or update the JAVA_HOME and PATH shell variables as follows:
export JAVA_HOME="/usr/lib/jvm/jdk1.[YOUR JDK VERSION]"
- Check if you have already installed correctly bu typing java -version again.
Now you will be able to compile file from your command line positioning the prompt in your java folder and using this syntax:
You can also use any IDE like Eclipse or netbeans to make it easier.