Logo/

Java Fundamentals Flashcards

Log in

Made with ScholarlyMake flashcards like these from your own notes

Java Fundamentals Flashcards

Questions and answers

58 cards
  1. Question:What file extension do Java source code files use?

    Answer:.java

  2. Question:What file extension do compiled Java files use?

    Answer:.class

  3. Question:What does 'syntax' refer to in Java programming?

    Answer:The grammar rules of the programming language

  4. Question:What is an 'object' in Java?

    Answer:An instance of a class on which methods can be called

  5. Question:What does 'instantiation' mean in Java?

    Answer:The process of creating an object based on a class

  6. Question:What is a 'variable' in Java?

    Answer:A named memory location for storing data that can change during execution

  7. Question:What is the purpose of the 'final' keyword in Java?

    Answer:Used to declare a constant

  8. Question:What does an 'import' statement do in Java?

    Answer:Declares that a Java file will use an external class

  9. Question:What is a 'method' in Java?

    Answer:A set of Java statements that perform a task when defined in a class

  10. Question:In the import statement 'import java.util.Scanner;', what is the package?

    Answer:java.util

  11. Question:In the import statement 'import java.util.Scanner;', what is the class?

    Answer:Scanner

  12. Question:What is wrong with 'Scanner console = new Scanner(10);'?

    Answer:Should use System.in instead of 10 for input

  13. Question:What is missing in 'System.out.println("Enter your age: ")'?

    Answer:Semicolon (;) at the end

  14. Question:What method should be used to read an integer from Scanner?

    Answer:nextInt()

  15. Question:Name a primitive type used in Java for characters.

    Answer:char

  16. Question:Name a primitive type used in Java for whole numbers.

    Answer:int

  17. Question:Name a primitive type used in Java for decimal numbers.

    Answer:double

  18. Question:What class is used for reading console input in Java?

    Answer:Scanner

  19. Question:What class might be used for GUI labels in Java?

    Answer:GLabel

  20. Question:Which declaration correctly initializes a String with double quotes?

    Answer:String saying = "We will see snow soon";

  21. Question:Why is 'String name = 'Angie';' incorrect?

    Answer:Uses single quotes instead of double quotes for String

  22. Question:Which declaration correctly initializes a char variable?

    Answer:char letter = 'A';

  23. Question:Why is 'char letter = "A";' wrong?

    Answer:Double quotes are for Strings, not chars

  24. Question:How does Java escape a backslash in a print statement?

    Answer:Use \\ to print \

  25. Question:How does Java print double quotes inside a string?

    Answer:Use \" to print "

  26. Question:What does \n do in a Java print statement?

    Answer:Inserts a newline

  27. Question:What is the result of 3 % 2 in Java?

    Answer:1

  28. Question:What is the result of 2 % 2 in Java?

    Answer:0

  29. Question:What is the result of 3 > 2 in Java?

    Answer:true

  30. Question:What is the result of 3 / 2 in integer division in Java?

    Answer:1

  31. Question:What does casting (int) 3.5 produce in Java?

    Answer:3

  32. Question:What is the result of 5 + 2 * 3 with operator precedence?

    Answer:11

  33. Question:What does myVar -= 3 do if myVar is 9?

    Answer:Sets myVar to 6

  34. Question:What does myVar += 2 do if myVar is 6?

    Answer:Sets myVar to 8

  35. Question:What naming convention do Java class names follow?

    Answer:Begin with capital letter and use camelCase

  36. Question:What naming convention do Java variable names follow?

    Answer:Begin with lowercase letter and use camelCase

  37. Question:What naming convention do Java constants follow?

    Answer:All uppercase with underscores (snake_case)

  38. Question:What naming convention do Java method names follow?

    Answer:Begin with lowercase letter and use camelCase

  39. Question:What is the output of "hang" + 7 + 2?

    Answer:hang72

  40. Question:What is the output of "2" + 1 + "four"?

    Answer:21four

  41. Question:What is the output of 7 + 2 + "hang"?

    Answer:9hang

  42. Question:What does Math.sqrt(16.0) return?

    Answer:4.0

  43. Question:What method does every Java program start with?

    Answer:main

  44. Question:What is the output of System.out.print("Catch " + (2 * 2));

    Answer:Catch 4

  45. Question:Why does print vs println affect output layout?

    Answer:print doesn't add newline, println does

  46. 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); }

  47. 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; }

  48. Question:What does String.equals() compare in Java?

    Answer:The actual content of the strings

  49. Question:In nested if-else, what happens if first condition false, second true?

    Answer:Executes the else if block

  50. Question:What is the output if age=10, weight=65 in the given if-else?

    Answer:You can ride the ferris wheel

  51. Question:How does assignment in if block affect later prints?

    Answer:Modifies the variable for subsequent use

  52. Question:What is the loop condition for printing 1 to 6 odd numbers?

    Answer:for(int i = 1; i <= 6; i = i + 2)

  53. Question:What prints from for(int i = 10; i >= 5; i--)?

    Answer:10 9 8 7 6 5

  54. Question:What makes a for loop infinite?

    Answer:Condition that never becomes false, like i++ when decreasing

  55. Question:In method tracing, what does main call first?

    Answer:The bodyParts method

  56. Question:What does part1.length() return in the bodyParts method?

    Answer:The number of characters in part1

  57. Question:In mystery(6), what is printed after if conditions?

    Answer:6 1

  58. Question:In mystery(-2), why n=5 after conditions?

    Answer:n < 0, so n = n + 7