Skip to main content

Спецификация

Книга для подготовки к Oracle OCP

JDK 19 Documentation - Home
https://docs.oracle.com/en/java/javase/19/index.html

Java Tutorials
https://docs.oracle.com/javase/tutorial/tutorialLearningPaths.html

Flight Recorder API Programmer’s Guide
https://docs.oracle.com/en/java/javase/19/jfapi/why-use-jfr-api.html

JDK HTTP Client
http://openjdk.java.net/groups/net/httpclient/

The Java® Language Specification
https://docs.oracle.com/javase/specs/jls/se19/html/index.html

1.5. Preview Features
Разобрать подробно

Programs are written using the Unicode character set (§1.7 (https://docs.oracle.com/javase/specs/jls/se19/html/jls-1.html#jls-1.7)). Information about this character set and its associated character encodings may be found at https://www.unicode.org/.

There are two kinds of comments:
/* text */
A traditional comment: all the text from the ASCII characters /* to the ASCII characters */ is ignored (as in C and C++).
// text
An end-of-line comment: all the text from the ASCII characters // to the end of the line is ignored (as in C++).

An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter.

3.9. Keywords

An integer literal is of type long if it is suffixed with an ASCII letter L or l (ell); otherwise it is of type int

In a hexadecimal or binary literal, the integer is only denoted by the digits after the 0x or 0b characters and before any type suffix. Therefore, underscores may not appear immediately after 0x or 0b, or after the last digit in the numeral.

Note that octal numerals always consist of two or more digits, as 0 alone is always considered to be a decimal numeral - not that it matters much in practice, for the numerals 0, 00, and 0x0 all represent exactly the same integer value.

The largest positive hexadecimal, octal, and binary literals of type int - each of which represents the decimal value 2147483647 (231-1) - are respectively:
0x7fff_ffff,
0177_7777_7777, and
0b0111_1111_1111_1111_1111_1111_1111_1111
The most negative hexadecimal, octal, and binary literals of type int - each of which represents the decimal value -2147483648 (-231) - are respectively:
0x8000_0000,
0200_0000_0000, and
0b1000_0000_0000_0000_0000_0000_0000_0000
The following hexadecimal, octal, and binary literals represent the decimal value -1:
0xffff_ffff,
0377_7777_7777, and
0b1111_1111_1111_1111_1111_1111_1111_1111

A floating-point literal may be expressed in decimal (base 10) or hexadecimal (base 16).

String html = "<html>\n" + " <body>\n" + " <p>Hello, world</p>\n" + " </body>\n" + "</html>\n"; String html = """ <html> <body> <p>Hello, world</p> </body> </html> """;

class Story3 { public static void main(String[] args) { String story = """ "When I use a word," Humpty Dumpty said, in rather a scornful tone, "it means just what I choose it to mean - neither more nor less." "The question is," said Alice, "whether you can make words mean so many different things." "The question is," said Humpty Dumpty, "which is to be master - that's all.\""""; // OK } }

3.12. Operators

The Java programming language is a statically typed language, which means that every variable and every expression has a type that is known at compile time.

The Java programming language is also a strongly typed language, because types limit the values that a variable (§4.12 (https://docs.oracle.com/javase/specs/jls/se19/html/jls-4.html#jls-4.12)) can hold or that an expression can produce, limit the operations supported on those values, and determine the meaning of the operations. Strong static typing helps detect errors at compile time.

The types of the Java programming language are divided into two kinds: primitive types and reference types

A synthetic type variable is a type variable introduced by the compiler during capture conversion (§5.1.10) or inference variable resolution (§18.4).

It is sometimes necessary to find a close supertype of a type, where that supertype does not mention certain synthetic type variables. This is achieved with an upward projection applied to the type.

Similarly, a downward projection may be applied to find a close subtype of a type, where that subtype does not mention certain synthetic type variables. Because such a type does not always exist, downward projection is a partial function.

}
double gausser() {
Random r = new Random();
double[] val = new double[2];
val[0] = r.nextGaussian();
val[1] = r.nextGaussian();
return (val[0] + val[1]) / 2;
}

4.12.5. Initial Values of Variables

class Test { public static void main(String[] args) { // Casting conversion (5.5) of a float literal to // type int. Without the cast operator, this would // be a compile-time error, because this is a // narrowing conversion (5.1.3): int i = (int)12.5f; // String conversion (5.4) of i's int value: System.out.println("(int)12.5f==" + i); // Assignment conversion (5.2) of i's value to type // float. This is a widening conversion (5.1.2): float f = i; // String conversion of f's float value: System.out.println("after float widening: " + f); // Numeric promotion (5.6) of i's value to type // float. This is a binary numeric promotion. // After promotion, the operation is float*float: System.out.print(f); f = f * i; // Two string conversions of i and f: System.out.println("*" + i + "==" + f); // Invocation conversion (5.3) of f's value // to type double, needed because the method Math.sin // accepts only a double argument: double d = Math.sin(f); // Two string conversions of f and d: System.out.println("Math.sin(" + f + ")==" + d); } }

5.1. Kinds of Conversion

The scope of a declaration is the region of the program within which the entity declared by the declaration can be referred to using a simple name, provided it is not shadowed (§6.4.1 (https://docs.oracle.com/javase/specs/jls/se19/html/jls-6.html#jls-6.4.1)).

The package java is always in scope.

6.4.1. Shadowing

Programs are organized as sets of packages. The members of a package (§7.1 (https://docs.oracle.com/javase/specs/jls/se19/html/jls-7.html#jls-7.1)) are classes and interfaces, which are declared in compilation units of the package, and subpackages, which may contain compilation units and subpackages of their own.
Each package has its own set of names for classes and interfaces, which helps to prevent name conflicts. The naming structure for packages is hierarchical.

Модули

Пакеты

Import, static import

Newly declared fields can hide fields declared in a superclass or superinterface. Newly declared member classes and member interfaces can hide member classes and member interfaces declared in a superclass or superinterface. Newly declared methods can hide, implement, or override methods declared in a superclass or superinterface.

synchronized method (§8.4.3.6) automatically locks an object before executing its body and automatically unlocks the object on return, as if by use of a synchronized statement (§14.19), thus allowing its activities to be synchronized with those of other threads

There are three kinds of class declarations: normal class declarations, enum declarations (§8.9), and record declarations (§8.10).

A class can be declared final if its definition is complete and no subclasses are desired or required.

A class body may contain declarations of members of the class, that is, fields (§8.3), methods (§8.4), classes, and interfaces (§8.5).

transient Fields

volatile Fields

The Java programming language allows threads to access shared variables (§17.1). As a rule, to ensure that shared variables are consistently and reliably updated, a thread should ensure that it has exclusive use of such variables by obtaining a lock that, conventionally, enforces mutual exclusion for those shared variables.

The Java programming language provides a second mechanism, volatile fields, that is more convenient than locking for some purposes.

A field may be declared volatile, in which case the Java Memory Model ensures that all threads see a consistent value for the variable

class Test {
Test(/* ?? ?? */) {}
// No receiver parameter is permitted in the constructor of
// a top level class, as there is no conceivable type or name.

void m(Test this) {}
// OK: receiver parameter in an instance method

static void n(Test this) {}
// Illegal: receiver parameter in a static method

class A {
A(Test Test.this) {}
// OK: the receiver parameter represents the instance
// of Test which immediately encloses the instance
// of A being constructed.

void m(A this) {}
// OK: the receiver parameter represents the instance
// of A for which A.m() is invoked.

class B {
B(Test.A A.this) {}
// OK: the receiver parameter represents the instance
// of A which immediately encloses the instance of B
// being constructed.

void m(Test.A.B this) {}
// OK: the receiver parameter represents the instance
// of B for which B.m() is invoked.
}
}
}

native Methods

8.4.8.2. Hiding (by Class Methods)

class C implements Cloneable {
C copy() throws CloneNotSupportedException {
return (C)clone();
}
}
class D extends C implements Cloneable {
D copy() throws CloneNotSupportedException {
return (D)clone();
}
}

Oracle Certified Associate и Oracle Certified Professional. Общее впечатление и нюансы подготовки / Habr
https://habr.com/ru/company/croc/blog/423833/

8.9. Enum Classes

8.10. Record Classes

9. Interfaces
https://docs.oracle.com/javase/specs/jls/se19/html/jls-9.html

10. Arrays
https://docs.oracle.com/javase/specs/jls/se19/html/jls-10.html

11. Exceptions
https://docs.oracle.com/javase/specs/jls/se19/html/jls-11.html

Break и continue с меткой

Внутренние и локальные классы

17. Threads and Locks
https://docs.oracle.com/javase/specs/jls/se19/html/jls-17.html

Почитать, как е вопросы задают на резюме по java core на сеньёра

Слабые ссылки

Шаблоны

enhorse/java-interview: Вопросы и ответы к интервью Java разработчика
https://github.com/enhorse/java-interview