Java SE 11: Variables & Operators Flashcards

1
Q

Variables can be initialized with.

A. Only A value

B. A value or without.

C. Without a value

A

B. A value or without.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

All variables must have a variable _____

A

Type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

You can set the value of a variable without having to declare the type a second time.

True or False

A

True

String zip;

zip = “83705”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Variables have default value of __________

A

uninitialized

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

When declaring a string variable the string type must be declared with __________ letter

A

Uppercase

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the naming guidelines for variables.

Begin each variable with a ______________ letter. Subsequent words should be _______________.

A

What are the naming guidelines for variables.

Begin each variable with a lowercase letter. Subsequent words should be capitalized.

Ex. myVariable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Names are not case-sensitive.

True or False

A

False

Name are case-sensitive

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Names cannot include a white space

True or False

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Names should be mnemonic and indicate to the casual observer the intent of the variable.

True or False

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

The Undserscore Character _ is a Legal within a vairable name

True or False

A

False

As of Java SE 9 the underscore character (“_”) is not a legal character and won’t compile in Java SE9 or later

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What type of variable is followed by name of variable set to a string in quotes

A

String

String name = “Steve”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What variable type has positive or negative real values containing decibel

A

double

double price = 9.99

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Which variable type holds true or false values?

A

boolean

boolean outOfStock = false;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the default value of a boolean value?

A

false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

String address = “123 Oak St”

Is this variable:

A. Declared
B. Initialized

C. Declared and Initialized

A

C. Declared and initialized

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What type of variable is a positive or negative whole number?

A

Integer

int quantity = 2;

17
Q

How do you declare multiple variables of the same type on one line?

A

Use comma to separate each variable declaration.

String zip = “83705”, customer = “customer”;

18
Q

What word means to combine multiple strings by joining them

A

Concatenation

19
Q

What symbol is used for Concatenation?

20
Q

IndexOf() and Substring() methods provided by the ______ class in Java

21
Q

What does the IndexOf method do.

A

Gives the location of a character in a string.

Example:

String ipAddress = “122.72.1.45”;

int index1 = ipAddress.indexOf(‘.’);

System.out.println( index1);

System.out.println( index1 + 1);

: 3

: 6

22
Q

What does the substring method do.

A

You provide it two arguments that are locations in a string and it prints out what’s in-between two points in a string.

String ipAddress = “122.72.1.45”;

int index1 = ipAddress.indexOf(‘.’);

int index2 = ipAddress.indexOf(index1 + 1)

String secondbyte = ipAddress.substring(index +1, index2)

System.out.println(secondbyte);

: 72

23
Q

How do you represents commas in integer (int) numbers

A

Underscore _

int lowest = -2_147_483_648

24
Q

Can double variable types use scientific notation?

Yes or No

A

Yes

double scientificValue = 2.345123E22;

25
Can double types using decimal ( . ) notation **Yes** or **No**
**Yes** double decimalValue = 3743743948.2134846
26
What are the standard mathematical operators in Java
Plus + Minus - Divide / Multiply \*
27
List operators by precedence: * Multiplication & Division * Addition * Parentheses * Increment and Decrement operators (++ or --)
1. **Parentheses** - IF there are nested parentheses start from middle and work your way out 2. **++** or **--** 3. **Multiplication** and **division** operators, evaluated from left to right 4. **Addition** and **subtraction** operators, evaluated from left tor right
28
You can set __________ by using parentheses ( )
Precedence
29
Which of the following variable declarations and/or initializations are correct? * string name; * boolean isComplete = false; * int count =5; quantity =2; * boolean isComplete = "true";
**boolean isComplete = false;**
30
Given the following variable declarations, what variable type should be used for the product of quantity \* price? int quantity = 2; double price = 9.99; * String * int * boolean * double
**double**
31
Which of the following is an uncommon method of declaring and/or initializing a String? * String zip = “12345”, country = “USA”; * String customer; * String address = “123 Oak St”; * String hello = new String(“Hello, World”);
**String hello = new String(“Hello, World”);**
32
Select the operator/character used for concatenating Strings? * & * . * ~ * $ * + * \*
**+**
33
What is the output of the following code? String phone = “555-548-1254”; System.out.println(phone.substring(3, 6)); * 548 * 5-5 * -54 * 48-
-54
34
Which of the following will result in a compile failure? * double price = 75; * int quantity = 5.5; * double price = 25.99; * int quantity = 10;
int quantity = 5.5;
35
What is the answer of the following division using Java ints? int a = 7; int b = 3; System.out.println(a / b); * 4 * 2 * 2.3333… * 3
2
36
Put the following operators in order of evaluation precedence in a mathematical expression. Multiplication and division operators Addition and subtraction operators Operators within a pair of parentheses Increment and decrement operators (++ or --)
1. Operators within a pair of parentheses 2. Increment and decrement operators (++ or --) 3. Multiplication and division operators 4. Addition and subtraction operators
37
What is the value of the variable `c` after evaluating the expression? int c = 50 – 8 \* 2 / 4 – 8 + 3 * 16 * 41 * -94 * 61
41
38
Which of the following statements correctly assigns the value “Bob wrote 3 Java programs.” to the msg variable? ▢ msg = name + " wrote " + 3 + " Java programs."; ▢ msg = name + " wrote " + 2+1 + " Java programs."; ▢ msg = name + " wrote " + num " Java programs."; ▢ msg = "Bob wrote "+ (2+1) + " Java programs.";
√ msg = name + " wrote " + 3 + " Java programs."; ▢ msg = name + " wrote " + 2+1 + " Java programs."; ▢ msg = name + " wrote " + num " Java programs."; √ msg = "Bob wrote "+ (2+1) + " Java programs.";