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