---
tags: Recaps
---
# Recap: Java segment
Here's a summary of essential points from this first segment:
## Java Programming
- All code goes into a class
- Classes contain fields (data) and methods/functions. Generally speaking, the methods operate on the fields of the class, plus any data taken in as parameters
### Types
The valid type names are
- Basic types like `int`, `boolean`, `string`
- Object versions of the basic types: `Integer`, `String`
- Names of any classes, abstract classes, or interfaces
When the type of a field/parameter/variable is a *class*, then Java will allow you to look at any public field or call any (public) method defined in that class.
When the type of a field/parameter/variable is an *interface*, Java will only let you call methods defined in that interface. In particular, you **cannot** dig into the details of a name whose type is given as an interface.
### Inheritence (`extends`)
- If one class is a more specialized version of another, you can have the more specialized class `extend` the more general class. The more specialized class will get all of the fields and methods of the general (parent) class.
- Use `super` to refer to the parent class from within a class
### Interfaces vs Abstract Classes
- Use interfaces to introduce new type names
- Use inheritence to capture general (shared) structure and methods across classes
- Mark a class as `abstract` to prevent anyone from creating objects from it (abstract classes will be extended to define classes for making objects)
- A class can `extend` at most one other class
- A class can `implement` arbitrarily-many interfaces
## Memory Maps
Under the hood, Java separately keeps track of four kinds of information:
- Which classes you have defined
- Which objects you have created (by using `new`) -- this area is called the *heap*
- Which names you have associated with objects or basic values -- this area is called the *environment*
- Where you currently are in the execution of a program
If you are asked to draw a memory map of a program as it runs, you should:
- mark off separate areas for the environment and heap
- add an object to the heap every time your program evaluates an expression that uses `new`
- add a name to the environment any time your program evaluates a statement like `name = ...`