Objects with Strings Flashcards

1
Q

Object

A

Is an in-memory data structure that combines state and behavior into a usable and useful abstraction.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Class

A

Source code that defines how to create an object and what state and behavior that object will have.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Steps to instantiate or create an Object from a Class

A
  1. Declare a variable to hold the object. The class will be the data type.
  2. Instantiate a new object from the class using the new keyword.
  3. Initialize variables inside the object with initial values using the constructor.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Data Types Memory

A

Value Type - primitive

Reference Type - Object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Value Type (primitive)

A

Reference a single static space in memory to hold the value. This memory is allocated on the stack.
Only 8 value types: byte, char, short, int, long, float, double, and boolean.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Reference Type (Object)

A

Holds a reference to where the object is located in free-floating, dynamic memory, the heap. Everything except the 8 value types is a reference type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Pass by Value

A

Pass the value of the variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Is Java Pass by Value or Pass by Reference?

A

Java is always Pass by Value. Java passes the value on the Stack when passing a variable to a method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Immutability

A

An object whose state cannot be changed after it is created. A string is immutable, meaning after a string is created the value cannot be changed, but instead, a new String must be created with the new value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Null

A

Not the same thing as empty. Refers to no value on the Stack. Empty refers to the value of an existing object on the Heap.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Object Equality

A

The value of Reference Types (Objects) cannot use == to compare the value of objects, instead they use the .equals() method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Reference Equality ( == )

A

The equality operator compares the value of 2 variables on the stack. For objects, this is the reference to the Object on the heap

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Value Equality ( .equals() )

A

The .equals() method compares the value of Objects on the Heap

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Object characteristics

A
  1. Live in the computer’s memory and only exist while a program is executing.
  2. Is distinct and separate from every other object in a program.
  3. Not written in a source code. Instead, they are what is created when a program executes, based on the source code.
  4. Everything in Java is an Object, except the primitive data types (byte, short, int, long, float, double, boolean, and char).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Class characteristics

A
  1. Is a blueprint for an object.
  2. Classes don’t exist when the program is running, they only exist in source code.
  3. Defines a Data Type, which makes everything in Java a Data Type.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Pass by Reference

A

Pass the memory location of the value.

17
Q

There are 2 types of Equality for Objects in Java

A
  1. Reference Equality ( == ).

2. Value Equality ( .equals() ).

18
Q

Objects behaviors represented by

A

Methods

19
Q

String methods

A

contains( string ), startWith( string)
endsWith( string ), indexOf( string ), replace( string1, string2), toLowerCase()
toUpperCase(), split( str ), equals( string )
equalsIgnoreCase( string ), trim()