Description
Problem Description
You are a CS 1331 student who needs to install the JDK, configure it for command line use, and learn how to use a programmer’s text editor to create and edit Java source code.
Solution Description
Setting Up Your Computer
- Download and install the JDK on your computer using our installation instructions or Oracle’s installation instructions
- Download and install a programmer’s text editor. You may end up trying out several over the course of the semester before you settle on one. See our guide to text editors.
- Create a directory for your CS 1331 coursework somewhere on your hard disk; we suggest cs1331.
- You can do this on the command line by navigating to the directory you want to contain is the cs1331 folder (using the cd command).
- To create the folder use the command mkdir cs1331.
- Enter the new folder by using the command cd cs1331.
- Note: avoid putting spaces in file and directory names, since doing so complicates the use of some command line tools.
- Create a subdirectory of your cs1331 directory named hw0.
- Download Schools.java to your hw0 directory.
- On the command line, make sure you are in the hw0 Enter these commands (remember that ‘$’ is the shell prompt (something like ‘C:>’ on Windows) – don’t type the shell prompt character(s)):
7. $ javac -version > hw0-output.txt8. $ java -version 2>> hw0-output.txt
Please note what is happening here:
> redirects the standard output of a program. 2> redirects stderr, which is used for diagnostics (such as version strings). The first line creates the hw0-output.txt file, and the second line (with the extra >) adds more text to the file. Here is a nice discussion of the file descriptors stdin, stdout and stderr.
What this means is that > (or 2>) will overwrite the file, so if you go back to repeat the first step, you’ll need to repeat all the other steps as well.
Your First Java Program
- Open your text editor and create a file in your newly created hw0 directory named java and enter the following Java program:
2. public class NimblyBimbly {3. public static void main(String[] args) {4. for (int i = 0; i < 9; i++) {5. System.out.print(“\u004D\u0065\u006F\u0077 “);6. }7. System.out.println(“…”);8. System.out.println(“\u004D\u0065\u006F\u0077\u0021”);9. }10. }
- On the command line, go to the directory containing your newly created java file and enter javac NimblyBimbly.java. Do a directory listing using the command ls on Mac and Linux or dir on Windows; you should see a file called NimblyBimbly.class that contains the compiled bytecode of your NimblyBimbly program. These commands should look like this:
12. Mac / Linux:13. 14. $ javac NimblyBimbly.java15. $ ls16. NimblyBimbly.class NimblyBimbly.java hw0-output.txt …17. 18. Windows:19. 20. C:\…\cs1331\hw0> javac NimblyBimbly.java21. C:\…\cs1331\hw0> dir22. NimblyBimbly.class NimblyBimbly.java hw0-output.txt …
- Now enter java NimblyBimbly to run the program and see its output on the command line.
- Add the output of your program to hw0-output.txt by running
25. java NimblyBimbly >> hw0-output.txt
Oh no. An Error
- We have provided a file (Schools.java) for you that contains some sort of error.
- Attempt to compile and run Schools.java (using javac and java).
- At some point during this process you will encounter an error. Read this error carefully and determine where in Schools.java the error originated. That is, identify which line caused the error. It’s alright if you don’t understand what the error means or how to fix it, but do your best to reason through it and think about it. You will encounter lots of errors as you work through homework for this class, so it’s important that you learn early how to decipher the error messages.
- Finally, report your findings. Open up the hw0-output.txt file from before in your text editor. At the bottom, add two lines.
- The first line should say when the error occurred – that is, during compilation or during running.
- On the second line, first put the number of the line causing the error. Then, copy the line itself.
For example, if you compiled the program successfully, the error happened when you ran it, and line 2 caused the error, you would add
runtime 2. public static void main(String[] args) {
to the file. Be sure to follow the instructions – no extra blank lines, capitalization (or lack of capitalization) as modeled above, etc. Get used to being pedantic about instructions. Computers are nitpicky.
Turn-in Procedure
Submit your hw0-output.txt file on Canvas as an attachment. When you’re ready, double-check that you have submitted and not just saved a draft.
Verify the Success of Your Submission to Canvas
Practice safe submission! Verify that your HW files were truly submitted correctly, the upload was successful, and that your program runs with no syntax or runtime errors. It is solely your responsibility to turn in your homework and practice this safe submission safeguard. NOTE: Unlike TSquare, Canvas will not send an email indicating that your assignment has been submitted successfully. Follow the steps outlined below to ensure you have submitted correctly.
- After submitting the files to Canvas, return to the Assignment menu option and this homework. It should show the submitted files.
- Download copies of your submitted files from the Canvas Assignment page placing them in a new folder.
- Re-run and test the files you downloaded from Canvas to make sure it’s what you expect.
- This procedure helps guard against a few things.
-
- It helps ensure that you turn in the correct files.
- It helps you realize if you omit a file or files. Missing files will not be given any credit, and non-compiling/non-running homework solutions will receive few to zero points. Also recall that late homework will not be accepted regardless of excuse. Treat the due date with respect. Do not wait until the last minute! (If you do discover that you omitted a file, submit all of your files again, not just the missing one.)
- Helps find syntax errors or runtime errors that you may have added after you last tested your code.




