In this chapter, we will discuss on the different aspects of setting up a congenial environment for Java.
If you want to set up your environment for Java programming language, then this section explains how to download and set up Java on your machine. Please follow the steps given below to set up you Java environment.
Java SE can be downloaded for free from the link −
Follow the instructions to download Java and run the .exe to install Java on your machine. Once you have installed Java on your machine, you would need to set the environment variables to point to correct installation directories −
Assuming you have installed Java in c:\Program Files\java\jdk directory −
Right-click on 'My Computer' and select 'Properties'.
Click the 'Environment variables' button under the 'Advanced' tab.
Alter the 'Path' variable so that it also contains the path to the Java executable. For example, if the path is currently set to 'C:\WINDOWS\SYSTEM32', then change your path to read 'C:\WINDOWS\SYSTEM32;c:\Program Files\java\jdk\bin'.
Assuming you have installed Java in c:\Program Files\java\jdk directory −
Edit the 'C:\autoexec.bat' file and add the following line at the end −
'SET PATH = %PATH%;C:\Program Files\java\jdk\bin'
Environment variable PATH should be set to point to where the Java binaries have been installed. Refer to your shell documentation if you have trouble doing this.
For example, if you use bash as your shell, then you would add the following line at the end of your '.bashrc: export PATH=/path/to/java:$PATH'
To write Java programs, you will need a text editor. There are even more sophisticated IDEs available in the market. But for now, you can consider one of the following −
Notepad − On Windows, you can use any simple text editor like Notepad (Recommended for this tutorial) or TextPad.
Netbeans − It is a Java IDE that is free and can be downloaded from https://www.netbeans.org/index.html.
Eclipse − It is also a Java IDE developed by the eclipse open-source community and can be downloaded from https://www.eclipse.org/.
Download the latest version of XStream jar file from xstream-1.4.7.jar. At the time of writing this tutorial, we have downloaded xstream-1.4.7.jar and copied it into C:\>XStream folder.
OS | Archive name |
---|---|
Windows | xstream-1.4.7.jar |
Linux | xstream-1.4.7.jar |
Mac | xstream-1.4.7.jar |
Set the XStream_HOME environment variable to point to the base directory location where xstream jar is stored on your machine. The following table shows how to set the XStream environment on Windows, Linux, and Mac, assuming we've extracted xstream-1.4.7.jar in the XStream folder.
Sr.No. | OS & Description |
---|---|
1 | Windows Set the environment variable XStream_HOME to C:\XStream |
2 | Linux export XStream_HOME=/usr/local/XStream |
3 | Mac export XStream_HOME=/Library/XStream |
Set the CLASSPATH environment variable to point to the XStream jar location. The following table shows how to set the CLASSPATH variable on Windows, Linux, and Mac system, assuming we've stored xstream-1.4.7.jar in the XStream folder.
Sr.No. | OS & Description |
---|---|
1 |
Windows Set the environment variable CLASSPATH to %CLASSPATH%;%XStream_HOME%\xstream-1.4.7.jar; |
2 | Linux export CLASSPATH=$CLASSPATH:$XStream_HOME/xstream-1.4.7.jar; |
3 | Mac export CLASSPATH=$CLASSPATH:$XStream_HOME/xstream-1.4.7.jar; |