More on this book
Kindle Notes & Highlights
OCA: Oracle Certified Associate Java SE 8 Programmer I Study Guide: Exam 1Z0-808 (Sybex Study Guide)
Started reading
October 14, 2019
There's one special package in the Java world called java.lang. This package is special in that it is automatically imported.
code blocks appear outside a method. These are called instance initializers.
The constructor runs after all fields and instance initializer blocks have run.
Java has eight built-in data types, referred to as the Java primitive types.
System.out.println(Integer.MAX_VALUE);
reference types can be assigned null, which means they do not currently refer to an object.
Local variables must be initialized before use. They do not have a default value and contain garbage data until initialized. The compiler will not let you read an uninitialized value.
multiple classes can be defined in the same file, but only one of them is allowed to be public.
A file is also allowed to have neither class be public.
Java provides a method called System.gc(). Now you might think from the name that this tells Java to run garbage collection. Nope! It meekly suggests that now might be a good time for Java to kick off a garbage collection run. Java is free to ignore the request.
Java operator is a special symbol that can be applied to a set of variables, values, or literals—referred to as operands—and that returns a result.
operator precedence.
Numeric Promotion Rules
For the third rule, note that unary operators are excluded from this rule. For example, applying ++ to a short value results in a short value. We'll discuss unary operators in the next section.
floating-point literals are assumed to be double, unless postfixed with an f, as in 2. 1f.
in Java 1 and true are not related in any way, just as 0 and false are not related.
The first four relational operators (see Table 2.3) are applied to numeric primitive data types only.
Table 2.4 Relational instanceof operator
Comparing two numeric primitive types. If the numeric values are of different data types, the values are automatically promoted as previously described. For
Two references are equal if and only if they point to the same object, or both point to null.
Data types supported by switch statements include the following: byte and Byte short and Short char and Character int and Integer String enum values For the exam, we recommend you memorize this list. Note that boolean and long, and their associated wrapper classes, are not supported by switch statements.
The values in each case statement must be compile-time constant values of the same data type as the switch value.
default block, it is only branched to if there is no matching case value for the switch statement, regardless of its position within the switch statement.
return statement, like a break statement, can be used to exit the switch statement early.
The initialization and update sections may contain multiple statements, separated by commas.
Note that the semicolons separating the three sections are required, as for( ; ) and for( ) will not compile.
In and of itself, that will not cause the code to not compile, as a corrected loop would just output null three times.
The optional label parameter allows us to break out of a higher level outer loop.
What is the output of the following code snippet?
use numeric addition if two numbers are involved, use concatenation otherwise, and evaluate from left to right.
Mutable is another word for changeable.
On the OCA exam, you need to know that String is immutable.
Also, immutable classes in Java are final, and subclasses can't add mutable behavior.
The string pool, also known as the intern pool, is a location in the Java virtual machine (JVM) that collects all these strings.
The string pool contains literal values that appear in your program.
int length()
char charAt(int index)
int indexOf(int ch) int indexOf(int ch, int fromIndex) int indexOf(String str) int indexOf(String str, int fromIndex)
Notice we said “stop at” rather than “include.”
beginIndex, int endIndex)
Since we start and end with the same index, there are no characters in between.
String