Unit 2 AP Comp Sci A

0.0(0)
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/27

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

28 Terms

1
New cards

What is the class and object of:

String tree = new String(“oak”);

Class: String

Object: tree

2
New cards

Null in Java

Represents an object or class data type that has not been created.

3
New cards

Two basic types of data types in Java

Primitive types and class (reference) types.

4
New cards

Primitive type

Holds only one piece of data at a time (e.g. int,double,boolean)

5
New cards

Class (reference) type

Can hold more than one piece of data at a time and is a blueprint that defines the properties and methods that objects created from it will have.

6
New cards

How primitive data types are stored in memory

As the actual value (e.g., int number 13, stores 13)

7
New cards

How class data types are stored in memory

As a memory address pointing to where the actual value is stored (e.g., String a = "Howdy";).

8
New cards

No reference set for a String

Holds the value null

9
New cards

Strings are immutable

They cannot be changed once created. If you modify a string, a new one is created instead of altering the original.

10
New cards

What would be the output of this code?

String alpha = "Toy Story"; 

String beta = alpha; 

alpha = alpha + " 2"; 

System.out.println(alpha); 

System.out.println(beta);

Toy Story 2

Toy Story

11
New cards

Three ways to create Strings in Java

String alpha = "Wonder Woman";`  

String beta;

beta = "Superman";

String gamma = new String("Spiderman");

12
New cards

+ operator in Java

Concatenates strings and adds integers.

13
New cards

Concatenation with strings

"Glues" two strings together (e.g.

14
New cards

+= operator with strings

combines the two strings into one

15
New cards

Controlling order of operations with strings and integers

By using parentheses

16
New cards

Escape sequences in Java

\" - double quote  

\n - new line  

\t - horizontal tab  

\\ - backslash  

\' - single quote 

17
New cards

Characters stored in a string

Each character is stored with an index starting at 0.

18
New cards

.length() method

Returns the number of characters in the string.

19
New cards

String s = “charizard”;

String t = “charizard”;

s.equals(t)

Tests if two strings are equal (returns true or false).

20
New cards

.substring(start,stop)

gets a part of a string from the start index to the stop index (not including the stop)

21
New cards

.toUpperCase() and .toLowerCase() methods

Convert all letters to uppercase or lowercase

22
New cards

.compareTo(other)

Compares two strings alphabetically.

23
New cards

.indexOf(str)

Searches for a character or string and returns its index position.

24
New cards

Class in Java

"Recipe" for creating objects.

25
New cards

Object in Java

Specific instance of a class.

26
New cards

Example of creating a String object

String tree = new String("oak")

27
New cards

Keyword new in Java

Allocates memory for the new object.

28
New cards

Assigning one object to another

Both variables now point to the same memory location.