Java8 Gold exam memorandum

Overwriting

Java class design

Immutable class

static initializer

public class Test {
    static int x;
    static { x = 1; }

Enum

Method Description
static E valueOf(String name) Returns an enumeration constant with the specified name
static E[] values() Return an array of enums
String name() Return the enumeration constant name as a character string
int ordinal() Returns the ordinal of an enumeration constant starting from 0

Additional elements in Java 8

interface A {
    static void test1() {
        System.out.println("static");
    }

    default void test2() {
        System.out.println("default");
    }
}

class B implements A { }

class test {
    public static void main(String[] args) {
        A.test1(); // 「static」
        A.test2(); //Compile error
        B b = new B();
        b.test1(); //Compile error
        b.test2();  // 「default」
    }
}

Design pattern

Singleton

public class Singleton {
    private static Singleton s = new Singleton(); // 1

    private Singleton() {} // 2

    public static Singleton getInstance(){ // 3
        return singleton;
    }
}

(1) Declare a private static field so that only one instance is always created. (2) Declare the constructor as private so that an instance cannot be created from the outside. (3) Declare a public static method that returns an instance so that the instance reference can be obtained from the outside.

Recommended Posts

Java8 Gold exam memorandum
Java8 Silver exam memorandum
Java memorandum
JAVA memorandum
Java memorandum (list)
Java study memorandum
[Java] Optional memorandum
[Qualification Exam] (Java SE8 Gold) Learning Review & Summary
webApi memorandum in java
Java Gold Countermeasures: Localization
Java SE 8 Sliver exam questions
I started Java Gold (Chapter 1-1)
JAVA Silver qualification exam record
On passing Java Gold SE 8
JAVA qualification exam preparation materials
Java Silver exam preparation memo
I took Java SE8 Gold.
Java 3 major elements (object-oriented) memorandum
memorandum
Java
Java SE Bronze exam test content
What I learned with Java Gold
memorandum
Java
Java Silver exam procedure and learning method
Memorandum of new graduate SES [Java basics]
[Creating] A memorandum about coding in Java
Java Silver Exam Reservation Complete Strategy Guide
I tried Google's entrance exam (unofficial) [java]