Unit 2 AP Comp Sci A

studied byStudied by 0 people
0.0(0)
Get a hint
Hint

What is the class and object of:

String tree = new String(“oak”);

1 / 27

28 Terms

1

What is the class and object of:

String tree = new String(“oak”);

Class: String

Object: tree

New cards
2

Null in Java

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

New cards
3

Two basic types of data types in Java

Primitive types and class (reference) types.

New cards
4

Primitive type

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

New cards
5

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.

New cards
6

How primitive data types are stored in memory

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

New cards
7

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";).

New cards
8

No reference set for a String

Holds the value null

New cards
9

Strings are immutable

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

New cards
10

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

New cards
11

Three ways to create Strings in Java

String alpha = "Wonder Woman";`  

String beta;

beta = "Superman";

String gamma = new String("Spiderman");

New cards
12

+ operator in Java

Concatenates strings and adds integers.

New cards
13

Concatenation with strings

"Glues" two strings together (e.g.

New cards
14

+= operator with strings

combines the two strings into one

New cards
15

Controlling order of operations with strings and integers

By using parentheses

New cards
16

Escape sequences in Java

\" - double quote  

\n - new line  

\t - horizontal tab  

\\ - backslash  

\' - single quote 

New cards
17

Characters stored in a string

Each character is stored with an index starting at 0.

New cards
18

.length() method

Returns the number of characters in the string.

New cards
19

String s = “charizard”;

String t = “charizard”;

s.equals(t)

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

New cards
20

.substring(start,stop)

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

New cards
21

.toUpperCase() and .toLowerCase() methods

Convert all letters to uppercase or lowercase

New cards
22

.compareTo(other)

Compares two strings alphabetically.

New cards
23

.indexOf(str)

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

New cards
24

Class in Java

"Recipe" for creating objects.

New cards
25

Object in Java

Specific instance of a class.

New cards
26

Example of creating a String object

String tree = new String("oak")

New cards
27

Keyword new in Java

Allocates memory for the new object.

New cards
28

Assigning one object to another

Both variables now point to the same memory location.

New cards

Explore top notes

note Note
studied byStudied by 132 people
... ago
5.0(1)
note Note
studied byStudied by 55 people
... ago
4.5(2)
note Note
studied byStudied by 7 people
... ago
5.0(1)
note Note
studied byStudied by 30 people
... ago
5.0(1)
note Note
studied byStudied by 37 people
... ago
5.0(1)
note Note
studied byStudied by 6 people
... ago
5.0(1)
note Note
studied byStudied by 16 people
... ago
5.0(1)
note Note
studied byStudied by 23129 people
... ago
4.8(187)

Explore top flashcards

flashcards Flashcard (21)
studied byStudied by 4 people
... ago
5.0(1)
flashcards Flashcard (93)
studied byStudied by 13 people
... ago
5.0(2)
flashcards Flashcard (27)
studied byStudied by 5 people
... ago
5.0(1)
flashcards Flashcard (58)
studied byStudied by 4 people
... ago
5.0(1)
flashcards Flashcard (83)
studied byStudied by 8 people
... ago
5.0(1)
flashcards Flashcard (30)
studied byStudied by 1 person
... ago
5.0(1)
flashcards Flashcard (22)
studied byStudied by 2 people
... ago
5.0(1)
flashcards Flashcard (68)
studied byStudied by 29 people
... ago
5.0(2)
robot