Email Subscription Form

Wednesday, May 8, 2013

Introduction to the Command Line

In order to run Maven (which we will discuss in the next post), it is necessary to know how to run commands from the command line.  If you are not familiar with using the command window, this post will explain the two most important commands.  My instructions will refer to the Windows command line, but they can be adapted without too much difficulty to Linux or Mac.

To bring up the command line, go to the Start menu and type "cmd" in the search field.  Click the return key and a command window should open.

cd:
cd stands for "change directory".  You will use this to navigate through your file system.  When you opened your command window, you probably saw something like this:  C:\Users\YourName>.  This is your user folder.  If you were to navigate to it in the File Explorer, you would go to Computer->Windows7_OS (C:)
->Users->YourName.  (The OS will vary based on your computer, and the YourName will be your user name.)

Let's try navigating to the Users folder.  In the command window, type "cd Users" and click return key.  Note that the command prompt now says C:\Users>.

There is another way to navigate up one folder.  First, let's return to your folder.  Type "cd YourName" (replacing the words YourName with your actual user name) and click Return.  Now the command prompt should say C:\Users\YourName.  Now type "cd .." and click Return.  Notice that you have returned to the Users folder.  The two dots send the instruction to go up one level.  If you type "cd.." and Return again, you will see C:\> in the command prompt.

You can also navigate through more than one folder at a time.  Type "cd Users/YourName" (replacing the YourName with your user name) and click Return.  Now the command prompt will say C:\Users\YourName.  You've navigated down two levels, from the C: level to the YourName level.

dir:
dir is the command used to list all the files in a particular location.  This really comes in handy when you can't remember what you named a file.

Let's try using the dir command.  In the command window, verify that the command prompt currently reads C:\Users\YourName.  If it doesn't, use the cd command to navigate there.  Now type "dir" and click Return.  You should get a list of all the files in your personal folder.

Let's add a new file to this location.  It's possible to do this through the command line, but that is beyond the scope of this tutorial.  Instead, create a simple Word or Notepad file called MyCommandFile, and save it in your folder.  Now return to the command window and type the "dir" command again.  You should see your new file in the directory.

Another shortcut to navigation when you have forgotten a file name is the tab key.  In the command line, type "cd My" and then click the tab key.  You should see the file name auto-complete for you.

Bonus command:  
One more helpful command to use is the up arrow key.  This key will go back through your most recent commands.  This really comes in handy if you have typed a particularly long command and would rather not type it again.


The command window is very helpful, and there are a number of good tutorials available if you would like to learn more about what it can do for you.

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!

New Blog Location!

I've moved!  I've really enjoyed using Blogger for my blog, but it didn't integrate with my website in the way I wanted.  So I&#...