How to install and compiling a source code with JDK

This tutorial will show you how to compile a source code with Java Development Kit in the most simply way.

Dropbox configuration

When was the last time you have a virtual drive that can store your file and you can view it on different computer without copying it?

Meet Processing

An open project initiated by Ben Fry and Casey Reas from MIT.

A simple way to work Java, introducing BlueJ

BlueJ, just as simply as its name.

Data Types

Bring you explanations of all Data Types in Computer Programming.

Senin, 29 Desember 2014

How to install Java Development Kit

Hello, good afternoon.
Are you have a nice day?

In this post, i'm going to show you how to install Java Development Kit on your computer. First of all, what is Java Development Kit?

The Java Development Kit (JDK) is an implementation of either one of the Java Standart Edition (SE), Java Enterprise Edition (EE) or Java Micro Edition (ME) platforms released by Oracle Corporation in the form of a binary product aimed at Java developers on Solaris, Linux, Mac OS X or Windows. The JDK includes a private Java Virtual Machine (JVM) and a few other resources to finish the recipe to a Java Application. Since the introduction of the Java platform, it has been by far the most widely used Software Development Kit (SDK). On 17 November 2006, Sun announced that it would be released under the GNU General Public License (GPL), thus making it free software. This happened in large part on 8 May 2007, when Sun contributed the source code to the OpenJDK.

Ok, i think it's enough for the introduction, let's get to the main topic, shall we?

Before you install it, you have to download it from Oracle website or just click this link : Download Java Development Kit, and this windows should pop up at any minute after you click those link.













Scroll down until you find a license agreement and click on "Accept License Agreement".













Scroll down again until you find a list of version of Java Development Kit Product, those list is helping you to find a compatible version of JDK for your operating system. So, if you have Windows Operating System, click on link near Windows OS (32bit/64bit, it depends on what bit your computer is running). On my case, i use Windows 8 64bit, so i clicked on "jdk-8u25-windows-x64.exe".













After the download finished, open your folder that contained the downloaded file and run it. It should look like this. Click "Next" to proceed.













 And this will followed.







 


 














At the middle, there is a list of what feature will be installed by this program, because i need a full version so i choose all of it by click it and choose "This feature will be installed on local hard drive.", then click "Next" and if you want to change your destination folder for the installation, click "Change" and choose the folder, if not, click "Next" again.



 





















And the installation begin, just wait for a couple of minutes until the green bar fully loaded. After that this windows might be pop up, just click "Next".



   










And wait again, if you succeed, this windows will appear.













And that's it, we finished our Java Development Kit Installation. You might want to check it if it's running fine, just go to your search on start menu and type "Configure Java".













And to check it, click on "Java" tab, then click "View" , on "Windows" tab, it should be there. Just like this.













And if you want to try to compiling a source code with Java Development Kit, just follow these steps :

After you make sure that JDK is already installed, the next step is to include JDK's bin directory in Path for your computer.

Windows OS searches the current directory and the directories listed in the PATH environment variable for executable programs. JDK's programs (such as Java compiler javac.exe and Java runtime java.exe) reside in directory "<JAVA_HOME>\bin" (where <JAVA_HOME> denotes the JDK installed directory, e.g., C:\Program Files\Java\jdk1.8.0_xx). You need to include the "<JAVA_HOME>\bin" directory in the PATH.
To edit the PATH environment variable in Windows XP/Vista/7/8:

  1. Control Panel ⇒ System ⇒ Advanced system settings
  2. Switch to "Advanced" tab ⇒ Environment Variables
  3. In "System Variables", scroll down to select "PATH" ⇒ Edit
  4. In "Variable value" field, insert "c:\Program Files\Java\jdk1.8.0_xx\bin" (Replace xx with the upgrade number and verify that this is your JDK's binary directory, on my case i got 25) in front of all the existing directories, followed by a semi-colon (;) which separates the JDK's binary directory from the rest of the existing directories.
  5. DO NOT DELETE any existing entries; otherwise, some existing applications may not run.













Then, the next step is to verify the JDK installation by running it in command prompt.
Launch a CMD shell (Click "Start" button ⇒ run... ⇒ enter "cmd"; OR from "Start" button ⇒ All Programs ⇒ Accessories ⇒ Command Prompt).
  • Issue "path" command to list the contents of the PATH environment variable. Check to make sure that your <JAVA_HOME>\bin is listed in the PATH. (previous step)
 









  • Issue the following commands to verify that JDK/JRE are properly installed and display their version: "java -version" -> enter. Then, "javac version" -> enter.










The last step is to write a Hello Java program and compile it using JDK.

To write it :

  1. Create a directory to keep your works, example: "d:\MyJavaProject" (or any directory of your choice). The directory name shall not contain blank or special characters. Use meaningful but short name as it is easier to type.
  2. Launch a programming text editor (such as TextPad or NotePad++). Begin with a new file and enter the following source code. Save the file as "Hello.java", under your work directory (example: d:\MyJavaProject).
/*
 * First Java program to say Hello
 */
public class Hello {   // Save as "Hello.java" under "d:\MyJavaProject"
   public static void main(String[] args) {
      System.out.println("Hello, world!");
   }
}
 
 
To compile it :
  • Start a CMD Shell (Click the "Start" button ⇒ "run..." ⇒ Enter "cmd"). Set the Current Drive to the drive where you saved your source file "Hello.java". For example, suppose that your source file is saved in drive "d", type "d:" and enter.
  • Set the Current Working Directory to the directory that you saved your source file via the cd (Change Directory) command. For example, suppose that your source file is saved in directory "d:\MyJavaProject".
  • Issue a dir (List Directory) command to confirm that your source file is present in the current directory.
  • Invoke the JDK compiler "javac" to compile the source code "Hello.java".
  • The compilation is successful if the command prompt returns. Otherwise, error messages would be shown. Correct the errors in your source file and re-compile. Check "Common JDK Installation Errors", if you encounter problem compiling your program.
  • The output of the compilation is a Java class called "Hello.class". Issue a dir (List Directory) command again to check for the output. 
  • To run the program, invoke the Java Runtime "java": java Hello
     
 And if nothing goes wrong, it should look like this.


















And this is the end of the post, i hope it can help you to install and compiling a source code with JDK on your computer. If you have questions, don't bother to ask in comment section.
Goodbye, have a nice day, good afternoon.