Java Command Sheets
||Prog Design and Devel 1
||Prog Design and Devel 2
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.
Learning to be a proficient programmer involves a variety of skills and knowledge:
- You need to have an accurate mental model variables and computer memory usage.
- You must be able to recall from memory what each individual programming statement does.
- You need to be able to combine programming statements in proper sequence to solve a problem.
- You need to have proficiency in using an editor and a compiler/interpreter.
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.
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:
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:
// swap them!
// see what happened
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:
// swap them!
// see what happened
Victory! Not only did Amy complete the assignment but she accomplished the following:
- She practiced using an editor and compiler.
- It is conceivable that as a brand new programmer Amy might have done
something like this on her first attempt to set one to be 45: one==45;
(because she remembered something about using two equals signs. When she tries
this the program won't compile and she will consult the command sheet and be
reminded of the correct syntax. Next time she will likely remember the correct
syntax because she tried to first recall it before looking it up.
- In her first, incorrect attempt, she was confronted with the fact that her
understanding of variables and their state was incorrect. This caused her to draw
a picture and walk through the program step by step until the error in her
thinking was revealed. She then updates the her mental model to conform to the
reality of what happened.
- In her second (correct) attempt she had to concern herself with ordering
statements correctly. If she had not paid attention to ordering she would have
produced an incorrect result and would then have continued making attempts.
The end result is that after several failing attempts she eventually figures
it out and her brain structure has changed as a result.
Notice that what Amy accomplished enhanced her knowledge and skills ... the same
knowledge and skills needed to be a proficient programmer.
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.
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!