Some code for practicing for the Java 8 OCP / Java SE 8 Programmer (1Z0-809).
150min (2.5h), 85 questions, 65% to pass.
- Lambdas
- Streams
- File IO
- NIO
- Generics
- Collection API
- File IO (Writer, Reader, ...)
- NIO 2: Path, Files, String, Stringwriter
- Exceptions
- HashMap
- Abstrakte Klassen
- Annotations
- Date/Time API
- Concurrency Updates
- Reflection
- Java OCP study book
- Learning the Java Language: Table of Contents
- java-certificate.com
- Java 8 Streams Tutorial
- Java Streams Cheat Sheet
- Java Docs on
Optional
- Why does Java have
transient
fields? - Java Docs on Varargs
- Use @Override annotation when implementing abstract methods?
- Methods in interface with or without a public/abstract access modifier?
- Defining an Interface
- Java Docs on StringBuilder
- Formatting Print Output
- The 'Immutable Interface' Pattern
- Java packages overview
- Java Class Library (JCL) - main features
- Data Access Object
- Liste von Entwurfsmustern
- Scope of private constructor in nested class
- Should an abstract class have at least one abstract method?
- Information & changes to exam topics
- Unbound wildcard
<?>
vs<T>
- Static Initialization Blocks
- Why to use
finally
- Java Docs on Autoboxing
- Java Docs on
Collections.binarySearch()
- Java Docs on Numbers Classes
- Access modifier review (
public
,default
,protected
,private
) -
transient
keyword (= "field should not be serialized") - Varargs
- Stringbuilder
- exact behaviour of
instanceof
(withnull
and usage on interfaces) - packages & imports (static imports, important
java.*
packages) - More keywords:
synchronized
,transient
,native
- Review: java.lang.Object & overridable methods
- Review: Inheritance & interfaces
- Java 8: Interfaces with default method implementation
- Review Exceptions, exception hierarchy tree
- Autoboxing, Unboxing
-
Comparable
interface -
static
,abstract
andfinal
keywords. Final fields vs. methods vs. classes -
Serializable
,writeObject()
- Review:
abstract
classes vs. interfaces - Collection API: set vs. map), lower/upper/wildcard bound
- Design Patterns: Singleton & Immutable creational patterns
- Review: Singleton classes
- Review: Inner classes
- Review: Generics, generic classes/interfaces, usage
- Generics: Wildcards
- toString on Enums will print String, not ordinal
- "An abstract type can be an abstract class or interface."
- "In a subclass, the compiler implicitly invokes a parameterless constructor in the superclass if a superclass constructor is not explicitly invoked."
- "Top-level classes cannot be declared using the protected access modifier. Only the access modifier public is allowed for top-level classes. An inner class can be declared with the access modifier protected because an inner class is a member of the top-level class."
- "Overriding methods can specify access modifiers that are less restrictive than the original method. Also, Java allows an overriding method to return a subtype of the return type of the original method."
- Command line params start at
args[0]
and are always Strings. - "It is permitted, but discouraged as a matter of style, to redundantly specify the public and/or abstract modifier for a method declared in an interface."
- "If you do not specify that the interface is public, then your interface is accessible only to classes defined in the same package as the interface."
- "Static methods can not be overridden in the exact sense of the word, but they can hide parent static methods" (source)
- Enums can not have a public constructor. All Enum values ("inner subclasses") will be constructed the first time a Enum value is used.
- "The first time that we ask for any of the
enum
values (of a certain Enum) Java constructs all of theenum
values." - "In Java 8, the 'effectively final' concept was introduced. If the code can still compile with the keyword
final
inserted before the local variable, the variable is effectively final." (study book) - Inner classes: "If the member or constructor is declared private, then access is permitted if and only if it occurs within the body of the top level class (§7.6) that encloses the declaration of the member or constructor." source
- 'local inner class' = nested class defined within a method
- Floats (for example) as class variables (not local ones) will be initialized with
0.0
, but not inside a method! - In a concrete class, all methods and Constructors must contain bodies.
- A class cannot include package or import statements. (class itself not, but file that contains class)
- (
abstract
) classes can be extended,interfaces
can be implemented (orextended
, if you're aninterface
yourself). In other words, valid examples are:interface extends interface
/class extends class
/class implements interface
. - "A JavaBean is a design principle for encapsulating data in an object in Java."
- A new
public StringBuilder()
has initial capacity of 16 characters. - Parentheses for Lambda parameter: can be omitted only if one parameter (not if 0 or 2+) and there is no type given.
- "Tight coupling is the practice of developing coupled classes that are highly dependent, such that a minor change in one class may greatly impact the other class. Alternatively, loose coupling is the practice of developing coupled classes with minimum dependencies on one another."
- "An instant is a point in time. A LocalDateTime does not contain a time zone, and is therefore not universally recognized around the world as the same moment in time."
- "The
CyclicBarrier
class allows us to perform complex, multi-threaded tasks, while all threads stop and wait at logical barriers."
Modifier | Class | Package | Subclass | World |
---|---|---|---|---|
public | Y | Y | Y | Y |
protected | Y | Y | Y | N |
no modifier | Y | Y | N | N |
private | Y | N | N | N |
Functional Interface | # Parameters | Return Type | Single Abstract Method |
---|---|---|---|
Supplier<T> |
0 | T | get |
Consumer<T> |
1 (T) | void | accept |
BiConsumer<T, U> |
2 (T, U) | void | accept |
Predicate<T> |
1 (T) | boolean | test |
BiPredicate<T, U> |
2 (T, U) | boolean | test |
Function<T> |
1 (T) | R | apply |
BiFunction<T, U> |
2 (T, U) | R | apply |
UnaryOperator<T> |
1 (T) | T | apply |
BinaryOperator<T, U> |
2 (T, U) | T | apply |
E
for an elementK
for a map keyV
for a map valueN
for a numberT
for a generic data typeS
,U
,V
, and so forth for multiple generic types
Checked:
java.text.ParseException
java.io.IOException
(generally all checked)java.io.FileNotFoundException
java.io.NotSerializableException
java.sql.SQLException
Unchecked:
java.lang.ArithmeticException
java.lang.ArrayIndexOutOfBoundsException
java.lang.ClassCastException
java.lang.IllegalArgumentException
java.lang.NullPointerException
java.lang.NumberFormatException
java.lang.ArrayStoreException
java.lang.DateTimeException
java.lang.MissingResourceException
java.lang.IllegalStateException
java.lang.UnsupportedOperationException
- Singleton pattern: Only one instance of a Singleton class may exist at runtime.
- Immutable pattern: Read-only objects.
- Builder pattern: Enrich object with attributes through setters (chainable) and create instance with
build()
- Factory pattern: Return different object types, based on given criteria, for example
PetFactory
which returns either aDog
orCat
instance.
Steps to make a class immutable:
- Use a constructor to set all properties of the object
- Mark all instance variables as
private
andfinal
- Don't define any setter methods
- Don't allow referenced mutable objects to be modified or accessed directly
- Prevent methods from being overriden
Rules for picking a resource bundle:
- The requested locale as
.java
-File - The requested locale as
.properties
-File - Only requested language (no country) as
.java
-File - Only requested language (no country) as
.properties
-File - The default locale as
.java
-File - The default locale as
.properties
-File - Only default language (no country) as
.java
-File - Only default language (no country) as
.properties
-File - The default bundle with no locale as
.java
-File - The default bundle with no locale as
.properties
-File - A
MissingResourceException
is thrown.