Get ready to program by writing a "Hello, World!" program on the same computer you plan to use to do your assignments.
Textbook: 1.5 - 1.6
New concepts: Compiling; printing to the screen.
If you are planning to use your home machine, you will need to download and install the JDK.
"JDK 7" is the latest version, but any Java 5 or 6 version will also work for this course. Make sure you get the JDK (Java Development Kit), not the JRE (Java Runtime Environment). You do not need any additional bundles, such as NetBeans (a large IDE program used when writing code), JavaFX, or Jave EE, but these versions will also work if you install them instead.
Hello, World!
Using Notepad or Wordpad, write a simple program, such as:
/** * My first program. It prints a greeting to the screen. * * @author Zach Tomaszewski */ public class Hello { public static void main(String[] args) { System.out.println("Hello, World!"); } }
Compile this program at the command line: javac Hello.java
And then run it: java Hello
Of course, to submit this program, you will need to change its name to UsernameA00b.java
, where Username
is your UH username. Remember that the class name must match the file name and that Java is case-sensitive.
Upload your UsernameA00b.java
file to Tamarin.
'javac' is not recognized as an internal or external command,
operable program or batch file.
javac.exe
file was installed. It will probably be somewhere like C:\Program Files\Java\jdk1.7.0\bin\
On Vista or Windows 7, also check in Program Files (x86)
, if you have one. You might also try a file search for javac.exe if you can't find it by browsing.
Once you find javac.exe, you can test that you have the path correct by typing the full path on the command line. It'll look something like this:
"C:\Program Files\Java\jdk1.7.0\bin\javac" -versionYou may need the quotes around the file path if it contains any spaces. Doing this is just a test. If it works (Windows can now find javac and it tells you the correct version number), then Java is installed correctly and you know where it is.
javac
(so probably C:\Program Files\Java\jdk1.7.0\bin\
) to the
end of the list. Make sure there is a ; (semi-colon) between this path and
the one before it.
javac -version
or javac Hello.java
should work now, without having to type the whole path to javac.
There are also a couple YouTube vidoes that show this process (with slightly different steps) here and here.
If you run into problems, let your TA know how far into this process you made it and what went wrong. If you have a laptop, feel free to bring it into lab or office hours for help.
error: cannot read: Hello.java
1 error
javac: file not found: Hello.java Usage: javac <options> <source files> use -help for a list of possible options
Either of these means javac can't find the .java file you are trying to compile (in this case, Hello.java). Check that you are in the same directory as the file. Type dir
on the command line and you should see your .java file in the list of files displayed.
If you need to switch directories to find where you saved Hello.java, remember that
cd ..
moves up a level, and
cd dirName
will move down one level into the sub-directory named dirName. See Using the Windows Command Prompt for more.
To write your code, use the simplest text editor you can find listed under Applications. If there is no plain text option when you go to save the file, you may have to go to Format -> Make Plain Text (or something similar). This will remove all formatting toolbar options and allow you to save as plain text.
To compile and run your code, go to Applications -> Utilities -> Terminal. Terminal works basically the same way as the Windows Command Prompt, although instead of dir
, you have to type ls
(or ls -l
, for a longer view). (Those are Ls, not 1s, since "ls" is short for "listing".) The cd
, java
, and javac
commands are the same.