Installing the Java Development Kit for Windows

INTRODUCTION

You will need to have administrator privileges for this tutorial.

The Java Development Kit (JDK) can be a pain to install and get working for any first time Java programmers. The process of choosing the correct version, configuring your environment variables properly and compiling your first program in the command prompt can be daunting for those with no prior experience in these areas. However, once you get past the initial hurdles, it gets much easier and all you have to do then is work on learning the Java language itself! So, with that in mind, this article will attempt to explain – in a step-by-step format – how to install and configure the Java Development Kit for Windows users and thus get you on your way to becoming a pro with the Java language!

Now, with the preamble over, let’s get started.

STEP ONE – DOWNLOADING THE CORRECT VERSION OF JAVA

The first thing you will need to do is head on over to: http://www.oracle.com/technetwork/java/javase/downloads/index.html, so that you can download the Java Development Kit.  Upon reaching this page, you should be faced with several different download options. The link you should click is at the top, and it should be labeled : Java Platform (JDK) 7u7. If you’re reading this article quite a time after it was posted, then this may have changed, but at any rate it should still be the topmost download.

After you have clicked this link, you will be taken to a page with a list of all the different Operating Systems that you can install Java on. For the purposes of this tutorial, I will be focusing on Windows. However, before you do anything else, you should see a two radio buttons (which are just like circular check boxes, if you didn’t know) at the top. If you want to install the Java Development Kit - which, presumably, you do – then you will need to accept the license agreement by clicking the radio button corresponding to that option.

Following this, scroll down to the bottom of the Java Development Kit 7u7 box, and you should see two download options labeled: Windows x86 and Windows x64. If you know whether your OS is 64 bit or 32 bit then just go ahead and select the download that corresponds to your system. After that, you can just skip to the next step.

If, however, you don’t know, then follow these steps to find out: Open your control panel, and then select the “System and Security” tab. After that, select “System”. Now, if you scroll down and read the information under the “System” tab, you should see a line saying “System Type:” and then your OS type following it. Once you know this, you can go back to the downloads page, and, if you’re running a 64-bit system, then download the x64 Java Development Kit. Otherwise, download the x86.

STEP TWO – CONFIGURING YOUR SYSTEM’S ENVIRONMENT VARIABLES

Setting the environment variables is important simply because it makes it much easier to make use of the java compiler (javac.exe) and run our programs from the command-line without having to type the entire path. Basically, configuring the variables lets the system know where to look for the java compiler, instead of you having to tell it where to look every time you want to compile and run some code.

Okay, so we know why we do it, but how do we do it? Well, the first thing you will have to do is to find the correct path to the java compiler. This is quite simple, and is exactly the same for every windows user unless you changed the default directory into which java is installed. If you did this, then you’ll need to find that path and use it.

So, firstly, open your start menu and click “computer”. Then open your C: drive. You should then open program files and find the “Java” folder. Open this, then open your Java Development Kit folder and then the bin folder. Once you have done that, copy the file path, which is just the text in the search box directly above the directories window.

Now that you have the file path copied, you will need to modify your systems PATH variable. To do this, open control panel, then System and Security, then system, and finally click Advanced System Settings on the left. Now that you’re in, you should automatically be centered on the “Advanced” tab. If not, click this now, and then select “Environment Variables” at the bottom right of the window. Now what you’ll need to do is select the scroll box headed “System Variables” and scroll down until you find the PATH variable. Select this, click edit, add a semicolon to the end of whatever text is already in there and then paste your file path into the text box.

Now, just get out of these folders by clicking “OK” until they’re gone.

STEP THREE – MAKING SURE EVERYTHING WORKED

Okay, just to establish that everything went to plan, we can create a small program that will display a window onto the screen if all is well.

Firstly, open whatever text editor you use. For this tutorial, I will be using Notepad. Into a blank document, paste the following code exactly as it is:

import java.awt.*;
import javax.swing.*;
public class Working extends JFrame{

public Working(){

super(“Working?”);
setSize(400, 300);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public void paint(Graphics g){
super.paint(g);
g.setColor(Color.BLACK);
g.fillRect(0, 0, 400, 300);
g.setColor(Color.GREEN);
g.setFont(new Font(“Verdana”, Font.BOLD, 19));
g.drawString(“Working!”, 157, 150);

}
public static void main(String args[])
{

new Working();

 }

}

After you have done this, save the file as “Working.java” onto your desktop. Now, open the command prompt by bringing up the start menu and typing “cmd” into the search box.

Okay, you should have your code saved into a .java file on your desktop and the command prompt open. What you have to do now is navigate – using command line programming – to the directory where your file is stored (this would be the desktop) and then compile it. This may sound quite daunting, but it’s actually really easy. All you have to do is type “cd C:Users(your computer name)Desktop” into the command prompt and press enter. Once you’ve done this, you type “javac Working.java” and as long as you have done everything correctly, you should get no errors. Finally, type “java Working” and your program should run and voila!, you’re done.

Congratulations on installing the Java Development Kit properly and good luck learning how to program in Java!



+ Site/Blog: http://www.owlspectacular.blogspot.co.uk
+ Find Owlee on:  Google+   FaceBook   Twitter

Leave a Reply

© 2018 HowToee.com. All rights reserved. Entries RSS · Comments RSS
You may post a link to the articles contained on this site. However, you are not allowed to post full articles from www.HowToee.com on any other website or blog. Violators will be prosecuted.
Terms of Use | Privacy Policy