Professional Documents
Culture Documents
Lecture 2 CS1101
Lecture 2 CS1101
1101
Lecture
2
Shah Ahmed
Whats
a
func1on?
You
give
a
func1on
something,
and
it
returns
something
else.
For
example,
func1on
1mes
two
I
give
it
3,
it
gives
me
6
Dissec1on
of
a
func1on
Parameters
are
what
I
give
the
func1on
public
sta1c
int
1mesTwo(int
x){
return
2*x;
}
Lets
try
it!
See
Func1onPrac1ce
Object
In
Java,
I
want
to
represent
items
as
code,
like
a
car
We
create
a
blueprint,
then
we
can
create
any
number
of
those
objects
We
have
to
code
up
the
blueprints
Object
Fields
Constructor
Creates
one
instance
of
the
item
Methods, func1ons
Pointers?
References?
Unlike
primi1ve
types
(int,
String),
when
objects
are
made,
variables
are
only
poin1ng
to
it
ONLY
when
we
say
new,
a
new
object
is
created
Very
convoluted
and
very
confusing
Example
Car
Enzo
=
new
Car(Enzo,200);
Car
myCar
=
Enzo;
A
new
car
wasnt
created,
we
have
two
pointers.
Constructor
How
do
we
create
an
object?
Fields
How
do
we
assign
elds?
Change
elds?
This!
Methods
Dierence
of
func1ons
and
processes
How
do
we
call
them?
Arrays
List
of
objects
Array
of
int
is
a
bunch
of
them
Int[]
holder
=
{5,56,33,43,65}
holder[2]
is
33