1 Primitives Flashcards

1
Q

How does java know if a decimal value is a float or a double?

A

Java uses double by default. If not specified, the value will be a double.
Otherwise it knows by what is added at the end
100.123f, 100.123F
100.123d, 100.123D

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

What is the range of a byte?

A

-128 to 127

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

What is the range of a short?

A

-32,768 and a maximum value of 32,767 (inclusive).

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

How many times do static initializers run?

A

Only ONCE!

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

How many times do instance initializers run? Instance, not static.

A

Every time a new object is made

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
Is a reference variable required when calling a constructor?
Is this legal?    new MyClass();
A

Reference is NOT required. If the constructor is called without one, the functions inside will be performed you just can’t refer to that object.

new MyClass();   // LEGAL, no reference
MyClass thing1 = new MyClass(); // example with a reference
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Should long be written with capital or lowercase L?

A

Capital 123L

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

should double and float be written with capital or lowercase?

A

lowercase, but either is legal.

123.0d, 123.0f

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

How can the number of code blocks be determined?

A

Count the number of pairs of curly braces.

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

What is the resulting data type after arithmetic between any of the data types byte - through - int?

A

The result is an int (ex, byte + byte = int). Add a cast to the operation if you need to assign the result back to the smaller data type.

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