Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

AP Computer Science A: Java Fundamentals, Exams of Computer Science

A comprehensive review of essential java programming concepts for ap computer science a students. Topics covered include the structure of a java program, identifiers, primitive types, variables, methods, exceptions, and more. It also includes coding examples and explanations of key terms and concepts. This document serves as a valuable resource for students preparing for the ap exam.

Typology: Exams

2023/2024

Available from 05/08/2024

star_score_grades
star_score_grades 🇺🇸

3.6

(19)

1.7K documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
AP Computer Science A edhesive term
A Java program must have at least ___ class(es). -
Answer>> 1
The java files that comprise your program are
called... - Answer>> source files
A __________ converts source code into a machine
readable form. - Answer>> compiler
All Java methods must be contained in a(n)... -
Answer>> class
All program statements must be placed inside a(n)...
- Answer>> method
The keyword _____ signals that the class or method
is usable outside the class. - Answer>> public
The keyword ____ signals data or methods are not
usable outside the class. - Answer>> private
The ________ method must always be static. -
Answer>> main
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download AP Computer Science A: Java Fundamentals and more Exams Computer Science in PDF only on Docsity!

AP Computer Science A edhesive term

A Java program must have at least ___ class(es). - Answer>> 1 The java files that comprise your program are called... - Answer>> source files A __________ converts source code into a machine readable form. - Answer>> compiler All Java methods must be contained in a(n)... - Answer>> class All program statements must be placed inside a(n)...

  • Answer>> method The keyword _____ signals that the class or method is usable outside the class. - Answer>> public The keyword ____ signals data or methods are not usable outside the class. - Answer>> private The ________ method must always be static. - Answer>> main

A(n) ____ is a name for a variable, parameter, constant, user-defined method, or user-defined class

  • Answer>> identifier An identifier may use... (3) - Answer>> letters, digits, and underscores Identifiers may not begin with a(n)... - Answer>> digit What primitive types are included in the AP Java subset? (4) - Answer>> int, boolean, double, char If you try to store a value that is too big in an int variable, you'll get a(n).... - Answer>> overflow error When you get an overflow error, does Java give you a warning? - Answer>> no Assigning a double to an int will cause a(n)... - Answer>> compile-time error Relational operators should generally only be used when comparing... - Answer>> primitive types Avoid using boolean operators to compare ______- ______ numbers. - Answer>> floating-point

What are the three escape sequences necessary to know for the AP exam? - Answer>> \n, ", \ if, if-else, nested if, and extended if statements are all known as ______-______ control structures. - Answer>> decision-making Name the two control structures that allow the computer to perform iterative tasks. - Answer>> for loop and while loop The following is known as what kind of loop? for (SomeType element : collection) { statements; } - Answer>> for-each A(n) __________ is an error condition that occurs during the execution of a Java program. - Answer>> exception If you divide an integer by zero, what kind of error is thrown? - Answer>> ArithmeticException

If you use a negative array index, what kind of error is thrown? - Answer>> ArrayIndexOutOfBoundsException A(n) __________ exception is thrown to indicate that a parameter does not satisfy a method's precondition - Answer>> IllegalArgumentException The ________ of the class provide behaviors exhibited by an object and the operations that manipulate the object - Answer>> methods In the AP Java subset, all classes are... - Answer>> public Give the formula for a method header. - Answer>> access specifier, return type, method name, parameter list All methods defined in the main program must be... - Answer>> static ________ methods are two or more methods in the same class that have the same name but different parameter lists. - Answer>> overloaded A method's signature consists of... - Answer>> the method name and parameter types

When will the equals() method return true? - Answer>> If the objects being compared reference the same memory slot The default implementation of equals() is equivalent to what operator? - Answer>> == What does a string literal consist of? - Answer>> zero or more characters, escape sequences, surrounded by double quotes String objects are immutable. What does this mean?

  • Answer>> There are no methods to change them after they've been constructed. If String objects are immutable, then how do you mutate them? - Answer>> create a new String Why are String objects unusual? (think about initialization) - Answer>> They can be initialized like a primitive type What is the concatenation operator? - Answer>> + What does the concatenation operator do to two Strings? - Answer>> combines them into a single String

What does the concatenation operator do with a String and a primitive type? - Answer>> the primitive type is converted to a String, and the two are combined into one String How does the compareTo method compare Strings?

  • Answer>> according to their position in the ASCII chart, or lexicographical order What does lexicographical order mean? - Answer>> the order it comes up in the dictionary How are characters sorted in the ASCII chart? (out of capitals, lowercase, and digits, in what order do they come?) - Answer>> digits, capitals, and lowercases Why shouldn't you use == to test Strings? - Answer>> it tests whether they're the same reference, not if they're the same string How do you read the results of a String compareTo method? - Answer>> If it's less than 0, the String it's called on comes first in the dictionary. If it's greater than 0, the String it's called on comes after. If it's equal to 0, the two Strings are identical.

All of the functions and constants in the Math class are... - Answer>> static How do you invoke methods in the Math class? - Answer>> Math, followed by the dot operator What is the range of the result when Math.random() is called? - Answer>> (inclusive) 0.0 to less than 1. True or false: Math.random() can return a random real number from 0.0 up to (but NOT including) 1.0. - Answer>> True Provide code to find a random real value in the range 0.0 to < 6.0. - Answer>> 6 * Math.random(); Provide code to find a random real value in the range 2.0 to <3.0. - Answer>> Math.random() + 2 Provide code to find a random real value in the range 4.0,6.0. - Answer>> 3 * Math.random() + 4 What is the formula to produce a random real value in the range lowValue<=x<highValue? - Answer>> (highValue - lowValue) * Math.random() + lowValue;

Provide code to find a random integer in the range [0,99]. - Answer>> (int) (Math.random() * 100) Provide code to find a random integer in the range [1,100]. - Answer>> (int) (Math.random() * 100) + 1 When does a compile-time error occur? - Answer>> during compilation of the program What happens during a compile-time error? - Answer>> the compiler cannot translate the program into bytecode and prints an error What causes a syntax error? - Answer>> violating the rules of the programming language When does a run-time error occur? - Answer>> during the execution of the program When a run-time error occurs, what exactly throws the exception? - Answer>> the Java run-time environment What does it mean when an exception is thrown? - Answer>> execution stops and an error message is printed

When an array with doubles or ints is declared, what are the values automatically initialized to? - Answer>> 0 When an array with boolean values is declared, what are the values automatically initialize to? - Answer>> false When an array with object references is declared, what are the elements automatically initialized to? - Answer>> null Small arrays whose values are known can be declared with a(n)... - Answer>> initializer list When getting the length of an array, do you use parentheses? Why or why not? - Answer>> no, because it's not a method What should you use to traverse elements in an array? - Answer>> a for loop When passing an array as a parameter, can you modify it? Why or why not? - Answer>> Yes, because you're passing its object reference and not a copy

What is a recursive method? - Answer>> A method that calls itself What happens when a method actually terminates in a recursive loop? - Answer>> The program returns to the most recent call What are the two parts of a recursive method? - Answer>> a base case and a non-base case What is a base case? - Answer>> a termination condition that causes the method to end What is a nonbase case? - Answer>> actions that move the algorithm towards termination True or false: A recursive algorithm cannot have more than one base case. - Answer>> false Define tail recursion. - Answer>> When a method has no pending statements after its recursive call What is infinite recursion? - Answer>> when a recursive method has no base case What error will be thrown if infinite recursion occurs?

  • Answer>> StackOverflowError