Anda di halaman 1dari 5

Test 1 Review Name: ________________

APCSA
Fall 2017

1. Provide 3 examples of input devices.


a. Scanner(System.in)
b. JOptionPane
c. DataInputStream
2. Provide 3 examples of output devices
a. System.out.println
b. System.out.print
c. JOptionPane
3. What is memory (or primary storage)?
a. Primary storage, or memory, is made from electronic circuits that can
store data, provided they are supplied with electric power.
4. What is storage (or secondary storage)?
a. Secondary storage, usually a hard disk (see Figure 2) or a solid-state
drive, provides slower and less expensive storage that persists without
electricity.
5. What does the compiler do?
a. The Java compiler translates source code into class files that contain
instructions for the Java virtual machine.
6. What is source code? What is the file extension of the source code file?
a. Instructions in a programming language that need to be translated
before execution on a computer.
b. .class
7. Assume you have a class named Project1, what is the name of the source code
file in which it is stored? What is the name of the object code file in which it is
stored?
a. Project1.java
b. Project1.class
8. What is an IDE? What IDE are we using in this class? What is included in the
IDE?
a. A programming environment that includes an editor, compiler, and
debugger.
b. NetBeans
9. What is the JVM? Why is it important?
a. A program that simulates a CPU that can be implemented efficiently on a
variety of actual machines. A given program in Java bytecode can be
executed by any Java virtual machine, regardless of which CPU is used to
run the virtual machine itself.
b. It is portable and you dont have to learn code for different CPUs
10. What are 2 categories of errors? Who/what is responsible for catching each type?
a. Compile time error
b. Run time error
11. What is the ; for in Java? To end a line of code

APCSA Fall 2017 Test 1 Review Sheet/Study Guide Page 1 of 5


12. Is Java case sensitive? yes
13. What is a sequence of steps that is unambiguous, executable, and terminating is
called?
a. Algorithm
14. What is the output of the following code snippet?
a. 142

System.out.print(10 + 4);
System.out.print(2);

15. Write the line of code to declare an integer variable named num
a. int num = 6;
16. What is the output of the following code snippet?
a. 28

public class PrintIt


{
public static void main(String[] args)
{
System.out.println(4 * 4 + 12);
}
}
17. Write the line of code to define and initialize an integer variable with name
value? Initialize the variable to 15.
a. int value = 15;
18. What are the primitive types in the AP Subset of Java?
a. int, Boolean, double, char
19. What reference type have we used in this class? What is the difference between a
primitive and a reference type?
a. String
b. Primitive stores value while reference stores addresses
20. What are the rules for naming identifiers in Java? How are variables and class
names different?
a. Case sensitive, start with a letter, Subsequent characters may be
letters, digits, dollar signs, or underscore characters; If the name you
choose consists of only one word, spell that word in all lowercase
letters. If it consists of more than one word, capitalize the first letter
of each subsequent word.
b. Should start with uppercase letter and be a noun
21. What 3 categories of operators are there in Java? In an expression including a
mix of variables, what order are they evaluated in?
a. Arithmetic
b. Relational
c. Logical
d. Arithmetic, Logical, Relational

APCSA Fall 2017 Test 1 Review Sheet/Study Guide Page 2 of 5


22. What are the 3 logic operators in Java? What type of operands are used with logic
operators?
a. &&, ||, !
b. Primitive data types
23. What is "short circuit evaluation"? (We didn't talk about this in class look it up
and see if you can figure it out)
a. when the first argument of the AND function evaluates to false, the
overall value must be false; and when the first argument of the OR
function evaluates to true, the overall value must be true.
24. What does an assignment operator do?
a. Assigns a value
25. What keyword do you use to make a constant?
a. final
26. Write the statements to define a constant to store a sales tax rate of 0.095
a. final int tax = 0.095;
27. How can you make code more explanatory for others?
a. Using single line comments or multiple line comments
28. What are the three types of comments in Java? Provide examples of each
a. Single Line; // hi whats up!
b. Multiple Line; /* lol lol lol lol lol lol lol lol lol lol lol lol lol lol lol lol lol
lol lol */
c. Javadoc; /** this website will have my documentation
www.google.com */
29. What is the result of the following code snippet?
a. Error because rad not initialized
public static void main(String[] args)
{
double rad;
double area = 22 / 7 * rad * rad;
System.out.println(area);
}
30. What is the increment operator? And the decrement operator? How does it
work?
a. ++
b. --
c. It either adds one or subtracts 1 when used.
31. What is hand tracing? (aka tracing)
a. A code trace is a method for hand simulating the execution of your
code in order to manually verify that it works correctly before you
compile it.
32. What is pseudocode?
a. Writing code but in English instead of java
33. What is a "dangling else"?
a. in which an optional else clause in an ifthen(else) statement results
in nested conditionals being ambiguous.
34. What is "spaghetti code"?

APCSA Fall 2017 Test 1 Review Sheet/Study Guide Page 3 of 5


a. Spaghetti code is a term for computer programming that is
unnecessarily convoluted, and particularly programming code that
uses frequent branching from one section of code to another
35. What does "inverting a condition" mean?
a. To flip the Boolean output
36. What is the output of the following code snippet?
a. 20
int num = 10;
if (num < 10)
{
if (num < 5)
{
num = num - 5;
}
else
{
num = num 1;
}
}
else
{
if (num > 15)
{
num = num + 5;
}
else
{
num = num + 10;
}
}
System.out.println(num);
37. Assuming that a user enters 5, 10, and 20 as input values one after another,
separated by spaces, what is the output of the following code snippet?
a. 20
int num1 = 0;
int num2 = 0;
int num3 = 0;
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
num1 = in.nextInt();
System.out.print("Enter a number: ");
num2 = in.nextInt();
System.out.print("Enter a number: ");
num3 = in.nextInt();
if (num1 > num2)
{
if (num1 > num3)

APCSA Fall 2017 Test 1 Review Sheet/Study Guide Page 4 of 5


{
System.out.println(num1);
}
else
{
System.out.println(num3);
}
}
else
{
if (num2 > num3)
{
System.out.println(num2);
}
else
{
System.out.println(num3);
}
}

38. What are the 6 flow chart symbols used in this class and what are each used for?
a. Diamond, Circle, Rectangle, Oval, Arrows, Parallelogram

APCSA Fall 2017 Test 1 Review Sheet/Study Guide Page 5 of 5