Starting from:

$30

CS1331-Homework 0 Java Source Code Solved

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
IMPORTANT: We do not use integrated development environments (IDEs) in this class. You must use the command line and a text editor to edit, compile, and debug your Java code.

Problem Description
You are a 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 folder. Enter these commands (remember that ‘$’ is the shell prompt (something like ‘C:’ on Windows) – don’t type the shell prompt character(s)):

$ javac -version hw0-output.txt
$ 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 NimblyBimbly.java and enter the following Java program:

public class NimblyBimbly {
public static void main(String[] args) {
for (int i = 0; i < 9; i++) {
System.out.print("\u004D\u0065\u006F\u0077 ");
}
System.out.println("...");
System.out.println("\u004D\u0065\u006F\u0077\u0021");
}
}

On the command line, go to the directory containing your newly created NimblyBimbly.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:

Mac / Linux:

$ javac NimblyBimbly.java
$ ls
NimblyBimbly.class NimblyBimbly.java hw0-output.txt ...

Windows:

C:\...\cs1331\hw0 javac NimblyBimbly.java
C:\...\cs1331\hw0 dir
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

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

More products