Review APCSA
1. What must all Java programs start with? public class
2. What syntax is used to start and end public class name{}
class definitions and method definitions?
public static void Method(){}
3. What is the difference between the System.out.print(value); VS
following print commands? System.out.println(value);
The difference is that the first line of code
won’t bring the cursor to the next line,
but for the second line of code, the cursor
will move to the next line once it's done
printing out the output.
4. What is a string literal? How many It is a data type that can hold words and it
characters can it have? can hold up a lot of characters
5. What must you use to show the end of a semicolon;
Java statement?
6. What is the process of removing errors Debugging
(or bugs) called?
7. What is a variable? Variables can store values of different
types such as doubles, ints and booleans
8. What are the two types of variables in primitive and object type
Java?
9. What are the 3 primitive type variables double, boolean and integer
that are tested on the AP CSA exam?
10. What is one of the object type variables String
on the exam?
11. How do you declare (create) a variable in int a=5; double d2=4.5;
Java? Write a few examples as practice.
12. What is = in Java? How is it used in it means equal to and so you can make a
relation to variables and their values? variable called b equal 5. So everytime
you call the variable b, it will be 5
13. Write two lines of code to declare an int perOfCSA;
integer variable called perOfCSA and
perOfCSA = 4;
initialize it for the current period.
14. Write one line of code to declare a double height = 64;
double variable called height and
initialize it for your height in inches.
15. What are some rules for naming it can’t start with a number, no keywords,
variables in Java? no special characters other than _ and $
16. What is camelCase? Make up two It's a way to distinguish words in a phrase
examples of variables using camelCase. by uppercasing the first letter of the
second word. cupCake and iceCream
17. What is an assignment statement? It is when a variable is assigned a value
18. Since one variable can be set to copy
another variable's value (without
changing the value of the variable that
you are copying from), what is the output
of the following code?
19. What is an ArithmeticException error it is when the code isn’t able compute the
message? calculation. For example number/0.
20. What are the math operator PEMDAS
precedence? (Don't forget the
Parentheses then
parentheses.)
Multiplication/Division/Modulus then
Addition/Subtraction
21. What is type casting? changing the variable type of a variable
22. List two different ways to get a double Make one of the variables a double or
result when doing division in Java. type cast it.
23. What is the output of each of the public class OperatorTest2{
public static void main(String[] args) {
following?
System.out.print(l/4 + " ,, ) ;
System.out.println{l.0/4);
System.out.println(l/4.0);
System.out.println((double)l/4);
System.out.println((int)l.0/4);
}
}
error
24. What is the output? Can you explain the public static void main(String args[]){
int total=25;
difference?
System.out.println( (double) (total/3));
System.out.println((double)total/3));
}
8.0
8.3
In the first print statement, the double is applied
too late and so it will first compute 25/3 and give
you an int value because 25 and 3 are ints. So it will
truncate the decimals and give you 8 and then the
double adds an .0 . the second print statement, the
typecasting is applied to the 25 making it 25.0.
double/int gives you double.