This assignment gets you started with the basic tools you will need to complete all of your homework projects. This project will:
- Ensure that you have correctly installed the JDK (Java Development Kit)
- Give you practice using a text editor to write Java programs
- Give you practice compiling and running Java programs
- Give you practice identifying and locating an error
- Show you a bit of command line fun
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 programmers text editor to create and edit Java source code.
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, youll 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(u004Du0065u006Fu0077 );6. }7. System.out.println();8. System.out.println(u004Du0065u006Fu0077u0021);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:cs1331hw0> javac NimblyBimbly.java21. C:cs1331hw0> 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
- 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. Its alright if you dont 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 its 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.
Reviews
There are no reviews yet.