zuai-logo
zuai-logo
  1. AP Computer Science A
FlashcardFlashcard
Study GuideStudy GuideQuestion BankQuestion Bank

What is an 'int'?

A primitive data type that stores whole numbers.

Flip to see [answer/question]
Flip to see [answer/question]
Revise later
SpaceTo flip
If confident

All Flashcards

What is an 'int'?

A primitive data type that stores whole numbers.

What is a 'double'?

A primitive data type that stores decimal numbers with high precision.

What is a 'boolean'?

A primitive data type that stores a truth value: either 'true' or 'false'.

What is a 'variable'?

A named storage location in memory that holds a value.

What is 'scope' in Java?

The region of the program where a variable is accessible.

What is 'initialization'?

Giving a variable its first value.

What is 'Integer Overflow'?

When an integer exceeds its maximum or minimum allowed value, wrapping around to the other end.

What does 'strongly typed' mean?

Once a variable has a data type, it cannot be changed to a different data type.

What is 'public' access modifier?

Accessible everywhere.

What is 'private' access modifier?

Accessible only within the class.

What is the range of an 'int'?

-2,147,483,648 to 2,147,483,647

Why are phone numbers stored as Strings?

Because they are not numerical values used in calculations.

What is Camel Casing?

A naming convention where the first word is lowercase, and subsequent words start with an uppercase letter (e.g., myVariableName).

What are reserved words?

Keywords in Java that cannot be used as variable names (e.g., int, class, public).

What happens during integer overflow?

The value wraps around to the opposite end of the integer range.

What are access modifiers?

Keywords that control the visibility or accessibility of a variable or method.

What is the purpose of variable declaration?

To specify the name and data type of a variable before it can be used.

What is the difference between declaration and initialization?

Declaration creates the variable; initialization assigns it a value.

Why is data type important in Java?

Java is strongly typed, so the data type determines what kind of values a variable can hold and what operations can be performed on it.

What is the default access modifier?

Accessible within the package.

Identify the error in the following code: int x = 3.14;

Cannot assign a 'double' value (3.14) to an 'int' variable.

Identify the error in the following code: boolean flag = 1;

Cannot assign an integer value (1) to a 'boolean' variable. 'boolean' can only be 'true' or 'false'.

Identify the error in the following code: double result = 10 / 3;

Integer division is performed (10/3 = 3), then the result is converted to a double (3.0). To get a double result, one of the operands must be a double (e.g., 10.0 / 3).

What does the following code output? int max = Integer.MAX_VALUE; System.out.println(max + 1);

Integer.MIN_VALUE (due to integer overflow)

Identify the error in the following code: private int 2variable = 10;

Variable names cannot start with a number.

Identify the error in the following code: int public = 5;

'public' is a reserved keyword and cannot be used as a variable name.

What does the following code output? double num = 5.0 / 2; System.out.println(num);

2.5

What does the following code output? boolean isTrue = (5 > 3); System.out.println(isTrue);

true

Identify the error in the following code: Int age = 20;

Java is case-sensitive. 'Int' should be 'int'.

What does the following code output? int a = 5; int b = a + 2; System.out.println(b);

7