You don't need to be a math whiz...
You don't need to be Spock-like logic monster...
But...
Do you want to find out? Here's an exercise that will help you decide whether YOU might be a programmer: There will be three steps to this exercise:
This contains everything you need for writing computer programs in Java! It has Internet links for downloading and instaling free software. It also has some programming exercises to get you started on your way to becoming a programmer.
First find a "text editor" on your computer -- you can use it to write your programs. Download and install the software you will need for "compiling" Java programs, using the instructions provided below. Then type the computer language "code" for each of the programs listed below. Compile them into working "programs", and run them -- see what happens!
This may be enough to help you decide if programming is for you!
Follow these 4 instructions to install Java!
| 1 |
Apple MacOSx already has a Java compiler, so there is nothing to install or configure!
Windows and Linux users can get the Java compiler from Sun Corporation.
The compiler download for Windows is about 72 MB in size. Go to the Sun website (http://java.sun.com), locate the heading "Popular Downloads", and use the "Java SE" link. |
![]() |
| 2 | Follow the "Download JDK 6 Update 14" link, or whatever is the current version -- (not the JRE): | ![]() |
| 3 | Accept the license agreement... | ![]() |
| 4 | ...and click the filename (which varies with the version number) to download and install the version of the Development Kit that matches your system (Windows, Linux, etc.), following all defaults. You can skip the registration step, and delete the installation file that you downloaded. | ![]() |
If you are using Windows, search your system for a file named javac.exe. It should be located in a folder named C:\Program Files\Java\jdk1.6.0_14\bin, or something similar. You may even have more than one from which to choose — if so, choose the newest one. Remember the folder name, because you'll need it later on.
Now you should be ready to write some programs!
You will need a text editor. Any text editor will do, including Windows Notepad, Linux vi, and Apple TextEdit. These are general-purpose text editors, not specifically designed for use in programming, but they work just fine. (For details on setting up Apple TextEdit, go to http://support.apple.com/kb/TA20406?viewlocale=en_US.
(Word, Windows WordPad, and other editors capable of "rich text formatting" are not very suitable for writing code. They are page-oriented, and they embed formatting information into the files that they produce. While it is possible to configure such editors for text editing, it is better to avoid them.)
Type (or copy/paste) the following computer "code" into a text editor.
| Rolling Two Six-sided Dice | |
|---|---|
|
import java.io.*;
public class DiceRoll { public static void main(String[] argv) throws Exception { int a; // the name of the first die int b; // the name of the second die int total; // the result a = 1 + (int)(6 * Math.random()); b = 1 + (int)(6 * Math.random()); total = a + b; System.out.print("Dice result: "); System.out.print(total); System.out.print(" ("); System.out.print(a); System.out.print(" and "); System.out.print(b); System.out.println(")"); } // main } // public class |
|
| that's print-EL-en, not print-ONE-en | |
Save the file as DiceRoll.java. In Windows, be sure to put c:\ in front of the file name, and enclose the whole thing in quote marks!
Now get a "command prompt" -- in Apple, use the "Terminal" application. In Windows, do Start|All Programs|Accessories|Command Prompt, like this:
The following assumes that your javac.exe file is located in a folder named C:\Program Files\Java\jdk1.6.0_14\bin -- modify these instructions if it's in another folder. In the command window, enter these commands to start the compiler: (You might want to copy/paste that long one!):
| cd\ |
| path=C:\Program Files\Java\jdk1.6.0_14\bin;%path% |
| set classpath= |
Then enter these commands to compile and run your program:
| javac DiceRoll.java |
| java DiceRoll |
Here's what it should look like (using Windows):
(You type what's in yellow, and press the ENTER key to send the command to the computer.)
Did it work? That's your first Java program!
|
Use the instructions from the first program, and create the following file.
Type (or copy/paste) the following computer "code" into a text editor.
|
Save the file as F2C.java. In the command window, enter these commands to compile and run your program:
Here's what it should look like (using Windows): (You type what's in yellow, and press the ENTER key to send the command to the computer.) |
|||||||
|
Use the instructions from the first program, and create the following file.
Type (or copy/paste) the following computer "code" into a text editor.
|
Save the file as Area.java. In the command window, enter these commands to compile and run your program:
Here's what it should look like (using Windows): (You type what's in yellow, and press the ENTER key to send the command to the computer.) Hint: Do you want to "round-off" the answers so that they don't show so many decimal digits? Here's how: replace System.out.println(area); with System.out.println(new java.text.DecimalFormat("#.0").format(area));. |
|||||||
|
Use the instructions from the first program, and create the following file.
Type (or copy/paste) the following computer "code" into a text editor.
|
Save the file as PokerHand.java. In the command window, enter these commands to compile and run your program:
Here's what it should look like (using Windows): (You type what's in yellow, and press the ENTER key to send the command to the computer.) |
|||||||
You may want to start your programming education at DVC. We have three possible starting places: COMSC-100, -105, or -110, depending on your aptitude and preparation going into this. If you did really well with the exercises presented here, and there's no holding you back, COMSC-110 may be your starting place. But if you had trouble getting off the ground with this, and you want to know more, COMSC-100 is for you. If you are in between these extremes, consider starting at COMSC-105.
Here's a link to a diagram that shows the sequence of programming classes offered at DVC: www.dvc.edu/org/departments/computer-science/computer-science-sequence.pdf.