1
h00
CS56 M16
Name:
(as it would appear on official course roster)
Umail address: @umail.ucsb.edu section
9am or 10:30am
Optional: name you wish to be called
if different from name above.
Optional: name of "homework buddy"
(leaving this blank signifies "I worked alone"

h00: HFJ 1,2: Java basics

ready? assigned due points
true Tue 06/21 09:30AM Wed 06/22 09:30AM

You may collaborate on this homework with AT MOST one person, an optional "homework buddy".

MAY ONLY BE TURNED IN IN THE LECTURE/LAB LISTED ABOVE AS THE DUE DATE,
OR IF APPLICABLE, SUBMITTED ON GRADESCOPE. There is NO MAKEUP for missed assignments;
in place of that, we drop the three lowest scores (if you have zeros, those are the three lowest scores.)


READING ASSIGNMENT

Throughout the quarter, when I refer to HFJ, this means your Head First Java, 2nd Edition textbook.

  1. (10 pts) Please fill in the information at the top of this homework sheet, including your name and umail address. Put the time your discussion section starts (either 9am or 10:30am) in the space indicated. If the other two items apply, please fill them in as well. Please do this every single time you submit homework for this class.
  2. (10 pts) If you didn't do it yet: For a variety of reasons, we will be using github.com (rather than github.ucsb.edu) for this course. So, please, if you have not done it yet * create your github.com username and password (free account) at github.com * fill in the form at: http://bit.ly/cs56-w16-githubform Points will be awarded if you do this by the time this homework is graded. If not, you'll still have to do it, but you wont get those points back.
  3. (10 pts) According to chapter two, anytime you need to test a class in Java, you need at least two classes. (As we'll discuss in lecture, this isn't strictly true, but let's go with it for now.) In the (oversimplified) view the author is presented (it is just chapter two, after all,) what are the two roles that these two classes are playing? Idenfity the roles, and explain each briefly,
  4. (10 pts) Throughout the book, some important material is sometimes in the little "side boxes" and dialogues. It's important to read everything on every page. One of these little side-boxes contains some important information about the "heap" in Java, and how it differs from the heap in C++. (C++ is not specifically mentioned, but from taking CS32, you should know about how the heap works in C++.) Briefly explain what the authors tell us about the heap in Java—something that is definitely different from the heap in C++.
  5. (10 pts) Explain briefly the relationships between/among (a) source code, (b) the Java Compiler, (c) Java bytecodes, and (d) JVM. You get full credit if you write a sentence (or a few sentences) that make it clear you understand how each of these relates to the big picture, and to the other three. To ensure full credit, *DO NOT JUST COPY TEXT FROM THE BOOK*. Put this in your own words. I should get at least a slightly different answer from each student (or pair of homework buddies.)
  6. (20 pts) On page 5 and 6, there is a set of exercises, and the answer to those. Here is a similar set of exercises, but the answer are not provided. Fill in the blanks.
    java code explanation
    boolean cs56IsAwesome= true;
     
    Course c = new Course("CMPSC56","W16");
     
    String thisQuarter = "M16";
     
    if (c.getQuarter().equals(thisQuarter))
     
  7. (20 pts) Now, the same kind of exercise, but in reverse---I give you the description, you give me the code. These are designed that you should be able to just reason them out from the examples of Java code given on p.4 and p.5, and your general programming background from CS16 and CS24 in C/C++---no other knowledge of Java should be needed.
    java code explanation
     
    declare a variable that indicates whether this year is a leap year or not, and initialize it to say that it is not a leap year
     
    declare a variable item of type MenuItem, and initialize it to a "Caesar Salad" that costs 8.95. Assume those are the two parameters that the constructor takes.
     
    declare a variable of type double called total
     
    an assignment statement that calls the method getPrice on the variable item and adds the result into the variable total
  8. (10 pts) In Chapter 2, the author describes two different approaches to a problem—one taken by "Larry", and the other taken by "Brad". Based on what you read here, and in your own words, how would you characterize the main difference between the two approaches?