Android Application Development: A Beginner's Tutorial (2015)
Appendix A. Installing the JDK
You need the Java SE Development Kit (JDK) to create Android applications. This appendix shows you how to download and install it.
Downloading and Installing the JDK
Before you can start compiling and running your programs, you need to download and install the JDK as well as configure some system environment variables. You can download the latest version of the JDK for Windows, Linux, and Mac OS X from this Oracle website:
If you click the Download link on the page, you’ll be redirected to a page that lets you select an installation for your platform: Windows, Linux, Solaris or Mac OS X. The same link also provides the JRE. However, for development you need the JDK not only the JRE, which is only good for running compiled Java classes. The JDK includes the JRE.
After downloading the JDK, you need to install it. Installation varies from one operating system to another. These subsections detail the installation process.
Installing on Windows
Installing on Windows is easy. Simply double-click the executable file in you downloaded in Windows Explorer and follow the instructions. Figure A.1 shows the first dialog of the installation wizard.
Figure A.1: Installing the JDK 8 on Windows
Installing on Linux
On Linux platforms, the JDK is available in two installation formats.
§ RPM, for Linux platforms that supports the RPM package management system, such as Red Hat and SuSE.
§ Self-extracting package. A compressed file containing packages to be installed.
If you are using the RPM, follow these steps:
1. Become root by using the su command
2. Extract the downloaded file.
3. Change directory to where the downloaded file is located and type:
chmod a+x rpmFile
where rpmFile is the RPM file.
4. Run the RPM file:
If you are using the self-extracting binary installation, follow these steps.
1. Extract the downloaded file.
2. Use chmod to give the file the execute permissions:
chmod a+x binFile
Here, binFile is the downloaded bin file for your platform.
3. Change directory to the location where you want the files to be installed.
4. Run the self-extracting binary. Execute the downloaded file with the path prepended to it. For example, if the file is in the current directory, prepend it with "./":
Installing on Mac OS X
To install the JDK 8 on Mac OS X, you need an Intel-based computer running OS X 10.8 (Mountain Lion) or later. You also need administrator privileges. Installation is straight-forward.
1. Double-click on the .dmg file you downloaded.
2. In the Finder window that appears, double-click the package icon.
3. On the first window that appears, click Continue.
4. The Installation Type window appears. Click Install.
5. A window appears that says “Installer is trying to install new software. Type your password to allow this.” Enter your Admin password.
6. Click Install Software to start the installation.
Setting System Environment Variables
After you install the JDK, you can start compiling and running Java programs. However, you can only invoke the compiler and the JRE from the location of the javac and java programs or by including the installation path in your command. To make compiling and running programs easier, it is important that you set the PATH environment variable on your computer so that you can invoke javac and java from any directory.
Setting the Path Environment Variable on Windows
To set the PATH environment variable on Windows, do these steps:
1. Click Start, Settings, Control Panel.
2. Double-click System.
3. Select the Advanced tab and then click on Environment Variables.
4. Locate the Path environment variable in the User Variables or System Variables panes. The value of Path is a series of directories separated by semicolons. Now, add the full path to the bin directory of your Java installation directory to the end of the existing value of Path. The directory looks something like:
5. Click Set, OK, or Apply.
Setting the Path Environment Variable on UNIX and Linux
Setting the path environment variable on these operating systems depends on the shell you use. For the C shell, add the following to the end of your ~/.cshrc file:
set path=(path/to/jdk/bin $path)
where path/to/jdk/bin is the bin directory under your JDK installation directory.
For the Bourne Again shell, add this line to the end of your ~/.bashrc or ~/.bash_profile file:
Here, path/to/jdk/bin is the bin directory under your JDK installation directory.
Testing the Installation
To confirm that you have installed the JDK correctly, type javac on the command line from any directory on your machine. If you see instructions on how to correctly run javac, then you have successfully installed it. On the other hand, if you can only run javac from the bin directory of the JDK installation directory, your PATH environment variable was not configured properly.
Downloading Java API Documentation
When programming Java, you will invariably use classes from the core libraries. Even seasoned programmers look up the documentation for those libraries when they are coding. Therefore, you should download the documentation from here.
(You need to scroll down until you see “Java SE 8 Documentation.”)
The API is also available online here: