Second Summer 2002


Chapter One Warmups: Some Very High-level Questions.

  1. Explain the difference between using a computer program and programming a computer.

    Using a computer program you are somewhat limited in what you can do with the computer, based on what the program that you're using is offering. Programming (which in effect also boils down to using a computer program, the Java compiler) gives you more freedom, but the amount of detail you need to specify increases. Thus, for example, using Word to write a paper is easy, but you can't use Word to browse the web easily, as with Netscape. Authoring documents with Netscape is not that easy either, because Netscape is mainly a browser.

    But using Java you can write your own browser, or your own word processor, or any other kind of program you want. The amount of work that you will have to do will be significant though, and the task of writing a browser or a word-processor will probably be much more difficult than browsing (or writing in Word) itself. But you have this freedom.

  2. What distinguishes a computer from a typical household appliance?

    To keep things short we can safely say that whatever can be programmed in Java is a computer. If it can't be programmed in Java it is at most an appliance.

  3. Which parts of the computer can store program code? Which can store user data?

    Memory (permanent or temporary) can store both program code (for the machine to run) and user data (for the program to work on it). So can most of the registers in the CPU. The distinction between program code and user data is not that precise, because one person's program code is someone else's user data. For example, think of your code, which is processed by the compiler.

    To summarize we can say that program code can be looked at as user data. (But there is some data that is not program code).

  4. Which parts of the computer serve to give information to the user? Which parts take user input?

    The monitor and the speakers are output devices. The mouse, keyboard, a microfone, and sometimes the monitor (touch screen) can be input devices. There may well be other non-standard input and output devices.

  5. What is the Java virtual machine?

    It is an interpreter: a computer program that runs Java bytecode instructions.

  6. What is an applet?

    An applet is a small program that has already been compiled to bytecode, and can be downloaded over the network, from a web page. Thus it can run on any machine that visits the web page and downloads it.

  7. On your own computer find the exact location (folder or directory name) of

    I am less interested in the actual locations, and very interested in how you found the files. So what I am looking for is an answer of the following kind: on NT, choose Start, Find files and folders, then type the program's name, and push Search, and then in the window that contains the results (all files that match the name) choose the one you're looking for; its full path will be written there.

  8. Explain the special role of the \ escape character in Java character strings.

    It gives a second meaning to each of a certain group of characters, when it precedes them in a string literal. The combination of backslash and the character in question is then interpreted in a certain way. For example, to specify a double quote inside a string you need to protect it, such that Java does not look at it as the end of string character. Same with the escape sequences for newline, tab, etc...

  9. How do you discover syntax errors? How do you discover logic errors?

    Syntax errors are all caught at compile time. Logic errors are difficult to spot, and you only catch them when you obtain unexpected, incorrectly computed results. One avoids logic errors by carefully thinking about the program before starting the implementation, and proving (in a mathematically rigorous way) that for all possible inputs the outputs are correctly computed.

  10. Write an algorithm to settle the following question: a bank account starts out with $10,000. Interest is compounded at the end of every month at 6 percent per year (0.5 percent per month). At the beginning of every month, $500 is withdrawn to meet college expenses after the interest has been credited. After how many years is the account depleted?

    Step 1 Start with the table:

    Month Balance
    0 $10,000.00

    Step 2 Repeat steps 2a, 2b, 2c while the balance is greater than $0.00

    Step 2a. Add a new row to the table.
    Step 2b. In column 1 of the new row, labeled "Month", put one more than the preceding month value.
    Step 2c. In column 2 of the new row, labeled "Balance", place the value of this formula
    b * (1 + 0.005) - 500
    where b is the preceding balance value.

    Step 3 Read the last number in the month column (let's call it months). Report that the account will be depleted in (months / 12) years and (months % 12) months.

  11. Explain the difference between an object and an object reference.

    An object is the real thing, an entity that is otherwise anonymous. An object reference is a (named) location where you keep the address to an object. It is a name for the actual object. For a given object you can have zero or more object references pointing to it.

  12. Explain the difference between an object and a class.

    A class is a factory, or a blueprint. Objects are the gadgets that the factory produces using the blueprint. For example you can play an audio tape with a Sony Walkman (of which there are millions in the world) but you can't do the same with its blueprint (of which there's only one, that model's).

  13. Explain the difference between an object and a method.

    A method is a program, a sequence of instructions, a way of doing things. An object is an entity, an agent, that can contain methods (which is what it does best, just like tiggers).


Last updated: Jul 28, 2002 by Adrian German for A201