Java Command Sheets

Program Design and Development 1 and 2/p>

Java Command Sheets

  CSCI 1320 CSCI 2320
  Prog Design and Devel 1 Prog Design and Devel 2
with commentary pdf format ps format pdf format ps format
without commentary pdf format ps format pdf format ps format

*Command Sheets and Page Content by Dr. Terry Sergeant

What are Command Sheets?

The command sheets contain a list of Java code snippets that represent most (perhaps all) of the Java commands needed in order to complete every assignment in HSU's two introductory programming courses. We encourage each student to independently complete every homework assignment by referring only to the assignment instructions and the command-sheet for the course (and if necessary the official Java language documentation found at https://docs.oracle.com/javase/8/docs/). In addition, students will be allowed to access the command sheet (without commentary) when taking exams.

Purpose

Learning to be a proficient programmer involves a variety of skills and knowledge:

In order to gain this knowledge you need to be exposed to it and then repeatedly try to recall it (without looking it up). And to become proficient with these skills you need to practice them.

Consider this simple problem we pose to a ficticious student who we'll call “Amy”:

Suppose two variables named one and two (of type double) contain distinct values. Write a program that will swap the contents of the two variables.

Approach #1 (Good)

As Amy thinks about this problem she correctly concludes that by the time the program ends the variables one and two will need to have been changed from their original values. She also, correctly recalls that to change a variable's value in Java she must use the “assignment operator” (i.e., =) which will take the value on the right and put it into the variable on the left. So, Amy knows at a minimum her program will have two statements like this:
            one= ??
            two= ??
            

She also knows that to test her program she'll need to declare the variables and give them initial values. Then she'll try to swap and print them out to see what happens. So, in her first attempt she creates this code segement:

            double one,two;
            one= 45;
            two= 78;

            // swap them!
            one= two;
            two= one;

            // see what happened
            System.out.println(one);
            System.out.println(two);
            

When she compiles and runs the program she is surprised by the fact that the output is 78 for both variables! To understand why she draws boxes for each variable and manually traces her program. A light comes on when she encounters the statement one= two; and finds that upon completion of that statement both boxes contain the value 78! That explains why the following statement (two= one;) ends with both variables still being 78.

Amy takes a moment to find a way around this problem. It dawns on her that she will need a third variable to hold one of the values (just like she'd need a third cup if she wanted to swap contents of two cups of liquid). She then tries this code segment:

            double one,two,temp;
            one= 45;
            two= 78;

            // swap them!
            temp= one;
            one= two;
            two= temp;

            // see what happened
            System.out.println(one);
            System.out.println(two);
            

Victory! Not only did Amy complete the assignment but she accomplished the following:

Notice that what Amy accomplished enhanced her knowledge and skills ... the same knowledge and skills needed to be a proficient programmer.

Approach #2 (Bad)

Suppose, instead Amy begins the assignment by performing an internet search: “how to swap two variable in Java”. She finds a complete working example and types it in. Not surprisingly it works and she is done with the assignment. Although both approaches yield a completed homework assignment this approach only enhanced one of the skills needed to be a proficient programmer: using an editor and compiler.

Conclusion

By providing a command summary we provide our students with a ready resource, which when used to the exclusion of other resources, results in the skills needed to be a proficient programmer. Of course, there are times when a student may want to go “above and beyond” for a particular assignment and so may need to access other resources. We are not discouraging this practice. We do, however, want our students to first do the basic assignment without external aids. Then they are free to experiment, read, learn, grow as much as they'd like!

.