Unit 2: Using Objects Flashcards Preview

AP CS-Applications > Unit 2: Using Objects > Flashcards

Flashcards in Unit 2: Using Objects Deck (15)
Loading flashcards...
1

What is the keyword "new" ?

The "new" keyword is used to creat a new object.

2

Proper String initialization

String myString = new String("Hello, World!");

3

Overloading

In Java, two or more methods may have the same name if they differ in parameters (different number of parameters, different types of parameters, or both). This is called overloading.
Ex.
public Rectangle(int rectWidth, int rectHeight)
{
width = rectWidth;
height = rectHeight;
}

public Rectangle(int sidelength)
{
width = sidelength;
height = sidelength;
}

4

What are parameters?

The name given to data passed into a method

5

Wrapper Classes

Wrapper classes provide a way to use primitive data types (int, boolean, etc..) as objects.

6

Integer.parseInt()

This method is used to get the primitive data type of a certain String.
Ex. Integer.parseInt("11"); // Returns the int value 11

7

Generating random numbers using Math

int randInt = (int) (Math.random() * (max - min) + min;

8

What is an instance method?

A piece of code called on a specific instance (an object) of the class.

9

What is a void method?

A void method is a method that does not have a return value. Usually, these contain a print statement or modify the variables within the object in some way.

10

What defines a non-void method?

Non-void methods have a return statement. The method returns a certain data type and can be used as a variable of that data type.

11

What is an Integer? What is its purpose?

A wrapper class that helps turn a primitive into an object and object into a primitive data type.

It can be used in lists and such because they only store data as objects, so the conversion from primitive to object is needed.

12

Static Methods

Belong to the class rather than the object of a class, therefore can be called without using an object.

13

What are the different sting methods?

name.concat("value") - returns a new string with "value" appended at the end of name
name.replace("a", "p") - returns a new string with all instances of "a" in name replaced with "p"
name.toUpperCase()- Returns name as Upper Case Letters

14

Can you change a string once it is created?

No! Strings are immutable, so they cannot be changed once they are created.
(If you wanted to change the value of a string, you would have to re-assign it!)

However, you can concatenate strings with one another to create a new string value!

15

What are the different types of escape sequences?

\" - allows for quotations
\\ - includes a backslash
\n - creates a line break
\t - adds a tab space