1Z0-771 flashcards
1Z0-771 · Build recall with a focused review session.
32 cards. Read the term and the definition here. The deck at the top of this page is optional.
- Integer cache range
- Java caches Integer objects from -128 to 127. Autoboxing values inside this range returns the same reference, so == is true; outside it, == compares distinct objects.
- var restrictions
- var requires an initializer on the same declaration, cannot be null, and cannot be used for fields, method parameters, or return types. It is local-variable type inference, not dynamic typing.
- Definite assignment
- A local variable must be assigned on every path before use or the code fails to compile. Fields instead receive default values such as 0, false, or null.
- Switch expression yield
- In a switch expression, an arrow arm with a block must return a value using yield. Arrow arms never fall through, and the switch must be exhaustive.
- Multi-catch rules
- catch (IOException | SQLException e) handles several unrelated types. The parameter is implicitly final, and the listed types cannot be related by subclassing.
- try-with-resources close order
- Resources declared in a try-with-resources header are closed in reverse order of declaration, even when the body throws, using their AutoCloseable close method.
- finally override behavior
- A return or throw inside finally overrides any earlier return or exception from the try block, which is why returning from finally is discouraged.
- Record compact constructor
- A compact canonical constructor omits the parameter list, cannot assign fields directly, and runs validation before the implicit field assignments occur.
- Default method conflict
- When a class implements two interfaces declaring the same default method, it must override that method or the code fails to compile.
- Sealed class permits clause
- A sealed class lists permitted subclasses with permits; each subclass must be final, sealed, or non-sealed. Permits may be omitted when subclasses share the source file.
- Static method hiding
- Static methods are hidden, not overridden. The version invoked depends on the declared type of the reference, not the runtime class of the object.
- Type erasure
- Generic type parameters are erased at compile time. Consequently primitives cannot be type arguments, and instanceof List<String> or new T() is illegal.
- PECS principle
- Producer extends, Consumer super. List<? extends Number> can be read from, while List<? super Integer> can be written to, preserving type safety.
- HashMap null rules
- HashMap permits one null key and multiple null values. Hashtable and ConcurrentHashMap reject null keys and values with a NullPointerException.
- TreeMap ordering
- TreeMap sorts keys by natural ordering or a supplied Comparator and uses compareTo rather than equals to decide key identity and duplicates.
- Stream single use
- A stream pipeline can be consumed only once. Reusing it after a terminal operation throws IllegalStateException.
- Intermediate vs terminal operations
- Intermediate operations such as map, filter, and sorted are lazy and return a stream. Terminal operations such as collect, forEach, and count trigger execution.
- orElse versus orElseGet
- Optional.orElse always evaluates its argument, even when a value is present. orElseGet takes a Supplier and evaluates it only when the Optional is empty.
- partitioningBy result
- Collectors.partitioningBy always returns a Map with exactly two entries keyed Boolean.TRUE and Boolean.FALSE, unlike groupingBy which omits empty groups.
- Thread start versus run
- Calling start creates a new thread that then executes run. Calling run directly executes the method on the current thread without creating a new one.
- volatile guarantees
- volatile ensures visibility and ordering of reads and writes across threads but not atomicity, so incrementing a volatile int is still unsafe without synchronization.
- Thread lifecycle states
- Thread.getState returns NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING, or TERMINATED. BLOCKED means waiting for a monitor lock; WAITING means waiting indefinitely.
- ExecutorService shutdown
- shutdown stops accepting new tasks but lets queued tasks finish. shutdownNow interrupts running tasks and returns the list of tasks never started.
- Serialization transient keyword
- Fields marked transient are skipped during serialization and restored to default values on deserialization. The class must implement Serializable for any of this to apply.
- Path versus File
- Path is the NIO.2 abstraction for a file system location, created with Path.of. Files provides static operations such as exists, readAllLines, and move.
- Files.walkFileTree
- Files.walkFileTree traverses a directory tree with a FileVisitor, giving control over preVisitDirectory, visitFile, and postVisitDirectory, unlike the lazy Files.walk stream.
- Module requires transitive
- requires transitive re-exports a dependency so modules reading your module also read it. Plain requires keeps the dependency internal to your module.
- Module opens directive
- opens grants runtime deep reflection access to a package. Without it, setAccessible fails for non-exported packages in named modules.
- Automatic modules
- A plain JAR placed on the module path becomes an automatic module that exports all its packages and reads all other modules, easing migration.
- Annotation retention policies
- RetentionPolicy.SOURCE discards annotations after compilation, CLASS stores them in bytecode but hides them from reflection, and RUNTIME makes them reflection-visible.
- getMethods versus getDeclaredMethods
- getMethods returns public methods including inherited ones. getDeclaredMethods returns all methods declared in the class, including private ones, but excludes inherited methods.
- Period versus Duration
- Period is date-based, holding years, months, and days. Duration is time-based, holding seconds and nanoseconds, and is used with Instant and time values.