0

Till date, i've been working with C programs and I guess all the C libraries are installed already in my system, since I can just gcc program.c and it would compile.

But now I am moving onto Java, and I guess I'd need to install the libraries for that. someone please help me with it.

I picked up this book 'Thinking In Java' and it says that

This book focuses on and is tested with Java SE5/6.

So I guess, I'd want to download the same version of libraries.

1 Answer 1

1

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:

java -version

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:

  1. First, grab Oracle Java 7 directly from Oracle Java download page:
  2. 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.
  3. 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 /usr/lib/jvm

  1. Set or update the JAVA_HOME and PATH shell variables as follows:

export JAVA_HOME="/usr/lib/jvm/jdk1.[YOUR JDK VERSION]" export PATH="$PATH:$JAVA_HOME/bin"

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

javac HelloWorld.java

You can also use any IDE like Eclipse or netbeans to make it easier.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .