Made with ScholarlyMake flashcards like these from your own notes
Question:What file extension do Java source code files use?
Answer:.java
Question:What file extension do compiled Java files use?
Answer:.class
Question:What does 'syntax' refer to in Java programming?
Answer:The grammar rules of the programming language
Question:What is an 'object' in Java?
Answer:An instance of a class on which methods can be called
Question:What does 'instantiation' mean in Java?
Answer:The process of creating an object based on a class
Question:What is a 'variable' in Java?
Answer:A named memory location for storing data that can change during execution
Question:What is the purpose of the 'final' keyword in Java?
Answer:Used to declare a constant
Question:What does an 'import' statement do in Java?
Answer:Declares that a Java file will use an external class
Question:What is a 'method' in Java?
Answer:A set of Java statements that perform a task when defined in a class
Question:In the import statement 'import java.util.Scanner;', what is the package?
Answer:java.util
Question:In the import statement 'import java.util.Scanner;', what is the class?
Answer:Scanner
Question:What is wrong with 'Scanner console = new Scanner(10);'?
Answer:Should use System.in instead of 10 for input
Question:What is missing in 'System.out.println("Enter your age: ")'?
Answer:Semicolon (;) at the end
Question:What method should be used to read an integer from Scanner?
Answer:nextInt()
Question:Name a primitive type used in Java for characters.
Answer:char
Question:Name a primitive type used in Java for whole numbers.
Answer:int
Question:Name a primitive type used in Java for decimal numbers.
Answer:double
Question:What class is used for reading console input in Java?
Answer:Scanner
Question:What class might be used for GUI labels in Java?
Answer:GLabel
Question:Which declaration correctly initializes a String with double quotes?
Answer:String saying = "We will see snow soon";
Question:Why is 'String name = 'Angie';' incorrect?
Answer:Uses single quotes instead of double quotes for String
Question:Which declaration correctly initializes a char variable?
Answer:char letter = 'A';
Question:Why is 'char letter = "A";' wrong?
Answer:Double quotes are for Strings, not chars
Question:How does Java escape a backslash in a print statement?
Answer:Use \\ to print \
Question:How does Java print double quotes inside a string?
Answer:Use \" to print "
Question:What does \n do in a Java print statement?
Answer:Inserts a newline
Question:What is the result of 3 % 2 in Java?
Answer:1
Question:What is the result of 2 % 2 in Java?
Answer:0
Question:What is the result of 3 > 2 in Java?
Answer:true
Question:What is the result of 3 / 2 in integer division in Java?
Answer:1
Question:What does casting (int) 3.5 produce in Java?
Answer:3
Question:What is the result of 5 + 2 * 3 with operator precedence?
Answer:11
Question:What does myVar -= 3 do if myVar is 9?
Answer:Sets myVar to 6
Question:What does myVar += 2 do if myVar is 6?
Answer:Sets myVar to 8
Question:What naming convention do Java class names follow?
Answer:Begin with capital letter and use camelCase
Question:What naming convention do Java variable names follow?
Answer:Begin with lowercase letter and use camelCase
Question:What naming convention do Java constants follow?
Answer:All uppercase with underscores (snake_case)
Question:What naming convention do Java method names follow?
Answer:Begin with lowercase letter and use camelCase
Question:What is the output of "hang" + 7 + 2?
Answer:hang72
Question:What is the output of "2" + 1 + "four"?
Answer:21four
Question:What is the output of 7 + 2 + "hang"?
Answer:9hang
Question:What does Math.sqrt(16.0) return?
Answer:4.0
Question:What method does every Java program start with?
Answer:main
Question:What is the output of System.out.print("Catch " + (2 * 2));
Answer:Catch 4
Question:Why does print vs println affect output layout?
Answer:print doesn't add newline, println does
Question:How do you write a static void method that prints a String parameter?
Answer:public static void printMe(String text) { System.out.println(text); }
Question:How do you write a static method to average three ints as double?
Answer:public static double calculateAverage(int a, int b, int c) { return (a + b + c) / 3.0; }
Question:What does String.equals() compare in Java?
Answer:The actual content of the strings
Question:In nested if-else, what happens if first condition false, second true?
Answer:Executes the else if block
Question:What is the output if age=10, weight=65 in the given if-else?
Answer:You can ride the ferris wheel
Question:How does assignment in if block affect later prints?
Answer:Modifies the variable for subsequent use
Question:What is the loop condition for printing 1 to 6 odd numbers?
Answer:for(int i = 1; i <= 6; i = i + 2)
Question:What prints from for(int i = 10; i >= 5; i--)?
Answer:10 9 8 7 6 5
Question:What makes a for loop infinite?
Answer:Condition that never becomes false, like i++ when decreasing
Question:In method tracing, what does main call first?
Answer:The bodyParts method
Question:What does part1.length() return in the bodyParts method?
Answer:The number of characters in part1
Question:In mystery(6), what is printed after if conditions?
Answer:6 1
Question:In mystery(-2), why n=5 after conditions?
Answer:n < 0, so n = n + 7