1/102
AP Computer Science A Exam - Flashcards to help study and learn material.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What are the System.out.print and System.out.println methods used for?
To send output for display on the console
What is the difference between System.out.print and System.out.println?
The println method moves the cursor to a new line after displaying the given data, while the print method does not.
What is a comment in Java?
Any text in a source code file that is marked to not be executed by the computer
How are single line comments denoted in Java?
//
How are multiline comments demarcated in Java?
/* and */
What are the three primitive types used in AP Computer Science A?
int, double, boolean
What are literals?
Representations in code of exact values
What are the arithmetic operators in Java?
+, -, *, /, %
According to precedence rules, which operators are evaluated first?
*, /, %
According to precedence rules, which operators are evaluated second?
+, -
How are operators within the same group evaluated?
They are evaluated in the order in which they appear in the expression
What are parentheses used for?
To override the default precedence rules
When an arithmetic operation involves two int values, what is the result?
The result is an int, truncating any non-integer part
If an operation involves at least one double value, what is the result?
The result will be a double, behaving as expected mathematically
What is a variable?
A name that is associated with a piece of computer memory that stores a value
What must be declared as being of a certain type?
Every variable that is used in a program
What does A variable declaration statement consists of?
A type followed by a name.
What does an assignment statement have?
A variable on the left side of an equal sign, and an expression on the right side
How can a variable be declared to refer to a value that will never change?
Using the final keyword
If a variable that is declared with final, what error does it cause if you try to change it again?
A compiler error
What is an example of a compound operator?
x += 3
What is an example of an increment operator?
x++
What is an example of a decrement operator?
x--
What casting operators can be used to create temporary values converted to another type?
(int) and (double)
What does casting a double to an int result in?
Truncation
In some cases, what happens to int values?
They are automatically cast to double value
What is the special value reserved for reference variables that do not contain a reference to any actual object?
null
How is interaction with objects primarily done?
Calling their methods
What does it mean when methods can be overloaded?
Multiple methods with the same name that may exist in a class, as long as their signatures are different
When a method is called, what happens to the execution of the program?
The execution of the program is interrupted, and control is transferred to the method
How can void methods only be called?
As standalone statements, rather than as part of an expression
How is a method called?
The dot operator between the name of the object and the name of the method, followed by a list of parameters in parentheses
What will happen if a method is called on a null value?
A NullPointerException to be thrown
When a method is not void, what happens to the method call expression?
It can be used as part of an expression in place of any value of the specified type
How can a single character (as a string) at index n be retrieved?
By calling substring(n, n+1)
Is a String immutable?
Strings are immutable and they have no mutator methods
What wrapper classes does Java provide?
Integer and Double
What features does the Java compiler have that automatically convert between these wrapper classes and the corresponding primitive types?
Autoboxing and unboxing
What is a static method?
A method that is called using the name of the class to which it belongs, rather than an object.
What class is an example of a class that contains only static methods?
Math
What is De Morgan's Laws used for?
To transform Boolean expressions into equivalent ones
What are the operators used to check whether a reference variable is null?
==(equal) and !=(not equal)
How is the equals method called?
Using the dot operator between the name of the object and the equals method, followed by a list of parameters in parentheses
What is used when a program needs to make decisions based on its current state?
Control flow statements
What does an if statement do?
Allows the program to either execute or skip a section of code based on whether a Boolean expression is true or false.
What does an if followed by one or more else if clauses do?
Multiple possibilities
What statement allows a code block to repeat as long as a condition is true?
The while statement
What will happen if the condition in a while loop never becomes false?
The program will be executed infinitely
What does a for loop use?
A variable to count the iterations of a loop
When a loop is used in the body of another loop, what is it referred to as?
Nested loop
What are the basic components of writing classes?
Instance variables, constructors, and methods
What should the visibility be for instance variables?
Private
What should the visibility be for constructors?
Public
What should the visibility be for methods?
Public or private
What is the purpose of a constructor?
To set up an object with some initial state, and generally consists of assigning values to the instance variables
What is a default constructor?
A constructor that does not have any parameters
If a constructor does not explicitly set an instance variable, what happens to the variable?
The variable will automatically be given a default value
What must be true immediately prior to a method being called?
Precondition
What is guaranteed to be true immediately after the execution of the method?
Post condition
What is a method?
A block of code that exists within a class and has access to the instance variables
What values can visibility be when writing a method?
public or private
What is it called when it retrieves and returns data associated with the class but does not modify?
Accessor
To return a value from a method, what statement should be used?
the statement return expression;
What does a return statement do?
Will immediately terminate the execution of the method
What kind of method changes the state of the object in question by modifying one or more of its instance variables?
Mutator
What method implemented in many classes returns a string?
The toString method
What is the parameter as declared within a method header referred?
Formal parameter
What is the value passed in when the method is called?
Actual Parameter
In Java, how are parameters always passed?
Passed by value
What refers to the code within which it is accessible?
Scope
What is declared within the body of a constructor or method?
A local variable
What do you call the type of method that merely retrieves and returns, but does not modify?
Accessor
Where are instance variables declared in a class accessible?
Throughout the entire class
Within a constructor or non-static method, what additional variable is always available?
this
What are associated with a class, rather than with instances of the class?
Static variables and methods
What is an array?
An object that allows a single variable to refer to multiple values of a particular type
What keyword is used to create an array?
new
When an array is created without this, all its elements are automatically initialized with
Default values
What does zero represent?
Minimum valid index in every array
What does array length -1 represent?
Maximum valid index in every array
Use of an index outside of the valid range will cause what error?
ArrayIndexOutOfBoundsException to be thrown
What refers to systematically accessing all elements within it?
Traversing
What type of loop is useful for traversing arrays?
Enhanced for loop
What stores multiple elements of the same type, but differs with arrays as its size is not set at creation and can change dynamically?
Arraylist
What is a standard and universal algorithm used in Arraylist?
Sequential search, or linear search
What is an array of arrays, often thought of as a rectangular array of values, with rows and columns?
2D Array
What represents shared attributes so that code can be shared and reused between the classes?
Inheritance
How many subclasses can a superclass have?
A subclass can only have a single superclass, but a superclass can have many subclasses.
Are constructors inherited from a superclass?
Constructors are not inherited from a superclass
Within a subclass constructor, the super keyword can be used to _ ?
call a superclass constructor
What does the call to the super class constructor need?
The call to a superclass constructor must be the first line in a subclass constructor
What does a subclass inherit?
Inherited all the attributes and behaviors of its superclass, it cannot access private variables or methods from the superclass
What should a string 0 or 1 equal to in a reverse string technique?
Return 1
What is recursion?
A programming technique where a function calls itself in order to solve a problem.
What is a base case in recursion?
The condition that stops the recursive calls and provides a direct solution to the smallest subproblem.
What is a recursive step?
The part of a recursive function where the function calls itself with a modified input, moving towards the base case.
What is the importance of a base case in recursion?
Without a base case, a recursive function would call itself infinitely, leading to a stack overflow error.
What is sorting?
The process of arranging elements in a collection (e.g., array, list) in a specific order (e.g., ascending or descending).
What is a common sorting algorithm that works by repeatedly stepping through the list, compares adjacent elements, and swaps them if they are in the wrong order?
Bubble Sort
What is a sorting algorithm that divides the input array into two halves, calls itself for the two halves, and then merges the two sorted halves?
Merge Sort