click below
click below
Normal Size Small Size show me how
AP Comp Sci Midterm
AP Computer Science vocab and review for Semester 1 Midterm
Question | Answer |
---|---|
Syntax Error | Error in program that won't let it run |
Logic Error | Error that runs, but doesn't work the way we wanted it to |
Run-time Error | Program runs/compiles, but then error occurs |
Exception | Something happening, during the run of the code |
Casting | Changing data type of variable |
Modulus Division | A type of division to say the remainder |
Math Class Methods | Methods for rounding, absolute value, random numbers, just about math |
Primitive Data Types (list them) | Char, String, boolean, int, double |
Generating range of random integers using Math.random() | int x = (int)(Math.random()*101); |
Rounding to nearest whole number formula | (int)(x + 0.5) |
Difference between System.out.print() and System.out.println() | System.out.println() enters a new line after |
final | Constant variable, can't be changed |
Difference between int and Double | Int is a whole number, double is decimals |
Postfix Operations | Place operator after operands |
Prefix Operations | Place operator before operands |
Object | An entity in code, sometimes representing an object or concept from the real world, that has a set of attributes and behaviors. The attributes hold specific values; some of them can change while the program is running |
Attributes | Describe features of the class, become fields |
null | Reference has not been assigned, exception Student three = null; so this would result in a null-pointer exception |
Instance Variable | Non - static variables that are declared in the class, outside of methods and constructors, however, the constructor typically takes them in |
Constructor | Allow object to be set up properly when it is created, puts each field into a usable state once it's created, and initializes all fields |
Constructor name | Same name as the class name |
Methods | Block of code, only running when called(unless main), and can take in parameters, does certain actions, mutator, accessor, etc. getGPA(), calculateCost() |
New Operator | operator used to create new objects, it assigns the reference and defines an instance of an object |
No-args Constructor | Constructor with no parameters, will initialize fields to default values, and will be supplied by the compiler if you write a class without a constructor |
Reference | the hexadecimal address of where the object is stored in the computer's memory during the program run, when you use new in driver class and define an instance, the instance is assigned a reference |
void | no return type needed for method, used in method declaration |
Actual Parameter | The parameters used in calling a method or class |
Formal Parameter | The variables declared in the header of the constructor of the class |
Accessor Method | A method that gives you access to private fields of an external class, return the value of a field, getters |
boolean data type | Variable that holds two value types, either true or false |
conditional branching | Logic part, which based on the condition, tells the computer which way the program should go |
relational operators(list them) | < less than, > greater than, <= less than or equal to, >= greater than or equal to, == equal to , != not equal to (there are no spaces between any of the symbols) |
logical operators(list them) | && - AND: all conditions must be true for an && condition to evaluate as true, || - OR: only one condition needs to be true for the || condition to evaluate as true, ! - NOT operator, !(true) = false, !(false) = true |
DeMorgan's Laws (list them) | not(p and q) is the same as not p or not q, not(p or q) is the same as not p and not q, !(p && q) same as !p || !q, !(p || q) same as !p && !q |
short-circuit evaluation | Conditions joined with && must all be true for all to be true, if the first is false, the 2nd doesn't get evaluated. Conditions joined with ||, only one needs to be true for condition = true. |
== comparison of object types | equal to relational operator, if you apply the == to object types, you aren't comparing the object values, but their references, or addresses in memory |
nested if/else statement | When you write code with multiple if/else statements, the else will match up with the closest if, especially if there are no {} to block the code |
String class equals() method | Compares the contents of a String variable. equals() method is used to compare String values. |
String class compareTo() method | compareTo() method is used to compare alphabetical order, parameter is a String, Returns negative if the String comes before the parameter, returns 0 if String is equal to the parameter, returns positive int if the String comes after the parameter. |
Three elements of while loop | Initialization, testing, change |
initialize | To set a variable to a value for the first time. |
increment | Either an operator used for adding 1 to an integer variable, x++ or x+=1, or the process of adding an amount of numbers to your variable in the loop |
decrement | Either an operator used for subtracting 1 to an integer variable, y-- or y-=1, or the process of subtracting an amount of numbers to your variable in the loop |
break | used to break out of loop and go to first line after |
iteration | Repetition of a process, in this case, a loop. A full iteration of a loop is a full run-through of it, and going back to the condition to test if it should run again. |
nested loop | Loop within another loop, inside loop must completely finish before outer loop does |
do while loop | Loop that always runs at least once, tests the condition after the body of the loop, and is great for trapping input. |
while loop | A loop, which, when the condition evaluates to true, the body of the loop executes. It will keep iterating, until the condition is false. |
for loop | Shorthand for the while loop, combines initialization, condition, and change into one statement. |
algorithm | A more or less compact, general, and abstract step-by-step recipe that describes how to perform a certain task or solve a certain problem. Existed long before computers. |
pseudocode | Formal notation to help with recording algorithms. |
flowchart | Graphical representation of an algorithm. Parallelograms represent input and output, rectangles represent processing steps and diamonds represent conditions checked. |
Copy Constructor | This takes one object and creates another object that is equivalent to it. |
Default Constructor | No-args Constructor that is automatically made if you do not have one made for your class/object. all values default |
This | keyword used to reference the object itself, and it helps to clarify when another method is called for the same object. |
primitives passed "by value" | While calling a method, parameters passed to the method will be clones of original parameters. Anything done in the method will have no effect on the original parameters in caller method. |
parameters of object type passed "by reference" | When a variable is pass-by-reference, the unique identifier of the object is sent to the method. Any changes to the parameter's instance members will result in that change being made to the original value. |
method's return statement | Tells method what to return, can be used like a break |
overloaded method | Methods within the same class that have the same name but different numbers or types of parameters. When this is called, the compiler knows which to execute bases on order or type of parameters. (if parameter is int, it is converted to double) |
static fields | Static fields are also called class variables, and they are shared by ALL objects of the class, static implies that the values of the fields do not change each instance, but if a change is made to a static field it changes it for every instance, |
information hiding | Some details of a class are kept hidden from the class's clients, providing as little info to the runner/client class as possible. |
encapsulation | encapsulation is making helper methods private, ensuring that the class can be completely described to outsiders by its public methods and public constructors. They describe what it can do. |
method signature | Method's name and parameter list, the signature of a method call must match the signature in the header for the code to compile. |
static method | This type of method does not access or manipulate the instance variables, only works with static variables(static data applies to every object), static methods are referred to as class methods |
null pointer exception | If you declare a variable of a reference type, and it isn't initialized with the new operator, the value is null, and when executed, the program will throw a Nullpointer exception |
precondition | What conditions are true at the time a method is called |
postcondition | What conditions are true after a method has executed |
one-dimensional array | A variable that holds multiple values of the same data type. |
array subscript | Index used to reference individual compartments(single part/value of an array). Subscript can be number, variable, or an expression in square brackets. |
array .length | A property of an array, returns the number of compartments/values in the array, the size of the array, do not confuse with .length(), which is a method for strings. .length is not a method and specifically for arrays. |
ArrayIndexOutOfBoundsException | An exception that is thrown when you try to reference a compartment that doesn't exist, |
Syntax for declaring a 1-D array | Data type [] identifier = new data type[# of compartments]; |
traverse an array | To access each element of an array, once and processing that element, the for each loop structure can easily traverse |
for each loop | Loop structure that is made for traversing an array, or accessing each element of an array. |
code to total the contents of an int or double array | int total = 0; for(int x: nums) {total += x;} |
code to declare and fill an array in one step | int [] array = {90, 23, 72, 9832, 93939}; |