Java specification memo

A personal memo that I haven't put together with the intention of letting others read it.

Primitive Type

Inheritance

Inheritance example:

interface Foo {
    void bar();
}

class Foo extends Bar implements Foo {
    ...
}

Multiple inheritance

operator

Override of equals

final, finally, finalize

final

finally

finalize

Modifier

abstract

protected

private

static

volatile

class

External class

Inner class

Local class

static inner class

String

Integer

Deque Double-ended queue. Since it implements Queue interface, it can be used as Queue, but Stack is a class, so it is not implemented. On the other hand, Stack is recommended in the Stack documentation, such as Use Deque over Stack. You should use Deque when you need a wind interface. Stack implements Vector, which allows index access that seems unnecessary.

In general, LinkedList has $ O (1) $ for all operations, and an implementation like ArrayDeque has an additional worst calculation time of $ O (n) $, but Time Complexity for all operations is $ O in Amortized Analysis. (1) It becomes $.

Class that reserves a continuous area of the heap

Be careful not to use too much memory

Legacy class

Comparison

There are two main ways to implement arbitrary class comparisons.

Comparable.compareTo

class Foo implements Comparable<Foo> {
    int key;

    public Foo(int key) { 
        this.key = key;
    }

    @Override
    public int compareTo(Foo f){
        return this.key - f.key;
    }
}

Collections.sort(fooList);
Collections.sort(fooList, Collections.reverseOrder());

Comparator.compare

class FooComparator implements Comparator<Foo> {
    @Override
    public int compare(Foo a, Foo b) {
        return a.key - b.key;
    }
}

Collections.sort(fooList, new FooComparator());

thread

Example of usage

class Foo implements Runnable {
    public void run() {
        while (true) System.out.print(".");
    }
}

Foo foo = new Foo();
Thread thread = new Thread(foo);
thread.start();

Classes that are not thread-safe

It is necessary to handle with synchronized etc. when there is access in parallel

reference

There are the following types of references:

https://docs.oracle.com/javase/jp/8/docs/api/java/lang/ref/Reference.html

Generics

Other things I want to find out later

Recommended Posts

Java specification memo
Java memo
java anything memo
Java Silver memo
java, maven memo
Java SE 7 memo
java anything memo 2
Java pattern memo
Java development environment memo
java basic knowledge memo
Java learning memo (method)
Java Kuche Day memo
[Java ~ Method ~] Study memo (5)
java se 8 programmer Ⅰ memo
Java paid private memo
[Java ~ Array ~] Study memo 4
Java learning memo (basic)
java lambda expression memo
(Memo) Java for statement
Java lambda expression [memo]
Java learning memo (interface)
[Java] Implicit inheritance memo
Java learning memo (inheritance)
java competitive programming memo
[Memo] Java Linked List
Java (WebSphere Application Server) memo [1]
[Java] Variable name naming memo
Java memo (standard class) substring
Java learning memo (data type)
Java memo (standard class) length
Java Silver Study Method Memo
[Java ~ Boolean value ~] Study memo (2)
Create a java method [Memo] [java11]
Java Silver exam preparation memo
Java learning memo (logical operator)
Java
Java learning memo (abstract class)
[Java] Date Related Term Memo
Java
Recent Java API specification generation
What are Java metrics? _Memo_20200818
Java HashMap, entrySet [Personal memo]
[Eclipse Java] Development environment setting memo
Java learning memo (creating an array)
Personal memo: Metaprogramming with Java reflection
[Java] Memo for naming class names
[Study session memo] Java Day Tokyo 2017
Java learning memo (while statement, do-while statement)
From Java to VB.NET-Writing Contrast Memo-
[Java] Processing time measurement method memo
I tried using Java memo LocalDate
Integer memo
docker memo
Java learning (0)
Studying Java ―― 3
[Java] array
Java protected
[Java] Annotation
[Java] Module
Java array
Studying Java ―― 9