Skeleton (hierarchy) of a Class
/* Package declaration */
/* Import declarations */
class House {
/* Field declarations */
/* Constructors */
/* Methods */
Why should an object should hide its implementation details?
Classes should present their users with an interface that
Encapsulation: Classes and Users
Classes should allow you to change the internal representation without affecting users
A good problem solving strategy: Divide and Conquer
Understand problem, find tools, break into small problems.
Java Strategy: Imaginary Methods
Typically, a solution to a problem of reading, manipulating or writing information is a method.
When writing one method, if you need to do a sub-task that is too complex to solve straight-away.. .
Compile after each method
What to keep in mind when designing methods (even for imaginary):
!! variables constrained within some local scope.
• method input arguments…. . . within method definition
• locally defined variables…. . . until the end of method
• this object . . .
. . . within an instance method
• variables initialised in a for-loop. . .. . . within the for-body
due to local scope, within a method block can only directly access local parts of the stack, but….
. . . but ‘this’ allows you to access the owning object
. . .‘return’ variables allow information to escape the local scope
instance methods
a method that is invoked on a specific object, requesting the object to do something, and maybe changing the object’s state on the way
x = myCircle.area();
instance attributes/fields
myCircle.diameter;
static methods
aka class methods

static fields
aka class variables
Only one static object is created per class– not one per object

Static Fields as Global Variables: Global object references
System.out is a global object reference
static fields usually declared final or not?
yes, they don’t change
how to make methods global
static can be used to make methods global
(static methods, like static fields, are underlined in UML)
5 features of Arrays
Consequences of pass-by-value:
Method arguments are passed-by-value.
Can a method alter the elements of an array without having to return anything (void)
yes.
what is a recursive method?
A recursive method is one that includes a call to itself
!! All recursive methods must have the following:
good use case for recursive methods
If a problem can be reduced to smaller instances of thesame problem, then a recursive solution is likely to be easy to find and implement.
A recursive method definition normally contains 2 kinds of cases:
◦ one or more base cases without recursive calls
◦ one or more cases that include at least one recursive call
Abstraction
Abstraction is a process of hiding the implementation details and showing only functionality to the user.