Variables and Data Types - AP Computer Science A

  1. How do you declare a float variable named 'temperature'?
    float temperature;. Float provides 32-bit precision for decimal numbers.
  2. Which escape sequence is used for a new line in Java?
    . It moves output to the next line.
  3. What is the default value of an int variable in Java?
    0. Java initializes unassigned integer variables to zero.
  4. What data type in Java is used for decimal numbers?
    double. It provides 64-bit precision for floating-point numbers.
  5. Which operator is used for concatenating strings in Java?
    +. It joins string literals or variables together.
  6. What is the size in bits of a short data type in Java?
    16 bits. Short provides a smaller integer range than int.
  7. How do you declare a char variable named 'grade'?
    char grade;. This creates a character variable for single letters.
  8. What is the default value of a char variable in Java?
    '\u0000'. It represents the null character in Unicode.
  9. How do you declare a double variable named 'price'?
    double price;. This creates a double-precision floating-point variable.
  10. How do you declare a boolean variable named 'isOpen'?
    boolean isOpen;. This creates a boolean variable for true/false values.
  11. What is the size in bits of a long data type in Java?
    64 bits. Long provides extended range for large integer values.
  12. What is the size in bits of a boolean data type in Java?
    Not precisely defined. Implementation varies by JVM and platform.
  13. What is the result of '10 % 4' in Java?
    2. Modulo returns the remainder after division.
  14. How do you declare a variable of type int named 'counter'?
    int counter;. This creates an integer variable without initialization.
  15. Identify the result of '3.0 / 2' in Java.
    1.5. Double division produces a decimal result.
  16. What arithmetic operator represents subtraction in Java?
    -. It performs mathematical subtraction operations.
  17. Which data type can hold a sequence of characters in Java?
    String. String is a reference type for text data.
  18. State the Java data type for a single character.
    char. It stores a single Unicode character in 16 bits.
  19. How do you declare a string variable named 'name'?
    String name;. This creates a String reference variable.
  20. What does the '==' operator test in Java?
    Equality. It compares two values for identical content.
  21. What is the Java data type for storing a real number with double precision?
    double. It offers higher precision than float for decimals.
  22. Which keyword is used to declare a constant in Java?
    final. It prevents the variable's value from being changed.
  23. What is a variable in programming?
    A variable is a named storage location for data. It holds values that can change during program execution.
  24. Convert the string '123' to an integer in Java.
    Integer.parseInt("123"). This method parses string representations into integers.
  25. Which data type represents true or false values in Java?
    boolean. It can only hold one of two logical states.
  26. What is the result of '5 / 2' in Java using integer division?
    2. Integer division truncates the decimal portion.
  27. What is the size in bits of a float data type in Java?
    32 bits. Float uses single precision for decimal numbers.
  28. Which data type would you use for a variable storing a small integer?
    byte. Byte is the smallest integer type in Java.
  29. What is the maximum value of an int in Java?
    2,147,483,647. This is the upper limit for 32-bit signed integers.
  30. What is the range of a byte data type in Java?
    -128 to 127. Byte uses 8 bits with signed two's complement representation.
  31. Identify the default value for a boolean variable in Java.
    false. Java initializes unassigned boolean variables to false.
  32. Identify the data type for whole numbers in Java.
    int. It stores integers without decimal points.
  33. What is the default value of a double variable in Java?
    0.0. Java initializes unassigned double variables to zero.

Study these flashcards