Lecture 2

0.0(0)
studied byStudied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/19

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 2:11 AM on 7/28/25
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

20 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

15
New cards

Arrays.sort()

is a method used to sort elements in an array in ascending order. It can also sort arrays of objects that implement the Comparable interface.

16
New cards

s.toCharArray()

is a method that converts a string into an array of characters.

17
New cards

Arrays.toString()

is a method that returns a string representation of the contents of an array, displaying its elements in a readable format.

18
New cards

‘==’ vs .equals()

The ‘==’ operator compares reference equality, checking if two references point to the same object, while the .equals() method checks for value equality, determining if two objects are logically equivalent.

19
New cards

constructors

are special methods used to initialize objects in a class, setting initial values for instance variables. Every class must have a constructor. haven’t created one yet, but Java
synthesizes a default, empty constructor
for you if you don’t provide your own. • A constructor looks like a method.
• The name of a constructor must
match the name of the class

20
New cards

Explore top flashcards