1
h00
CS56 W18
Name:
(as it would appear on official course roster)
Umail address: @umail.ucsb.edu section
4pm, 5pm or 6pm
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 01/16 11:00AM Thu 01/18 11:00AM

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 four lowest scores (if you have zeros, those are the four 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 (4pm, 5pm or 6pm) in the space indicated (the one you are registered for—even if you usually attend a different one.) 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 both github.ucsb.edu and github.com for this course. So, please do all of the following by the time you hand in this homework in lecture (but sooner if possible):

    • Login once to github.ucsb.edu to establish your account there (use your CSIL/ECI/CoE Unix account)
    • Create your github.com username and password (free account) at github.com.
      • Be sure that your username@umail.ucsb.edu address is at least one of the email addresses associated with your github.com account, and that this email address is a “verified” email address. (It doesn’t have to be your primary github.com email address; it just has to be one of them.)
      • Please visit https://ucsb-cs56-w18-signup.herokuapp.com and login there with your github.com id. This will add you to a “github organization” for the course.

    Points will be awarded if you do all of the above by the time this homework is graded. Points may be deducted if any or all of it isn’t done. (You’ll still eventually 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","W18");
     
    String thisQuarter = "W18";
     
    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?