Enums in Java
An enum is a class with a fixed set of instances, which makes an invalid value impossible rather than merely unlikely.
Core Java, object oriented programming, collections, multithreading and JDBC.
100 notes in 18 topics
An enum is a class with a fixed set of instances, which makes an invalid value impossible rather than merely unlikely.
A record declares an immutable data carrier, and the compiler generates the constructor, accessors, equals, hashCode and toString.
An annotation attaches metadata to code. It changes nothing by itself; a compiler, a tool or a framework reads it and acts.
Wrapper classes turn primitives into objects so they can be used with generics and collections, and the conversion is automatic but not free.
Errors, checked exceptions and unchecked exceptions sit in one hierarchy, and knowing which is which decides how you should react.
try guards a block, catch handles specific failures, finally always runs, and try with resources closes what you opened.
throw raises an exception now; throws declares that a method may raise one and leaves the handling to the caller.
A custom exception names a failure in the language of your domain, which makes handling precise and messages meaningful.
The rules that separate exception handling which helps from exception handling which hides bugs.
A small set of interfaces describes how groups of objects behave, and many implementations trade memory, ordering and speed differently.
A List keeps insertion order and allows duplicates. ArrayList is the default; LinkedList wins only at the ends.
A Set stores unique elements. The three implementations differ in ordering and in what uniqueness is based on.