AP Notes, Outlines, Study Guides, Vocabulary, Practice Exams and more!

AP CSA Unit 2 Flashcards

Terms : Hide Images
11910701430Array: .length, Arraylist: .size(), String: .length()How do you find the lenghts of an Array, Arraylist, and String?0
11910748833For loop, while loop, do-while loop, improved for loop/for each loopname of different types of loops1
11910763845ArrayList = easier to add and remove things; Array = difficult to add and remove thingsWhat is one benefit of an ArrayList compared to an Array?2
11910862710For each: for(int x: array)What how would you write a for each loop filled with ints?3
11918452974X: 0 Y: 1079What would the X and Y coordinates be for the bottom left pixel in a 1920x1080 picture?4
11918486254They have a fixed size which can't change after initialization.What is one limitation of arrays?5
11930139054an int stores a number and is a primitive type a String stores an sequence of characters and is an objectWhat is the difference between an int and a String6
11922065877For a user to denote the end of the data set but not part of the data set itself. Ex: Enter -1 to quitWhat is one possible use of sentinel variables?7
119221073381) have a loop that continues until the specific value or values are entered Ex: while (input != -1) 2) create a boolean set to false and have the loop run until a sentinel value is entered, in which case the boolean returns a true and the loop is broken Ex: while (!done)What are two possible ways to implement a sentinel variable?8
11929738875Boolean is easier to use for while loops, for loops allow initialization of variables and conditions, do loops check the condition at the end, so it goes through at least once.What are the advantages a for each loop?9
11929821195denotes the end of a data set, but it is not part of the datadefine sentinel value10
11929830958use ==How do you test if two object references (not values) are identical?11
11931504632A break statement breaks out of a loop and any loop that it may be nested in. A continue statement will follow a condition and move to the next iteration of the loop.What are the purposes of break and continue statements?12
11938172078TrueTrue or False: a constructor is a method that is automatically called when an object is created13
11938604497Input validation is important as all data which is entered into the system needs to be validated in order to ensure that the program will run as intended.Why is input validation important?14
11939091991value comparison works because each value is a primitive type, while trying to compare object references only work if the object reference is compared to itselfWhat is the difference between comparing values and objects?15
11938775146Both arrays would reference the same actual array.Given an array "double[] values = new double[6]", would "double[] prices = values" create a new array or point to the same reference as the other?16
11938816770Use Arrays.copyOf(array, n)- continuing with the example one could do double[] prices = Arrays.copyOf(values, values.length); You could also use this to expand an existing array with new slots by creating a copy with n > values.lengthHow would you make a copy of an array that does not result in a reference to the same array?17
11939680837Relational OperatorsWhat compares values?18
11939702625Boolean variableWhere can you store the outcome of a condition?19
11940446217for (dataType elementVariable : array){ statement; }Format of enhanced for loop20
11940459380An array of arrays. Represents a table of variables with rows and columns.Two-dimensional Arrays321
11940982143Step through the instructions and track the values of each variable.How does one execute a hand trace?22
11941005925'count' only exists in the while loop, it can not be accessed outside of it. For each iteration of the while loop, 'count' is created againWhere does the variable 'count' exist? while (count != 5){ sumOtherRandomCode(); count++ }23
11941061961'i' is not declared. It should be 'int i'. Because the value of i is never less than -20, it will never run.What is wrong with the following code? for (i = 10; i < -20; i ++){ sumRandomCodeHere(); }24
11941087009Input validation, because it runs at least once. Use a sentinel variable to denote the end of a data set.What is a do Loop best for?25
11941144514Use a nested loop. for (int i = 0; i < array.length; i ++) { for (int j = 0; j < array[0].length; j ++) { code; } }How do you traverse through a 2D array?26
11941334931C is the correct answer. A will throw a syntax error (= always goes on RIGHT), B is a boolean, D is an assignment operator.Which of the following operators is a relational operator? A) =< B) ! C) <= D) =27
11941362788Yes, but it only checks whether it refers to the same object. Note that == is only for literals, or numbers. Use str.equals(str2) for strings.Can you use == for Strings?28
11941460147Literals in Java are a sequence of characters (digits, letters, and other characters) that represent constant values to be stored in variables. These are NOT java objects.What is a literal?29
11941479192Primitive types are the most basic data types available within the Java language. There are 8: boolean, byte, char, short, int, long, float and double.What is a primitive value?30
11941498522No, because a String (notice the capital S) is a java object and not a data type.Are strings a primitive value?31
11941464973to test whether two Strings are equal to each other, use the equals method (do not use == operator) or the compareTo method to compare their lexiographic orderComparing Strings32
11941453110The common programming structure that implements "conditional statements".What is an if statement?33
11942134968A set of related classesPackage34
11942168942a method that changes the state of an objectmutator method35
11942176923fetches private data stored within an objectaccessor method36
11942232608A class that gives access to the use of multi-character words, phrases, etc.; does not require an import statementString class37
11942542788Runs ("do") a specified subprocess while a specified condition is true.Do while38
11942550047for(int i=1; i<10; i++){ }What is proper format for a for loop?39
11942866231array.remove(position);How do you remove an element in an array list from a specific position in the array?40
11942931114ArrayList array = new ArrayList();How do you set up an arraylist for a list of Strings?41
11943012279Checks and runs if the condition is met and the program did not go through the previous if/else if statement(s)else if42
11943015364Runs when the program went through none of the if/else if statement(s) above; always placed at the very endelse43
11946303001They are a quick way to check if one variable is equal to many things without having to use a lot of if statementsWhat are switch case statements useful for?44
11946830638Executes certain code for a set number of times (based on a condition)What does a for loop do?45
11946843158Executed certain code while a statement is trueWhat does a while loop do?46
11948825899The name for a class should be a noun and capitalized. It cannot contain special characters or start with a number.What are the guidelines for naming a class?47
11948925221No. If it is only a single operation, it can be converted to a method.Is turning a single operation into a class advisable?48
11949253490Value < 0 = str1 comes before str2 in lexicographic order Value = 0 = str1 and str2 are the same string Value > 0 = str2 comes before str1 in lexicographic orderWhat are the possible return values of the str1.compareTo(str2) method, and what do they represent?49
11949307628Nothing will be stored; the null value represents the lack of an object, not an empty stringIf a String variable str1 is set equal to the "null" value, what String literal will be stored in the variable?50
11951025832doubles have a decimal point.How does a double differ from an int?51
11951037304It can store more dataWhy would one use a long instead of an int?52
11951465263Int, Char, Float, Double, Guassian, booleanName one primitive type53
11951473619A class containing a sequence of charactersWhat is a string54
11951496981Double is a class with methods for doubles while double is a primitive typeWhat's the difference Double and double?55
11951505818Short is a class with methods for shorts while short is a primitive typeWhat's the difference Short and short?56
11951505819Byte is a class with methods for bytes while byte is a primitive typeWhat's the difference Byte and byte?57
11951505820Integer is a class with methods for ints while int is a primitive typeWhat's the difference Integer and int?58
11951505821Long is a class with methods for longs while long is a primitive typeWhat's the difference Long and long?59
11951508694Character is a class with methods for chars while char is a primitive typeWhat's the difference Character and char?60
11951588620Int[][] name;How would you initialize a 2d integer array?61
11951611194[Y][X], also as [row][column]Are arrays indexed [X][Y] or [Y][X]62
11951616011Java.util.Scanner;What class needs to be imported to use a scanner?63
11951713427George.get(5)How do you get value 5 from an ArrayList named George?64
11951733490Random r = new Random(); double q = r.nextDouble();How do you generate a random double?65
11951757612NoIf you remove a value from an array, do the other values shift down?66
11951757613Yes, automatically.If you remove a value from an ArrayList, do the other values shift down?67
11951760298An arraylist.What is an expandable list called.68
11951581427Boolean is a class with methods for the primitive type of booleans.What's the difference between boolean and Boolean?69
11951733269Top leftDoes array[0][0] point to the array's bottom left or top left?70
11951782650You receive an error out of bounds exceptionWhat happens when you call a value outside of an arrays bound.71
11951773770YesShould the names of classes be capitalized?72
11951778090NoShould the names of packages be capitalized?73
11951800668BufferedImageWhat class are images stored in?74
11951801667i++What code increments a for loop with int i?75
11951781627for(int i = 0; i< array.length; i++){ for(int j = 0; j< array.length; j++){ number = array[i][j]; } }How do you iterate through a two dimensional array?76
11951874884A type with two possible values: true and false.Boolean type77
11951881650A loop that is contained in another loopNested loop78

Need Help?

We hope your visit has been a productive one. If you're having any problems, or would like to give some feedback, we'd love to hear from you.

For general help, questions, and suggestions, try our dedicated support forums.

If you need to contact the Course-Notes.Org web experience team, please use our contact form.

Need Notes?

While we strive to provide the most comprehensive notes for as many high school textbooks as possible, there are certainly going to be some that we miss. Drop us a note and let us know which textbooks you need. Be sure to include which edition of the textbook you are using! If we see enough demand, we'll do whatever we can to get those notes up on the site for you!