1 Primitives Flashcards
How does java know if a decimal value is a float or a double?
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
What is the range of a byte?
-128 to 127
What is the range of a short?
-32,768 and a maximum value of 32,767 (inclusive).
How many times do static initializers run?
Only ONCE!
How many times do instance initializers run? Instance, not static.
Every time a new object is made
Is a reference variable required when calling a constructor? Is this legal? new MyClass();
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
Should long be written with capital or lowercase L?
Capital 123L
should double and float be written with capital or lowercase?
lowercase, but either is legal.
123.0d, 123.0f
How can the number of code blocks be determined?
Count the number of pairs of curly braces.
What is the resulting data type after arithmetic between any of the data types byte - through - int?
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.