Chapter Summary Section 4.1: Identifiers and Data Types • Identifiers are names for variables, programs, and methods and must start with a letter, underscore, or dollar sign numbers are allowed after the first character, but spaces are not allowed. • The data type is the format in which the data will be stored and the size the variable will be given in memory Java contains eight built-in data types called primitive data types. • To define a variable, provide a data type and a name followed by a semicolon it is a good practice to choose names that clearly indicate what data will be stored in the variable. Section 4.2: Variable Values • A literal value is a textual representation of a value and is set in Java with the assignment operator (=) a String literal is a sequence of characters enclosed in quotation marks (“), and the concatenation operator (+) can be used to join data values and String literals into one message for output. • A constant is a value that cannot change during the execution of the program and is created by placing the final keyword at the beginning of the variable definition. • The Scanner class is used to input values from the user the three-step process is to import the Scanner class, create the Scanner object, and ask the user for input with a prompt. Chapter 4 Test Multiple Choice Select the best response. 1. Which of these identifiers does not follow standard Java naming conventions? A. testDate B. cleanupTime C. winterChill D. timechange 2. Numeric data types are chosen based on the _____ of the value that will be placed in them. A. size B. method C. identifier D. capitalization 3. A boolean data type can have values of _____. A. integers B. floating decimals C. true and false D. large (astronomical) numbers 4. The concatenation operator (+) is used to: A. Combine text and variable values. B. Add two numbers. C. Eliminate the use of double quotes. D. As a shortcut for defining variables. 5. Which class is imported when desiring user input? A. Scanner B. Prompt C. Literal D. Char Completion Complete the following sentences with the correct word(s). 6. A(n) _____ is the punctuation used at the end of a statement that defines a variable. 7. The four primitive data types that can hold integers are byte, short, _____, and long. 8. The data types that can hold real number values are _____ and float. 9. The _____ keyword is used to create a constant. 10. A data mismatch is a(n) _____ runtime error, which can be avoided by using the correct data type. Matching Match the correct term with its example. A. int B. double C. long D. square feet E. public 11. Cost of a gallon of gas 12. Invalid identifier 13. Reserved word 14. Number of eggs in a dozen 15. Width of the Milky Way galaxy Copyright Goodheart-Willcox Co., Inc. Chapter 4 Variables 95