AP Computer Science A - Unit 1.9-1.15

0.0(0)
studied byStudied by 0 people
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/31

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

32 Terms

1
New cards

argument

value that is passed into a method when the method is called

  • must be compatible in number and order with the types identified in the parameter list of the method signature.

method(9,10,11)

<p>value that is passed into a method when the method is called</p><ul><li><p>must be compatible in number and order with the types identified in the parameter list of the method signature.</p></li></ul><p></p><p><code>method(9,10,11)</code></p><p></p>
2
New cards

attribute/instance variable

data the object knows about itself.

  • turtle object knows the direction it is facing or its color.

    • Shape, Color, Height, Width, Direction, etc.

<p>data the object knows about itself.</p><ul><li><p>turtle object knows the direction it is facing or its color.</p><ul><li><p>Shape, Color, Height, Width, Direction, etc.</p></li></ul></li></ul><p></p>
3
New cards

boolean equals(Object other)

returns true when the characters in the current string are the same as the ones in the other string. This method is inherited from the Object class, but is overridden which means that the String class has its own version of that method.

"Test string".equals("test string 1")

<p><mark data-color="yellow" style="background-color: yellow; color: inherit;">returns true when the characters in the current string are the same as the ones in the other string</mark>. This method is inherited from the Object class, but is overridden which means that the String class has its own version of that method.</p><pre><code>"Test string".equals("test string 1")</code></pre><p></p>
4
New cards

call by value

initializes the parameters with copies of the arguments.

  • Copying the value, not the actual variable

  • Refers to a location value, not the actual thing

<p>initializes the parameters with copies of the arguments.</p><ul><li><p><mark data-color="yellow" style="background-color: yellow; color: inherit;">Copying the value, not the actual variable</mark></p></li><li><p>Refers to a location value, not the actual thing</p></li></ul><p></p>
5
New cards

class

defines the attributes (data) and behaviors (methods) that all objects of that class will have

  • The objects are the specific instances of the class that have their own values for the attributes

  • Attributes: the data or properties that an object knows about itself

    • turtle object's color and size

  • Behaviors: things an object can do

    • turtle object's ability to play, jump, run, etc.

public class MyClass {

}

<p><u>defines the attributes (data) and behaviors (methods)</u> that <mark data-color="yellow" style="background-color: yellow; color: inherit;">all objects of that class will have</mark></p><ul><li><p>The objects are the specific instances of the class that have their own values for the attributes</p></li></ul><p></p><ul><li><p>Attributes: the data or properties that an object knows about itself</p><ul><li><p>turtle object's color and size</p></li></ul></li><li><p>Behaviors: things an object can do</p><ul><li><p>turtle object's ability to play, jump, run, etc.</p></li></ul></li></ul><p></p><p><span>    </span><code>public class MyClass {</code></p><p><code>}</code></p>
6
New cards

concatenation

Adding String(s) to each other to create a new string using the + or += operator

String name = "John";
int age = 25;
System.out.println("My name is " + name + " and I am " + age + " years old.");
String firstName = "John ";
String lastName = "Doe";
System.out.println(firstName.concat(lastName));

<p><mark data-color="yellow" style="background-color: yellow; color: inherit;">Adding String(s) to each other</mark> to create a new string using the + or += operator</p><p></p><pre><code>String name = "John";
int age = 25;</code></pre><pre><code>System.out.println("My name is " + name + " and I am " + age + " years old.");</code></pre><pre><code>String firstName = "John ";
String lastName = "Doe";
System.out.println(firstName.concat(lastName));</code></pre><p></p>
7
New cards

constructor signature

consists of the constructor's name, which is the same as the
class name, and the ordered list of parameter types.

  • World, width, height

World world1 = new World();

World world2 = new World(width,height);

<p>consists of the <mark data-color="yellow" style="background-color: yellow; color: inherit;">constructor's name</mark>, which is the same as the<br>class name, <mark data-color="yellow" style="background-color: yellow; color: inherit;">and the ordered list of parameter types</mark>.</p><ul><li><p>World, width, height</p></li></ul><p><code>World world1 = new World();</code></p><p><code>World world2 = new World(width,height);</code></p>
8
New cards

constructors

Special methods used for the creation of an Object

  • Constructors have the same name as the class.

  • typically created using the keyword "new" followed by a call to one of the class's constructors

    • new ClassName()

    • //Constructor here is ClassName

9
New cards

dot operator

access classes and objects

  • also known as separator or period used to separate a variable or method from a reference variable.

ClassName objectName = new ClassName();

objectName.fieldName; // Accesses the field 'fieldName' of 'objectName'

10
New cards

index

a number associated with a position in a string

  • Each character is at a position or index that starts with 0

  • The length of a string is the number of characters in it, including any spaces or special characters

<p>a number associated with a position in a string</p><ul><li><p>Each character is at a position or i<mark data-color="yellow" style="background-color: yellow; color: inherit;">ndex that starts with 0</mark></p></li><li><p>The length of a string is the number of characters in it, including any spaces or special characters</p></li></ul><p></p>
11
New cards

int indexOf(String str)

method searches for the string str in the current string and returns the index of the beginning of str in the current string or -1 if it isn't found.

String s1 = "someone is a baby";
int s2 = s1.indexOf("baby"); //will return 13

12
New cards

int length()

method returns the number of characters in the string, including spaces and special characters like punctuation.

String s1 = "baby";
int s2 = s1.length(); //will print 4

13
New cards

intl compareTo(String other)

returns a negative value if the current string is less than the other string alphabetically, 0 if they have the same characters in the same order, and a positive value if the current string is greater than the other string alphabetically

  • before alphabetically = less than

  • negative = less than

  • 0 = the same,

  • positive = greater than

String s1 = "baby";
String s2 = "child";
System.out.println(s1.compareTo(s2)); //will a negative num

14
New cards

Math.abs method

takes a single argument, either a double or an int and returns a value of the same type which is the absolute value of the argument

  • The absolute value is the positive value of the number without its sign or its distance from 0

Math.abs(-4) = 4

15
New cards

Math.pow

takes two argument, both doubles and returns a double which is the first argument raised to the power of the second argument.

Math.pow(2,3); //returns 8.0

16
New cards

Math.random() method

used to generate a random number

int n = (int)(Math.random()*3)+3;
  • multiplying by three: [0,1) -> [0,3)

  • adding by three: [0,3) -> [3,6) // last value isn't included

17
New cards

Math.sqrt method

takes one double argument and returns a positive double value which is the square root of the argument

Math.sqrt(9); //returns 3

18
New cards

method

named block of code that only runs when it is called

<p><mark data-color="yellow" style="background-color: yellow; color: inherit;">named block of code</mark> that <u>only runs when it is called</u></p>
19
New cards

method call

interrupts the sequential execution of statements, causing the program to first execute the statements in the method before continuing

20
New cards

method signature

defines the method's name and the number and types of parameters it takes

  • A method signature for a method without parameters consists of the method name and an empty parameter list

println();
println("Hello World");

<p>defines the <mark data-color="yellow" style="background-color: yellow; color: inherit;">method's name and the number and types of parameters</mark> it takes</p><ul><li><p>A method signature for a method without parameters consists of the method name and an empty parameter list</p></li></ul><pre><code>println();
println("Hello World");</code></pre><p></p>
21
New cards

no-argument constructor

a constructor that doesn't take any passed-in values (arguments)

  // Explicitly defined no-argument constructor
        public MyClass() {
            this.name = "Default Name";
            this.age = 0;
            System.out.println("No-argument constructor called.");
        }

        // Parameterized constructor
        public MyClass(String name, int age) {
            this.name = name;
            this.age = age;

22
New cards

object

is a specific instance of a class with defined attributes

    ClassName objectName = new ClassName(); // For a default constructor
    ClassName objectName = new ClassName(arguments); // For a parameterized constructor

<p>is a specific <mark data-color="yellow" style="background-color: yellow; color: inherit;">instance of a class </mark>with <u>defined attributes</u></p><pre><code>    ClassName objectName = new ClassName(); // For a default constructor</code></pre><pre><code>    ClassName objectName = new ClassName(arguments); // For a parameterized constructor</code></pre><p></p>
23
New cards

overloaded methods

multiple methods with the same name but different signatures.

  • Parameters have to be the same as what is called in the method

  • One method can share multiple parameters (int, double, boolean, etc)

<p><mark data-color="yellow" style="background-color: yellow; color: inherit;">multiple methods </mark>with the <u>same name but different signatures</u>.</p><ul><li><p>Parameters have to be the same as what is called in the method</p></li><li><p>One method can share multiple parameters (int, double, boolean, etc)</p></li></ul><p></p>
24
New cards

parameter

a variable declared in the header of a method or constructor

  • can be used inside the body of the method

  • allows values or arguments to be passed and used by a method or constructor
    (int x, int y)

<p>a variable declared in the header of a method or constructor</p><ul><li><p>can be used inside the body of the method</p></li><li><p><mark data-color="yellow" style="background-color: yellow; color: inherit;">allows values or arguments to be passed and used</mark> by a method or constructor<br>(int x, int y)</p></li></ul><p></p>
25
New cards

parameter list

in the header of a constructor, lists the types of the values that are passed and their variable names.

<p>in the header of a constructor,<mark data-color="yellow" style="background-color: yellow; color: inherit;"> lists the types of the values that are passed and their variable names</mark>.</p>
26
New cards

Procedural abstraction

allows a programmer to use a method by knowing what the method does even if they do not know how the method was written.

27
New cards

reference type

holds an object reference or null if there is no object

  • classes 

  • Interfaces

  • Arrays 

  • Enums

28
New cards

Signature

Defines a Method (method name + parameter)

Verse(String animal, String sound)
triple(int n)

<p><mark data-color="yellow" style="background-color: yellow; color: inherit;">Defines a Method</mark><u> (method name + parameter)</u></p><pre><code>Verse(String animal, String sound)</code></pre><pre><code>triple(int n)</code></pre><p></p>
29
New cards

string literal

a set of characters enclosed in double quotes ("),

  • creates a String object.

String greeting = Hello;

30
New cards

string object

use the new keyword followed by a space and then the class constructor and then in parentheses you can include values used to initialize the fields of the object

String greeting = new String("Hello");

31
New cards

String substring(int from, int to)

method returns a new string with the characters in the current string starting with the character at the from index and ending at the character before the to index (if the to index is specified, and if not specified it will contain the rest of the string)

String s1 = "baby";
String s2 = s1.substring(0,2); //will return ba

32
New cards

variable

holds an object reference, which can be thought of as the of that object.

  • named storage location in memory used to hold a value

<p><mark data-color="yellow" style="background-color: yellow; color: inherit;">holds an object reference</mark>, which can be thought of as the of that object.</p><ul><li><p><span>named storage location in memory used to hold a value</span></p></li></ul><p></p>