Unit 2: Using Objects - Lesson 1: Strings and Class Types

full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/10

flashcard set

Earn XP

Description and Tags

Flashcards covering primitive vs. reference types, String immutability, initialization, and memory behavior from Lesson 1.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

11 Terms

1

What is stored in a primitive variable vs a reference variable in Java?

Primitives store the actual value in the variable's own memory location; references store a memory address (reference) to an object in heap memory.

2

If int x = 35 and String y = "Otters Holding Hands"; then String zz = y; what does zz reference?

zz references the same String object as y (both point to the same data).

3

What is stored in an uninitialized primitive variable and an uninitialized reference variable in Java?

Primitives get a placeholder value (0 for int, 0.0 for double, false for boolean); references get null (meaning no object reference).

4

If int z = x; and later x is set to 70, what are the values of x and z?

z remains the original value (35); x becomes 70 because primitives copy the value.

5

If String y = "Otters Holding Hands"; String zz = y; then y = "So cute!"; what are y and zz now?

y points to the new string 'So cute!'; zz still points to the original 'Otters Holding Hands'.

6

Why do Strings in Java sometimes behave differently from other classes when you reassign them?

Strings are immutable; reassignment creates a new String object instead of modifying the original.

7

What are the three common ways shown to create a String in Java?

1) String alpha = "Cat"; 2) String beta; beta = "Dog"; 3) String kappa = new String("Otter");

8

What does null mean for a reference variable?

Null means there is no object reference; the variable points to nothing.

9

What does 4 bytes (32 bits) memory imply for primitive values?

Memory for primitive types like int uses 4 bytes (32 bits) and can store up to 2^32 distinct values.

10

What is the difference between how memory stores primitive and class types when copying via assignment?

Primitive assignment copies the value; class type assignment copies the reference to the object.

11

How are Strings treated in memory terms compared to other class types as per the lesson?

Strings are stored as references to immutable String objects; modifications create new objects rather than updating the original.