As mentioned in the first lecture, we assume that you are familiar with some programming language. If that language is not Java, you should read the Java basics tutorial, particularly the sections on Operators, Expressions, statements, and blocks and Control flow statements (including the 6 subsections).
We will not cover this material in lecture.
At the end of last lecture, we saw that variables correspond to "boxes"; values of primitive types are placed directly into the boxes, while values of Object type are placed elsewhere, and their addresses are written into the boxes:
We start by discussing the different types of variables, and how the boxes are organized in the computer's memory.
There are three kinds of variables, which are stored in three different ways:
fields and array entries
x.namethey are accessed by
int. Arrays are a special kind of object; array types are written
The debugger allows you to step through your code line by line, inspecting data on the stack and heap as it executes.
To start the debugger, first set a breakpoint. A breakpoint tells the debugger where to stop. You can set a breakpoint by double-clicking to the left of your code (in the blue bar, by the line number).
You then launch the debugger by clicking the button that looks like a bug, next to the run button:
This will start running your program and switch to the debug perspective. When your program reaches a breakpoint, it will stop, allowing you to inspect the variables in the "Variables" tab. You can also see the different stack frames in the "Debug" tab.
The buttons for controlling execution are found in the toolbar:
The most useful of these are step over, step into, and step return. These cause the execution to execute the next line, jump into the next function, or jump to the return of the current function, respectively.
Methods work the same way!
static methods are like static variables; they are part of the class. Only one version of a static method exists.
non-static methods (could be called dynamic methods, but usually called just methods) are like non-static variables (fields); conceptually, at least, there is one copy of the method with each object of the class. We'll talk more about this tomorrow.