Friday, May 3, 2013

Setting Up Your Java Environment


In order to write your automated tests in Java, you will need the Java Development Kit, or JDK.  Here are instructions for downloading and installing the JDK:

1. Navigate to http://www.oracle.com/technetwork/java/javase/downloads/index.html

2. Click on the download button for the JDK

3. Click the radio button that signifies that you have accepted the license agreement

4.  Find your operating system and click on the download link.  If you are a Windows user and trying to determine whether you should use Windows x86 or Windows x64, go to the start menu, right-click on "Computer" and click "Properties".  A popup window should appear.  Look at the entry next to "System type".  A 32-bit operating system means you should use x86; a 64-bit operating system means you should use x64.

5.  Follow the installation prompts, and if prompted to do so, restart your computer


Next, you will need an Integrated Development Environment (IDE), like Eclipse.  Here's how to download and install it:

1. Navigate to http://www.eclipse.org/downloads/

2. Use the dropdown at the top of the page to select your operating system

3. Find the entry for Eclipse IDE for Java Developers, and click on the link for either 32-bit or 64-bit, depending on your operating system

4. Follow the installation prompts


Now you are all ready to begin coding in Java!  Let's write a program:

1. Open Eclipse

2. You will be prompted to name your workspace; give this space whatever file name and filepath you prefer, such as C:\Users\YourName\workspace.

3. The Eclipse window should open

4. Select File-> New-> Java Project

5. Give your project a name, such as MyFirstJavaProject, and click Finish

6. Look in the leftmost window, in the section called Package Explorer.  You should see a folder icon with the letter J above it, and your project name.

7. Right-click on the project name and choose New-> Package

8. Give your package a name, such as myFirstPackage, and click Finish

9. In the Package Explorer section you should now see a folder called src under the project name, with an icon that shows a folder with a package inside it.  You should also see a package icon under the src folder with your package name.  You also should see that the JRE System Library has been added to the project file.

10. Right-click on the package name and choose New->Class

11. Give the class a name, such as MyFirstClass, and click Finish

12. In the Package Explorer section you should now see a file called MyFirstClass.java.  The file will have an icon that looks like a sheet of paper with a J on it.

13. Look in the center section of the Eclipse window.  You should see that the class file you created is open, and has this text in it:

package myFirstPackage;
public class MyFirstClass {
}

14. Paste the following code in between the curly braces found after the class name:

public static void main(String[ ] args){
System.out.println("Hello world!");
}

15.  If you have done step 14 correctly, the whole class file should look like this:

package myFirstPackage;
public class MyFirstClass {
public static void main(String[ ] args){
System.out.println("Hello world!");
}
}

16. Save the changes you made by clicking on the disk icon in the toolbar

17. Right-click on the class name in the Package Explorer and choose Run As-> Java Application

18.  Look in the the bottommost pane of the Eclipse window- you should see a section called Console.  In this section, you should now see the message Hello world!

19.  Congratulations!  You have successfully set up Eclipse and run your first Java program!

No comments:

Post a Comment