Читать книгу OCP Oracle Certified Professional Java SE 17 Developer Study Guide - Jeanne Boyarsky - Страница 94

Is String a Primitive?

Оглавление

No, it is not. That said, String is often mistaken for a ninth primitive because Java includes built-in support for String literals and operators. You learn more about String in Chapter 4, but for now, just remember it's an object, not a primitive.

There's a lot of information in Table 1.6. Let's look at some key points:

 The byte, short, int, and long types are used for integer values without decimal points.

 Each numeric type uses twice as many bits as the smaller similar type. For example, short uses twice as many bits as byte does.

 All of the numeric types are signed and reserve one of their bits to cover a negative range. For example, instead of byte covering 0 to 255 (or even 1 to 256) it actually covers -128 to 127.

 A float requires the letter f or F following the number so Java knows it is a float. Without an f or F, Java interprets a decimal value as a double.

 A long requires the letter l or L following the number so Java knows it is a long. Without an l or L, Java interprets a number without a decimal point as an int in most scenarios.

You won't be asked about the exact sizes of these types, although you should have a general idea of the size of smaller types like byte and short. A common question among newer Java developers is, what is the bit size of boolean? The answer is, it is not specified and is dependent on the JVM where the code is being executed.

OCP Oracle Certified Professional Java SE 17 Developer Study Guide

Подняться наверх