Lecture 2

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/13

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

14 Terms

1
New cards

What type is an array in Java?

Arrays in Java are homogeneous: Can only hold items of a single type

2
New cards


For-each

• e will take the value of each
element in the array nums.
• Written this way, the loop will
automatically go through each
element in nums.
• Don’t need to keep track of index
or conditions, it’s done for us.

3
New cards

what does clone() do?

The clone() method in Java creates a copy of an array or object, duplicating its elements and structure. This allows for independent manipulation of the cloned object without affecting the original.

4
New cards

What does == do?

• When we use == with objects, we test object equality.
• “Are these two variables referring to the same object?”
• Declaring arrays with identical literals yields different objects

5
New cards

What do use to check content equality?

Use Arrays.equals()

6
New cards

What is a class?

A Class is a blueprint for creating objects

7
New cards

What are objects?

If the class is the blueprint, the actual car is the object.
Objects are instances of Classes:
• A string object is an instance of the String class
in the same way that 7 is an instance of int
• Classes may implement methods (behaviors)
that their objects can invoke.
• I.e. subString(), charAt(), etc. from String class

8
New cards

Access specifier: private

Access specifier:
• Private means this variable cannot be
accessed from outside the Counter class.
Let’s add some properties and behaviors to Counter

9
New cards

Access specifier: Public

Access specifier:
Public means this method can be
accessed from outside the Counter class

10
New cards

Mutator

Also known as the setter method. Modifies object data

11
New cards

Accessor

Also known as the getter method. Retrieves object data.

12
New cards

Set method

• Set methods ensure all possible operations upon the data fields of a given class fall within the intended domain of that class

13
New cards

Constructors

A constructor can be used to initialize
object values or perform some behavior
upon object creation.
Every class must have a constructor. We
haven’t created one yet, but Java
synthesizes a default, empty constructor
for you if you don’t provide your own. • When we use new to create an object, we invoke its constructor.

14
New cards

Can two methods have the same name

Two methods can have the same name IF
their parameter lists are different