A subset of the Java language (experimental)
Experimental. rontolisp reads a subset of the Java language and lowers it to the same
core forms as Common Lisp, so a .java program runs on every backend. It is a subset by
design and nothing here is a compatibility promise: a construct outside it is refused by
name, with its position, before anything runs. The front end and its library are written
for rontolisp from the published specifications; no JDK code is read, bundled or shipped
in a compiled program.
A .java file is read as this subset; --source-language java says so for any other file
and for -e. A program is the file it starts at, the files of its source tree that
file names, and what it reaches of the libraries on its source path
(Using a library).
rontolisp Hello.java # interpreter
rontolisp Hello.java -o Hello.class && java Hello # JVM
rontolisp Hello.java -o hello.wasm && wasmtime run hello.wasm
rontolisp Hello.java -o hello-c.wasm --component && wasmtime run hello-c.wasm
rontolisp -e 'void main() { IO.println(1 + 2); }' --source-language java
--no-gc is refused: that backend has no structures, strings or closures. With no program,
--source-language java starts a REPL (At the prompt).
examples/java/ holds a
program of several packages with its expected output, an HTTP server with its client, a
miniature httpbin, and a form validated with a library read from its sources jar.
circle 1.5, 2 shapes, total 11.068583470577035
-2147483648
Where a program starts
At the first class of the file when it has a main, otherwise at the class named as the
file. main(String[]) is chosen before main(); an instance main runs on an instance
made with the constructor of no argument. The argument array is empty. A file whose
top level holds methods and fields is a compact source file: they are the members of one
class, and every library class is in scope without an import. A class declared beside them
is a member of that class too: an inner class, unless it is static, a record, an enum or
an interface.
A program of several files
A class the program names that no file read so far declares is read from the file its
package and name spell under the root of the source tree, the directory above the
starting file's package: for app/Main.java declaring package app;, util.Strings is
util/Strings.java and Helper of the package app is app/Helper.java. Every class of a
file read joins the program, and the program is compiled whole. The directories above the
starting file must spell its package. A (load "app/Main.java") from Common Lisp runs the
program as rontolisp app/Main.java does (Across languages).
$ rontolisp app/Main.java
$ rontolisp app/Main.java -o main.wasm
An import names a class, a package on demand, module java.base (every class of the
library but java.sql's), module java.sql, or with static a static member of a class, or
all of them on demand. A package imported on demand shadows a module imported, and a name
two packages of one kind bring is refused (reference to Date is ambiguous). A class
that is not public and a member with no access modifier are reached from their own
package only, a protected member from its package and from the classes under its class.
Using a library
A class the program names that its source tree does not declare is read next from the
program's source path: the roots of the libraries it uses, as source. A library is
compiled with the program, on every backend, as far as the program reaches it; nothing is
carried beside the output, so a .wasm holds what it uses of the library.
$ rontolisp app/Main.java --java-source-path libs/geo-sources.jar:other/src/main/java
$ rontolisp app/Main.java --java-source-dep org.example:geo:1.2.0 -o main.wasm
--java-source-pathtakes directories and jars, separated as a class path is. A classgeo.Tableisgeo/Table.javaunder the first root that has it.--java-source-deptakes Maven coordinates and may be repeated: the sources jar of the library (geo-1.2.0-sources.jar) and of what it depends on at run time join the source path, from Maven Central through~/.m2/repository;--java-repositoryadds a repository. A library named that publishes no sources jar is refused. One it depends on that publishes none is a warning, and its classes are not there.
examples/java/yavi
has two programs over YAVI, --java-source-dep am.ik.yavi:yavi:0.18.0, that run on every
backend: one validates a record, the other reads one from a map with a schema.
This is not --java-classpath and --java-dep: those are class files the host runs for a
java: call from Common Lisp or Clojure, and a program of the Java subset calls none.
Whether a library works is decided by what the program reaches of it. Only the methods called, the classes instantiated and the static initializers used are compiled, each with the checks a program's own code gets. So a library works when the part the program uses stays within the subset and the library classes this page lists. What the program reaches and the subset lacks is an error at the place in the library, with the way the program comes to it:
geo-sources.jar!/geo/Table.java:42:54: the class java.util.Currency is not supported by the experimental Java subset yet
reached through geo.Table.column(String,geo.Table.ToMoney)
A class a library names only in a declaration, such as a parameter's type of a method the program never calls, is passed by. An annotation in a library whose type is not on the source path is dropped, as a compiler reads a class file without it: annotation-only dependencies need not be there. A class declared in a file named after another class is found once that file was read. A source file of the program wins over one of the same name on the source path.
At the prompt
--source-language java with no program, and the playground's Java pick, read a buffer at a
time: a statement, an expression, a variable, a method, a class or an import. A statement
needs no ;. An expression is shown under a generated name, $1, $2, ..., which a later
buffer can read with the expression's type; a variable under its own name. A string and a
char are shown as literals, an array with its type and elements.
java> int twice(int n) { return 2 * n; }
java> int quad(int n) { return twice(twice(n)); }
java> quad(1)
$1 ==> 4
java> int twice(int n) { return n + 1; }
java> quad(1)
$2 ==> 3
java> var names = new String[] { "a", "b" }
names ==> String[2] { "a", "b" }
java> 1 / 0
Error: Exception java.lang.ArithmeticException: / by zero
A declaration replaces the earlier one of its name (a method: of its name and parameter types),
and what was declared before calls the new one: a method, an override, a subclass added later
is reached by every call. A class keeps its static fields until it is declared again; then the
variables whose type names it hold null. The session reads no file of a source tree; a class
of a library on the source path is read as a program's is. The playground
has no source path.
Across languages
A Common Lisp program loads a .java file. A file with a main runs it; a file with none
defines its classes and runs nothing. A static method is the function named by its class, its
name and its parameter types: |Geometry.area(int)|, |app.Geometry.area(int)| in a package,
|Point.new(int,int)| for a constructor. A native static method of a Java program is the
Common Lisp function its name spells, a hyphen before each capital: stringUpcase is
string-upcase, read in the package the program is loaded in.
$ cat Geometry.java
record Point(int x, int y) { }
class Geometry {
static native int square(int n);
static native String stringUpcase(String s);
static int norm2(Point p) {
return square(p.x()) + square(p.y());
}
static String shout(String s) {
return stringUpcase(s) + "!";
}
}
$ cat main.lisp
(defun square (n) (* n n))
(load "Geometry.java")
(print (|Geometry.norm2(Point)| (|Point.new(int,int)| 3 4)))
(print (|Geometry.shout(String)| "hi"))
$ rontolisp main.lisp
25
"HI!"
Nothing is converted but this: a char crosses as a character, a boolean comes back as T
or NIL. A number is a number, a string a string, null is NIL, an object of the program a
structure, an Object[] a vector. A Common Lisp list is no List: hand a Java method a vector.
The tools
rontolisp test refuses a .java file: the subset has no test framework, and a program's
exit status is its verdict. rontolisp format refuses one: it re-indents S-expressions.
A Maven project
The wasm goal of rontolisp-maven-plugin compiles the program in a Maven project's
src/main/java to WebAssembly at package, starting at its main class. javac still
compiles the same sources and surefire still runs their tests, so the program also runs
on a JDK.
<plugin>
<groupId>am.ik.rontolisp</groupId>
<artifactId>rontolisp-maven-plugin</artifactId>
<version>VERSION</version>
<configuration>
<mainClass>app.Main</mainClass>
</configuration>
<executions>
<execution>
<id>preview1</id>
<goals><goal>wasm</goal></goals>
</execution>
<execution>
<id>component</id>
<goals><goal>wasm</goal></goals>
<configuration>
<component>true</component>
<outputFile>${project.build.directory}/app-component.wasm</outputFile>
</configuration>
</execution>
</executions>
</plugin>
$ mvn package
$ wasmtime run target/app-1.0.0.wasm
$ wasmtime run target/app-component.wasm
- The program is the one
rontolisp src/main/java/app/Main.java -o target/app-1.0.0.wasmcompiles: the main class's file and the files of the tree it names (A program of several files). - The output is
target/<finalName>.wasmunlessoutputFilenames another;<native>true</native>writes the native executabletarget/<finalName>. - The parameters are the command line's flags in camel case:
component,noWasi,optimize,simd,hostRandom,hostFetch,reentrant,hostBoundary,reportLocations,emitWit,emitJsGlue,native,nativeTarget,nativeCpu,dynamic,noPrune,warningsAsErrors,javaSourcePath.skip(-Drontolisp.skip=true) turns the goal off. - The front end reads source, not class files (Using a library). The
sources jar of each
compile,providedandsystemdependency is fetched from the project's repositories and joins the source path, after the directories and jars<javaSourcePath>lists. A dependency with no sources jar is a warning; a class of it the program names fails the goal with its name and position, for@Nullablefrom such a jar:.../app/Main.java:7:9: cannot find symbol: class Nullable. - When no
.javafile of the tree or of a directory on the source path and no jar on it is newer than the last build, none was added or removed, the parameters and the source path are the same and the output exists, nothing is compiled. Otherwise the whole program is. - An HTTP server built with
componentruns fromtarget/underwasmtime serve.
What is read
| Types | int, long, short, byte, char, double, float, boolean, String, classes, interfaces, enums, records, arrays; var for a local; type arguments, wildcards (?, ? extends T, ? super T) and raw types; an inner class of a parameterized class (Outer<String>.Inner) |
| Declarations | classes with extends and implements, abstract classes and methods; classes, interfaces, records and methods with type parameters and their bounds; enums with fields, constructors, methods and constants that have a body; records with compact and canonical constructors; interfaces with abstract, default, static and private methods and constants; sealed, permits and non-sealed; static nested, inner, local and anonymous classes; fields, static fields, a field hiding one of a class above it, static and instance initializer blocks; constructors with this(..), super(..) and outer.super(..) and statements ahead of them; overloaded and variable arity methods; synchronized methods and volatile fields; package and import |
| Statements | local variables (final, the unnamed _), if, while, do, for, the enhanced for over an array or an Iterable, switch with colon or arrow cases, patterns and guards, labeled statements, break and continue with or without a label, yield, return, throw, try with catch (of one type or several) and finally, try-with-resources, synchronized over an object or a class literal |
| Expressions | every operator of the primitive types with its conversions, string concatenation, the conditional, assignments and compound assignments, casts (to several types, (A & B) x, a lambda and a method reference too), instanceof with a type, a type pattern or a record pattern, switch expressions, new with or without the constructor's type arguments (new <T>Box(..)), outer.new Inner() with or without a class body, Outer.this, array creation with one or several lengths and initializers, text blocks, method calls with or without type arguments, super.m(..), super.x for a field, Interface.super.m(..), Outer.super.m(..), new Box<>(..) with or without a class body, lambdas and method references (Type::name, expression::name, super::name, Type::new, int[]::new, List<String>::size, Type::<T>name, Type::<T>new) for any functional interface |
An annotation is read and dropped, on a declaration and on a type (List<@Label String>),
but for what a compiler checks of @Override and @FunctionalInterface and for the
warnings @SuppressWarnings("unchecked") and @SafeVarargs silence. Its name has to be
one of an annotation type the file can see -- those of java.lang and
java.lang.annotation, one the program or a library declares with @interface -- and any
other name is refused as a compiler refuses it. Nothing reads an annotation where the
program runs. An int, a long, a short and a byte wrap as two's
complement; a float is rounded to single precision at every operation. A double and a
float print as the shortest text that reads back as the same value of their type.
Circle[r=1.0] is a shape of area 3.141592653589793
Rect[w=2.0, h=2.0] is a square of area 4.0
Rect[w=2.0, h=3.0] is a shape of area 6.0
CM 0 1 small
M 1 100 large
Unchecked warnings
What a compiler warns of as unchecked -- a member called through a raw type, a raw type
converted to a parameterized one, a cast the program that runs cannot check, a variable
arity parameter of a type it cannot check -- is printed on standard error before the
program runs, as a compiler prints it. A compile prints them as it compiles; the compiled
program prints nothing. A declaration annotated @SuppressWarnings("unchecked") warns of
nothing inside it. A catch clause nothing reaches, because the clauses before it take
every exception of its try it could, is warned of in the same way
(unreachable catch clause).
[ann]
Run as Raw.java, it prints first, on standard error:
Raw.java:3: warning: [unchecked] unchecked call to add(E) as a member of the raw type List
names.add("ann");
^
where E is a type-variable:
E extends Object declared in interface List
1 warning
Type parameters, lambdas and method references
A type parameter exists only while the program is read: the type arguments of a call and of
new Box<>(..) are found from the arguments, from the type the value is wanted as and from
the lambdas among the arguments, and a value is boxed or unboxed where a type argument is a
box. A lambda and a method reference are made for any interface with one abstract method,
the program's or the library's.
[4, 3, 6] Pair[first=pear, second=6] Pair[first=pear, second=9.0]
1 [false, false, true]
The library
Each class has the members listed and no others; a missing class or member is refused by
name. String, StringBuilder, the boxes, Math, System and IO are part of the
front end. Every other class is written in the subset itself and compiled with the program
as far as the program reaches it, so a class of the program can extend or implement one
(AbstractList, Iterable, Comparator).
| Class | Members |
|---|---|
Object | new Object(), toString, equals, hashCode, getClass(), wait(), wait(long), notify, notifyAll |
Class | a class literal (Name.class, int.class, String[].class, void.class) and getClass(); getName, getSimpleName, getCanonicalName, getTypeName, getPackageName, getSuperclass, getComponentType, isInstance, cast, isAssignableFrom, isInterface, isArray, isPrimitive, isEnum, isRecord, getEnumConstants, toString, equals, hashCode |
| An enum | values(), valueOf(String), Enum.valueOf(Class, String), name, ordinal, compareTo, getDeclaringClass, toString |
| A record | the accessors, equals, hashCode, toString |
| An array | length, clone() |
String | length, charAt, isEmpty, isBlank, equals, equalsIgnoreCase, compareTo, compareToIgnoreCase, hashCode, substring, subSequence, indexOf and lastIndexOf of a string or a character with or without a start, indexOf within a range, codePointAt, codePointBefore, codePointCount, offsetByCodePoints, regionMatches, contentEquals, getChars, indent, contains, startsWith, endsWith, toUpperCase, toLowerCase, trim, strip, stripLeading, stripTrailing, repeat, replace, replaceAll, replaceFirst, matches, concat, toCharArray, split, intern, formatted, getBytes of nothing, a Charset or a charset's name, toUpperCase and toLowerCase of a Locale; String.valueOf, String.copyValueOf, String.join, String.format with or without a Locale, String.CASE_INSENSITIVE_ORDER; new String(), new String(String), new String(char[]), new String(char[], int, int), new String(byte[]) with or without a range and a Charset or a charset's name, chars, codePoints, lines |
StringBuilder, StringBuffer | the constructors of nothing, a capacity or a text; append of a value or of a range of a text or of a char[], insert, reverse, setLength, setCharAt, deleteCharAt, delete, replace, indexOf and lastIndexOf with or without a start, appendCodePoint, repeat of a text or a code point, compareTo, toString, length, isEmpty, charAt, substring, subSequence, chars, codePoints |
CharSequence | length, charAt, subSequence, isEmpty, chars, codePoints; a String and a StringBuilder are one |
Appendable | append of a CharSequence, of a range of one and of a char; a StringBuilder, a Writer and a PrintStream are one |
Integer, Long | boxing and unboxing; MAX_VALUE, MIN_VALUE, SIZE, BYTES, parseInt / parseLong with or without a radix, valueOf, decode, toString with or without a radix, toBinaryString, toHexString, toOctalString, Integer.parseUnsignedInt and Long.parseUnsignedLong with or without a radix, toUnsignedString with or without a radix, Integer.toUnsignedLong, divideUnsigned, remainderUnsigned, compareUnsigned, highestOneBit, lowestOneBit, numberOfLeadingZeros, numberOfTrailingZeros, reverse, reverseBytes, rotateLeft, rotateRight, compare, signum, sum, max, min, bitCount, hashCode, intValue, longValue, doubleValue, compareTo |
Byte, Short | boxing and unboxing; MAX_VALUE, MIN_VALUE, SIZE, BYTES, parseByte / parseShort with or without a radix, valueOf, toString, compare, hashCode, toUnsignedInt, byteValue / shortValue, intValue, longValue, floatValue, doubleValue, compareTo |
Float | MAX_VALUE, MIN_VALUE, MIN_NORMAL, MAX_EXPONENT, MIN_EXPONENT, SIZE, BYTES, POSITIVE_INFINITY, NEGATIVE_INFINITY, NaN, parseFloat, valueOf, toString, toHexString, compare, hashCode, floatToIntBits, floatToRawIntBits, intBitsToFloat, isNaN, isInfinite, isFinite, sum, max, min, floatValue, doubleValue, intValue, longValue, compareTo |
Double | MAX_VALUE, MIN_VALUE, MIN_NORMAL, MAX_EXPONENT, MIN_EXPONENT, SIZE, BYTES, POSITIVE_INFINITY, NEGATIVE_INFINITY, NaN, parseDouble, valueOf, toString, toHexString, compare, hashCode, doubleToLongBits, doubleToRawLongBits, longBitsToDouble, isNaN, isInfinite, isFinite, sum, max, min, intValue, longValue, doubleValue, compareTo |
Boolean, Character | Boolean.TRUE, FALSE, parseBoolean, valueOf, toString, hashCode, compare, logicalAnd, logicalOr, logicalXor, booleanValue, compareTo; Character.MAX_VALUE, MIN_VALUE, valueOf, toString, compare, hashCode, isDigit, isLetter, isLetterOrDigit, isAlphabetic, isWhitespace, isSpaceChar, isUpperCase, isLowerCase, toUpperCase, toLowerCase, getNumericValue, digit, forDigit, charValue, compareTo; getType and the constants of the general categories, isTitleCase, isDefined, isMirrored, isIdeographic, isISOControl, isJavaIdentifierStart, isJavaIdentifierPart, isUnicodeIdentifierStart, isUnicodeIdentifierPart, isIdentifierIgnorable, isEmoji, isEmojiPresentation, isEmojiModifier, isEmojiModifierBase, isEmojiComponent, isExtendedPictographic, each test of a char or of a code point; toChars of a code point with or without an array to write into, codePointAt of an array, reverseBytes, toString of a code point, charCount, isValidCodePoint, isBmpCodePoint, isSupplementaryCodePoint, isHighSurrogate, isLowSurrogate, isSurrogate, isSurrogatePair, toCodePoint, highSurrogate, lowSurrogate; MIN_RADIX, MAX_RADIX, SIZE, BYTES, MIN_CODE_POINT, MAX_CODE_POINT, MIN_SUPPLEMENTARY_CODE_POINT and the bounds of the surrogates |
Number | intValue, longValue, floatValue, doubleValue, byteValue, shortValue; a class extending it, which declares the first four |
Math, StrictMath | PI, E, TAU, abs, max, min, sqrt, cbrt, pow, exp, log, log10, floor, ceil, rint, round, signum, sin, cos, tan, asin, acos, atan, atan2, sinh, cosh, tanh, hypot, toRadians, toDegrees, floorDiv, floorMod, random, addExact, subtractExact, multiplyExact, negateExact, toIntExact, absExact, incrementExact, decrementExact, divideExact, floorDivExact, ceilDivExact, ceilDiv, ceilMod, clamp, multiplyFull, multiplyHigh, unsignedMultiplyHigh, log1p, expm1, IEEEremainder, copySign, getExponent, nextAfter, ulp, nextUp, nextDown, fma, scalb |
System | out, err (each a PrintStream), in (an InputStream), currentTimeMillis, nanoTime, exit, arraycopy, identityHashCode, lineSeparator, getProperty with or without a default, getenv of a name, gc |
Runtime | Runtime.getRuntime, availableProcessors, gc, exit, halt |
IO | println, print, readln |
InputStream, OutputStream | read of a byte or into an array, readAllBytes, readNBytes, skip, skipNBytes, available, mark, reset, markSupported, transferTo, close, InputStream.nullInputStream; write of a byte or of an array, flush, close, OutputStream.nullOutputStream; a class of the program extends either |
ByteArrayInputStream, ByteArrayOutputStream | over a byte[] or a range of one; toByteArray, size, reset, writeTo, writeBytes, toString with or without a charset |
FilterInputStream, FilterOutputStream, BufferedInputStream, BufferedOutputStream | a stream over another, the buffered ones with or without a size |
PushbackInputStream, SequenceInputStream | with or without a size, unread of a byte or of an array; over two streams or an Enumeration of them |
DataInput, DataOutput, DataInputStream, DataOutputStream | readBoolean, readByte, readUnsignedByte, readShort, readUnsignedShort, readChar, readInt, readLong, readFloat, readDouble, readFully, skipBytes, readLine, readUTF; the write of each, writeBytes, writeChars, writeUTF, size |
PrintStream | over an OutputStream, with or without automatic flushing and a charset; print and println of each type, printf and format with or without a Locale, append, write, writeBytes, flush, close, checkError, charset |
Reader, Writer | read of a character or into an array, skip, ready, mark, reset, markSupported, transferTo, close; write of a character, an array or a string, append, flush, close; Reader.nullReader, Writer.nullWriter; a class of the program extends either |
FilterReader, FilterWriter, CharArrayReader, CharArrayWriter, PushbackReader, LineNumberReader | a reader or a writer over another; over a char[] or a range of one, toCharArray, size, reset, writeTo; with or without a size, unread of a character or of an array; getLineNumber, setLineNumber |
StringReader, StringWriter, InputStreamReader, OutputStreamWriter | over a string; getBuffer, toString; over a stream, with or without a Charset or a charset's name, getEncoding |
BufferedReader, BufferedWriter, PrintWriter | with or without a buffer size; readLine, lines; newLine; a PrintWriter over a Writer or an OutputStream, with or without automatic flushing and a charset, with the members of PrintStream over characters |
Charset, StandardCharsets | UTF_8, ISO_8859_1, US_ASCII, UTF_16, UTF_16BE, UTF_16LE; Charset.forName, defaultCharset, isSupported, name, displayName, toString |
Locale | ROOT, ENGLISH, US, UK, CANADA, Locale.getDefault (which is US), getLanguage, getCountry, toLanguageTag, toString |
MessageFormat | new MessageFormat of a pattern with or without a Locale, MessageFormat.format; format of an Object[], applyPattern, toPattern, getLocale, setLocale. A pattern's arguments {n} with no format type: a number is written as a JDK writes one in English (1,000, 1,234.568), a BigInteger and a BigDecimal from their own digits, any other value as its toString |
Normalizer, Normalizer.Form | Normalizer.normalize and isNormalized of a CharSequence and a form; the forms NFD, NFC, NFKD, NFKC |
Iterable, Iterator | iterator, forEach, spliterator; hasNext, next, remove, forEachRemaining |
Spliterator, Spliterators, RandomAccess | tryAdvance, forEachRemaining, trySplit, estimateSize, getExactSizeIfKnown, characteristics, hasCharacteristics, getComparator and the eight characteristics; a collection's spliterator reports the characteristics and the estimate a JDK's reports; Spliterators.spliterator of a collection, an iterator and its size or an array, spliteratorUnknownSize, emptySpliterator, iterator, AbstractSpliterator; RandomAccess, which ArrayList and the lists of List.of and Arrays.asList are |
Collection | size, isEmpty, contains, add, remove, containsAll, addAll, removeAll, retainAll, removeIf, clear, toArray of nothing, an array or a function making one, iterator, forEach, stream, parallelStream, equals, hashCode, toString |
List, ArrayList | the members of Collection; get, set, add and addAll at an index, remove at an index, indexOf, lastIndexOf, subList, sort, replaceAll, getFirst, getLast, removeFirst, removeLast, addFirst, addLast, reversed, listIterator with or without an index (a ListIterator: hasNext, next, hasPrevious, previous, nextIndex, previousIndex, remove, set, add); List.of, List.copyOf; new ArrayList<>() of nothing, a capacity or a collection, ensureCapacity, trimToSize |
Set, HashSet | the members of Collection; Set.of, Set.copyOf; new HashSet<>() of nothing, a capacity or a collection |
Map, HashMap, Map.Entry | size, isEmpty, containsKey, containsValue, get, getOrDefault, put, putIfAbsent, putAll, remove, replace, clear, keySet, values, entrySet, forEach, replaceAll, computeIfAbsent, computeIfPresent, compute, merge, equals, hashCode, toString; Map.of up to ten pairs, Map.entry, Map.ofEntries, Map.copyOf; new HashMap<>() of nothing, a capacity or a map; getKey, getValue, setValue, Map.Entry.comparingByKey, comparingByValue; AbstractMap.SimpleEntry and SimpleImmutableEntry of a key and a value or of an entry |
LinkedHashMap, LinkedHashSet | the members of HashMap and HashSet, walked in the order the keys were added; new LinkedHashMap<>(capacity, loadFactor, true), walked in the order they were last reached, and removeEldestEntry, asked after each key added; new LinkedHashSet<>() of nothing, a capacity or a collection |
Queue, Deque, ArrayDeque | the members of Collection; offer, poll, peek, element, remove; addFirst, addLast, offerFirst, offerLast, removeFirst, removeLast, pollFirst, pollLast, getFirst, getLast, peekFirst, peekLast, push, pop, descendingIterator |
LinkedList | the members of List and Deque; removeFirstOccurrence, removeLastOccurrence; null elements; of nothing or a collection |
AbstractCollection, AbstractList, AbstractSequentialList, AbstractSet, AbstractMap | what a class of the program extends to be a collection |
Vector, Stack, Enumeration | the members of ArrayList; addElement, elementAt, firstElement, lastElement, setElementAt, insertElementAt, removeElementAt, removeElement, removeAllElements, elements; push, pop, peek, empty, search; hasMoreElements, nextElement |
Hashtable | the members of Map; keys, elements, contains; no null key or value |
Arrays | asList, toString, fill, equals, copyOf, copyOfRange, sort of a whole array or a range, with or without a comparator, binarySearch; over arrays of int, long, double, char, boolean and of objects; toString, fill, equals, copyOf and copyOfRange of a byte[]; toString and equals of a short[] and a float[]; hashCode of every array; setAll of an int[], a long[], a double[] and an array of objects; deepToString, deepEquals, deepHashCode; stream of an array of objects, an int[], a long[] or a double[], or of a range of one; spliterator of an array of objects or of a range of one |
Collections | sort, binarySearch with or without a comparator, reverse, shuffle, swap, max, min, frequency, addAll, fill, nCopies, emptyList, emptySet, emptyMap, singletonList, singleton, unmodifiableList, unmodifiableSet, unmodifiableCollection, unmodifiableMap, synchronizedList, synchronizedSet, synchronizedCollection, synchronizedMap, reverseOrder, rotate, replaceAll, indexOfSubList, lastIndexOfSubList |
Objects | equals, hashCode, hash, toString, isNull, nonNull, requireNonNull with or without a message or a supplier of one, requireNonNullElse, requireNonNullElseGet, compare, checkIndex, checkFromIndexSize, checkFromToIndex |
Optional | empty, of, ofNullable, isPresent, isEmpty, get, orElse, orElseGet, orElseThrow, ifPresent, ifPresentOrElse, filter, map, flatMap, or, stream, equals, hashCode, toString |
OptionalInt, OptionalLong, OptionalDouble | empty, of, isPresent, isEmpty, getAsInt / getAsLong / getAsDouble, orElse, orElseGet, orElseThrow, ifPresent, ifPresentOrElse, stream, equals, hashCode, toString |
Stream | Stream.of, ofNullable, empty, iterate with or without a test, generate, concat, builder; filter, map, mapToInt, mapToLong, mapToDouble, flatMap, flatMapToInt, flatMapToLong, flatMapToDouble, distinct, sorted with or without a comparator, peek, limit, skip, takeWhile, dropWhile; forEach, forEachOrdered, toArray of nothing or a function making the array, reduce in its three forms, collect of a Collector or of three functions, toList, min, max, count, anyMatch, allMatch, noneMatch, findFirst, findAny, iterator; parallel, sequential, isParallel, unordered, onClose, close |
IntStream, LongStream, DoubleStream | of, empty, iterate, generate, concat, builder, and of the first two range and rangeClosed; the members of Stream over numbers, with mapToObj, boxed, asLongStream, asDoubleStream, sum, average, min, max, summaryStatistics, toArray, and an iterator that is a PrimitiveIterator.OfInt, OfLong or OfDouble |
Collectors | toList, toSet, toCollection, toUnmodifiableList, toUnmodifiableSet, toMap and toUnmodifiableMap of two functions, with a merge function, and toMap with a map's supplier too; joining of nothing, a delimiter, or one with a prefix and a suffix; groupingBy of a classifier, with a collector, and with a map's supplier too; partitioningBy with or without a collector; counting, summingInt / Long / Double, averagingInt / Long / Double, summarizingInt / Long / Double, minBy, maxBy, reducing in its three forms, mapping, filtering, flatMapping, collectingAndThen, teeing |
Collector | supplier, accumulator, combiner, finisher, characteristics; Collector.of with or without a finisher; Collector.Characteristics |
StreamSupport | stream of a spliterator, or of a supplier of one and its characteristics; the spliterator is asked for its elements when the stream is, and count() of one that says SIZED runs no stage |
IntSummaryStatistics, LongSummaryStatistics, DoubleSummaryStatistics | of nothing, or of a count, a minimum, a maximum and a sum; accept, combine, getCount, getSum, getMin, getMax, getAverage, toString |
Random | new Random(), new Random(long), setSeed, nextInt(), nextInt(int), nextLong, nextDouble, nextBoolean, nextGaussian; a seed gives the specified sequence |
UUID | new UUID(long, long), fromString, randomUUID; getMostSignificantBits, getLeastSignificantBits, version, variant, compareTo, equals, hashCode, toString. fromString takes the forms a JDK takes, such as 1-1-1-1-1; randomUUID is version 4 |
BigInteger | ZERO, ONE, TWO, TEN, valueOf; new BigInteger of a text with or without a radix, of the bytes of a two's complement or a range of them, of a sign and a magnitude; add, subtract, multiply, divide, remainder, mod, divideAndRemainder, pow, gcd, abs, negate, signum, sqrt, sqrtAndRemainder, modPow, modInverse; shiftLeft, shiftRight, and, or, xor, not, andNot, testBit, setBit, clearBit, flipBit, getLowestSetBit, bitLength, bitCount; compareTo, equals, hashCode, min, max; toString with or without a radix, toByteArray; intValue, longValue, floatValue, doubleValue, intValueExact, longValueExact, shortValueExact, byteValueExact |
BigDecimal | ZERO, ONE, TWO, TEN; valueOf of a long, of an unscaled long and a scale, of a double; new BigDecimal of a text, a char[] or a range of one, an int, a long, a double, a BigInteger with or without a scale, each with or without a MathContext; add, subtract, multiply, divide, divideToIntegralValue, remainder, divideAndRemainder and pow, each with or without a MathContext; divide at a scale or with a RoundingMode; sqrt, abs, negate, plus, round; signum, scale, precision, unscaledValue, setScale, movePointLeft, movePointRight, scaleByPowerOfTen, stripTrailingZeros, ulp; compareTo, equals, hashCode, min, max; toString, toEngineeringString, toPlainString; toBigInteger, toBigIntegerExact, intValue, longValue, floatValue, doubleValue, intValueExact, longValueExact, shortValueExact, byteValueExact; the older ROUND_UP .. ROUND_UNNECESSARY and the members taking one |
MathContext, RoundingMode | new MathContext of a precision with or without a RoundingMode, or of the text toString writes; UNLIMITED, DECIMAL32, DECIMAL64, DECIMAL128; getPrecision, getRoundingMode, equals, hashCode, toString; the eight modes and RoundingMode.valueOf(int) |
Comparator | compare, reversed, thenComparing of a comparator, of a key or of a key and its comparator, thenComparingInt, thenComparingLong, thenComparingDouble, Comparator.naturalOrder, reverseOrder, comparing with or without a comparator of the key, comparingInt, comparingLong, comparingDouble, nullsFirst, nullsLast |
| Exceptions | Throwable, Exception, Error, RuntimeException, IllegalArgumentException, IllegalStateException, ArithmeticException, NullPointerException, ClassCastException, IndexOutOfBoundsException, ArrayIndexOutOfBoundsException, StringIndexOutOfBoundsException, NegativeArraySizeException, UnsupportedOperationException, NumberFormatException, CloneNotSupportedException, InterruptedException, IllegalMonitorStateException, IllegalThreadStateException, NoSuchElementException, InputMismatchException, ConcurrentModificationException, EmptyStackException, MatchException, ArrayStoreException, SecurityException, AssertionError, VirtualMachineError, StackOverflowError, OutOfMemoryError, LinkageError, NoClassDefFoundError, ExceptionInInitializerError with getException, IOException, EOFException, FileNotFoundException, UTFDataFormatException, UnsupportedEncodingException, UncheckedIOException, UnsupportedCharsetException, IllegalCharsetNameException: the constructors of the API -- of no argument, of a message, of a message and a cause, of a cause, of an index --, getMessage, getLocalizedMessage, getCause, initCause, addSuppressed, getSuppressed, printStackTrace(), getStackTrace, setStackTrace, fillInStackTrace, toString; StackTraceElement with its constructor of four arguments, getClassName, getMethodName, getFileName, getLineNumber, isNativeMethod. IllegalFormatException and three subclasses the run time raises, with no constructor: IllegalFormatConversionException, UnknownFormatConversionException, MissingFormatArgumentException. Of java.util.concurrent: ExecutionException, TimeoutException, CancellationException, RejectedExecutionException, CompletionException, BrokenBarrierException |
Runnable, Comparable, AutoCloseable, Closeable, Flushable | run; compareTo, which a String, a box and an enum constant have too; close; flush |
Thread | the constructors of nothing, a Runnable, a name or both; a class extending it; start, run, join(), join(long), join(Duration), interrupt, isInterrupted, isAlive, getName, setName, isDaemon, setDaemon, getPriority, setPriority, isVirtual, threadId, getId, toString; Thread.currentThread, sleep(long), sleep(long, int), sleep(Duration), yield, onSpinWait, interrupted, holdsLock, startVirtualThread; Thread.ofPlatform() and ofVirtual() with name, daemon, priority, start, unstarted, factory; getState and Thread.State; setUncaughtExceptionHandler, getUncaughtExceptionHandler, Thread.setDefaultUncaughtExceptionHandler, getDefaultUncaughtExceptionHandler |
ThreadLocal, InheritableThreadLocal | new ThreadLocal<>(), withInitial, get, set, remove, initialValue; childValue |
AtomicInteger, AtomicLong | get, set, lazySet, getAndSet, compareAndSet, getAndAdd, addAndGet, getAndIncrement, getAndDecrement, incrementAndGet, decrementAndGet, getAndUpdate, updateAndGet, getAndAccumulate, accumulateAndGet, toString; each is a Number |
AtomicBoolean, AtomicReference | get, set, lazySet, getAndSet, compareAndSet, toString; of a reference also getAndUpdate, updateAndGet, getAndAccumulate, accumulateAndGet |
AtomicIntegerArray, AtomicLongArray, AtomicReferenceArray, LongAdder | of a length or an array; the members of the atomic of one value, each with an index, length, toString; add, increment, decrement, sum, reset, sumThenReset, toString; a LongAdder is a Number |
LongAccumulator, DoubleAdder, DoubleAccumulator | of a function and its identity; accumulate, get, reset, getThenReset; add, sum, reset, sumThenReset; toString; each is a Number |
AtomicIntegerFieldUpdater, AtomicLongFieldUpdater, AtomicReferenceFieldUpdater | newUpdater of class literals and a constant field name; get, set, lazySet, getAndSet, compareAndSet, weakCompareAndSet, getAndUpdate, updateAndGet, getAndAccumulate, accumulateAndGet; of an int and a long also getAndAdd, addAndGet, getAndIncrement, getAndDecrement, incrementAndGet, decrementAndGet |
TimeUnit | the seven units; convert, toNanos, toMicros, toMillis, toSeconds, toMinutes, toHours, toDays, sleep, timedJoin, timedWait |
Lock, ReentrantLock, Condition | lock, lockInterruptibly, tryLock with or without a limit, unlock, newCondition, isLocked, isHeldByCurrentThread, getHoldCount, isFair, hasQueuedThreads, getQueueLength, toString; await with or without a limit, awaitNanos, awaitUninterruptibly, signal, signalAll |
ReadWriteLock, ReentrantReadWriteLock | readLock and writeLock, each a Lock, the write lock with conditions; getReadLockCount, getReadHoldCount, getWriteHoldCount, isWriteLocked, isWriteLockedByCurrentThread, isFair, hasQueuedThreads, getQueueLength, toString |
StampedLock | writeLock, readLock, each also Interruptibly and as try.. with or without a limit; tryOptimisticRead, validate; unlockWrite, unlockRead, unlock, tryUnlockWrite, tryUnlockRead; tryConvertToWriteLock, tryConvertToReadLock, tryConvertToOptimisticRead; isWriteLocked, isReadLocked, getReadLockCount, isLockStamp, isWriteLockStamp, isReadLockStamp, isOptimisticReadStamp; asReadLock, asWriteLock, asReadWriteLock; toString. A stamp is the number a JDK 25 gives |
CountDownLatch, Semaphore | await with or without a limit, countDown, getCount; acquire, acquireUninterruptibly, tryAcquire with or without a limit, release, each of one permit or several, availablePermits, drainPermits, isFair; toString of both |
CyclicBarrier, Exchanger | of a number of threads, with or without an action; await with or without a limit, reset, isBroken, getParties, getNumberWaiting; exchange with or without a limit |
Phaser | of nothing, a number of parties, a parent or both; register, bulkRegister, arrive, arriveAndDeregister, arriveAndAwaitAdvance, awaitAdvance, awaitAdvanceInterruptibly with or without a limit, forceTermination, getPhase, getRegisteredParties, getArrivedParties, getUnarrivedParties, getParent, getRoot, isTerminated, toString; onAdvance to override |
BlockingQueue, ArrayBlockingQueue, LinkedBlockingQueue, SynchronousQueue, ConcurrentLinkedQueue | the members of Queue; of a blocking queue also put, take, offer and poll with a limit, remainingCapacity, drainTo; a SynchronousQueue holds nothing and hands an element from the thread putting it to the one taking it |
TransferQueue, LinkedTransferQueue | the members of a blocking queue; transfer, tryTransfer with or without a limit, hasWaitingConsumer, getWaitingConsumerCount |
BlockingDeque, LinkedBlockingDeque, ConcurrentLinkedDeque | the members of Deque; of a blocking deque also those of a blocking queue, and at either end putFirst, putLast, takeFirst, takeLast, offerFirst, offerLast, pollFirst and pollLast with a limit |
ConcurrentMap, ConcurrentHashMap | the members of Map; remove of a key and its value, replace of an old value, mappingCount, contains, keys, elements, keySet of a value, ConcurrentHashMap.newKeySet; of nothing, a capacity or a map; no null key or value |
CopyOnWriteArrayList, CopyOnWriteArraySet | the members of List, or of Set; addIfAbsent, addAllAbsent; an iterator walks the list there was when it was made and changes nothing |
Executor, ExecutorService, Executors | execute, submit of a Callable or a Runnable, invokeAll and invokeAny with or without a limit, shutdown, shutdownNow, isShutdown, isTerminated, awaitTermination, close; newFixedThreadPool, newSingleThreadExecutor, newCachedThreadPool, newScheduledThreadPool, newSingleThreadScheduledExecutor, each with or without a ThreadFactory, newVirtualThreadPerTaskExecutor, newThreadPerTaskExecutor, unconfigurableExecutorService, unconfigurableScheduledExecutorService, defaultThreadFactory, callable |
ThreadPoolExecutor, RejectedExecutionHandler | of a core size, a most size, a time and a queue, with or without a ThreadFactory, a handler or both; AbortPolicy, CallerRunsPolicy, DiscardPolicy, DiscardOldestPolicy; getPoolSize, getCorePoolSize, getMaximumPoolSize, getLargestPoolSize, getActiveCount, getTaskCount, getCompletedTaskCount, getKeepAliveTime, getQueue, getThreadFactory, getRejectedExecutionHandler, setRejectedExecutionHandler, setCorePoolSize, setMaximumPoolSize, setKeepAliveTime, setThreadFactory, allowCoreThreadTimeOut, allowsCoreThreadTimeOut, prestartCoreThread, prestartAllCoreThreads, remove, purge, isTerminating, toString; beforeExecute, afterExecute and terminated to override |
ScheduledExecutorService, ScheduledThreadPoolExecutor, ScheduledFuture, Delayed | schedule of a Runnable or a Callable, scheduleAtFixedRate, scheduleWithFixedDelay; of a core size, with or without a ThreadFactory; setRemoveOnCancelPolicy, setExecuteExistingDelayedTasksAfterShutdownPolicy, setContinueExistingPeriodicTasksAfterShutdownPolicy and what reads them; getDelay, compareTo |
ForkJoinPool, ForkJoinTask, RecursiveTask, RecursiveAction, CountedCompleter | new ForkJoinPool(), of a parallelism, ForkJoinPool.commonPool; invoke, execute, submit, getParallelism, getCommonPoolParallelism, getPoolSize and the members of ExecutorService; fork, join, invoke, invokeAll, get with or without a limit, cancel, isDone, isCancelled, isCompletedNormally, isCompletedAbnormally, getException, complete, completeExceptionally, quietlyComplete, quietlyJoin, quietlyInvoke, getRawResult, ForkJoinTask.adapt, inForkJoinPool, getPool; compute; of a CountedCompleter also tryComplete, propagateCompletion, onCompletion, onExceptionalCompletion, getCompleter, getRoot, getPendingCount, setPendingCount, addToPendingCount, compareAndSetPendingCount, decrementPendingCountUnlessZero, firstComplete, nextComplete, quietlyCompleteRoot, helpComplete |
Timer, TimerTask | of nothing, a name, a daemon flag or both; schedule of a delay with or without a period, scheduleAtFixedRate, cancel, purge; run, cancel, scheduledExecutionTime |
Callable, Future, FutureTask, ThreadFactory | call; get with or without a limit, isDone, cancel, isCancelled, state, resultNow, exceptionNow; run, toString; newThread |
CompletableFuture, CompletionStage | supplyAsync and runAsync with or without an executor, completedFuture, failedFuture, completedStage, failedStage, allOf, anyOf; thenApply, thenAccept, thenRun, thenCompose, handle, whenComplete, thenCombine, thenAcceptBoth, runAfterBoth, applyToEither, acceptEither, runAfterEither, exceptionally, exceptionallyCompose, each also Async with or without an executor; complete, completeExceptionally, completeAsync, obtrudeValue, obtrudeException, cancel, orTimeout, completeOnTimeout, delayedExecutor, copy, minimalCompletionStage, newIncompleteFuture, defaultExecutor, join, get with or without a limit, getNow, isDone, isCancelled, isCompletedExceptionally, getNumberOfDependents, state, resultNow, exceptionNow, toString |
java.util.function | Function, BiFunction, UnaryOperator, BinaryOperator, Supplier, Consumer, BiConsumer, Predicate, BiPredicate, BooleanSupplier; for Int, Long and Double: IntFunction, IntPredicate, IntUnaryOperator, IntBinaryOperator, IntSupplier, IntConsumer, ToIntFunction, ToIntBiFunction, ObjIntConsumer; from one of the three to another, IntToLongFunction, IntToDoubleFunction, LongToIntFunction, LongToDoubleFunction, DoubleToIntFunction, DoubleToLongFunction; each with its abstract method and its andThen, compose, and, or, negate, identity, not, isEqual |
Duration | ZERO; ofDays, ofHours, ofMinutes, ofSeconds with or without nanoseconds, ofMillis, ofNanos, parse; getSeconds, getNano, isZero, isNegative, isPositive; of a count of a unit, between, from; plus and minus of a Duration or a count of a unit, plusDays .. plusNanos, minusDays .. minusNanos, multipliedBy, negated, abs, withSeconds, withNanos, truncatedTo; get, getUnits, addTo, subtractFrom; toDays, toHours, toMinutes, toSeconds, toMillis, toNanos, toDaysPart .. toNanosPart; compareTo, equals, hashCode, toString; DateTimeException, DateTimeParseException |
LocalDate | MIN, MAX, EPOCH; now with or without a zone or a Clock, of, ofYearDay, ofEpochDay, ofInstant, parse, from; getYear, getMonth, getMonthValue, getDayOfMonth, getDayOfYear, getDayOfWeek, isLeapYear, lengthOfMonth, lengthOfYear; withYear .. withDayOfYear, plusYears .. plusDays, minusYears .. minusDays; until of a date as a Period; atTime, atStartOfDay with or without a zone, toEpochDay, toEpochSecond; isAfter, isBefore, isEqual, compareTo, equals, hashCode, toString |
LocalTime | MIN, MAX, MIDNIGHT, NOON; now, of, ofSecondOfDay, ofNanoOfDay, ofInstant, parse, from; getHour .. getNano; withHour .. withNano, plusHours .. plusNanos, minusHours .. minusNanos, truncatedTo; atDate, toSecondOfDay, toNanoOfDay, toEpochSecond; isAfter, isBefore, compareTo, equals, hashCode, toString |
LocalDateTime | MIN, MAX; now, of a date and a time or their numbers, ofInstant, ofEpochSecond, parse, from; toLocalDate, toLocalTime and the getters of both; withYear .. withNano, plusYears .. plusNanos, minusYears .. minusNanos, truncatedTo; atOffset, atZone, toEpochSecond, toInstant; isAfter, isBefore, isEqual, compareTo, equals, hashCode, toString |
OffsetDateTime | MIN, MAX; now, of, ofInstant, parse, from; getOffset, withOffsetSameLocal, withOffsetSameInstant, toLocalDateTime, toLocalDate, toLocalTime and the getters, with.., plus.., minus.. and truncatedTo of a LocalDateTime; toInstant, toEpochSecond, toZonedDateTime, atZoneSameInstant, atZoneSimilarLocal; isAfter, isBefore, isEqual, compareTo, equals, hashCode, toString |
ZonedDateTime | now, of, ofLocal, ofInstant, ofStrict, parse, from; getOffset, getZone, withZoneSameLocal, withZoneSameInstant, withFixedOffsetZone, withEarlierOffsetAtOverlap, withLaterOffsetAtOverlap, toLocalDateTime, toLocalDate, toLocalTime and the getters, with.., plus.., minus.. and truncatedTo of a LocalDateTime; toOffsetDateTime, toInstant, toEpochSecond; isAfter, isBefore, isEqual, compareTo, equals, hashCode, toString |
Instant | EPOCH, MIN, MAX; now with or without a Clock, ofEpochSecond with or without nanoseconds, ofEpochMilli, parse, from; getEpochSecond, getNano, toEpochMilli; plusSeconds, plusMillis, plusNanos, minusSeconds, minusMillis, minusNanos, truncatedTo; atOffset, atZone; isAfter, isBefore, compareTo, equals, hashCode, toString |
Year, YearMonth | now, of, parse, from; Year.isLeap, getValue, isLeap, length, plusYears, minusYears, atDay, atMonth; getYear, getMonth, getMonthValue, isLeapYear, isValidDay, lengthOfMonth, lengthOfYear, withYear, withMonth, plusYears, plusMonths, minusYears, minusMonths, atDay, atEndOfMonth; isAfter, isBefore, compareTo, equals, hashCode, toString |
Period | ZERO; of, ofYears, ofMonths, ofWeeks, ofDays, between, parse, from; getYears, getMonths, getDays, isZero, isNegative, toTotalMonths; withYears .. withDays, plus and minus of an amount, plusYears .. plusDays, minusYears .. minusDays, multipliedBy, negated, normalized; get, getUnits, addTo, subtractFrom; equals, hashCode, toString |
java.time.temporal | Temporal, TemporalAccessor, TemporalAdjuster, TemporalAmount, TemporalField, TemporalUnit, ChronoField, ChronoUnit, ValueRange, UnsupportedTemporalTypeException. Each date and time class above: isSupported of a field or a unit, get, getLong, range, with of a field or an adjuster, plus and minus of an amount or a count of a unit, until in a unit, adjustInto. A program may write its own field, unit, adjuster and amount |
java.time.chrono | ChronoLocalDate, ChronoLocalDateTime, ChronoZonedDateTime: what LocalDate, LocalDateTime and ZonedDateTime are, with their conversions and their order |
ZoneOffset, ZoneId, ZoneRules | UTC, MIN, MAX; ZoneOffset.of, ofHours, ofHoursMinutes, ofHoursMinutesSeconds, ofTotalSeconds, from, getTotalSeconds, compareTo; ZoneId.of, ofOffset, systemDefault, from, getId, getRules, normalized, equals, hashCode, toString; ZoneRules.of, isFixedOffset, getOffset, getValidOffsets, isValidOffset, getStandardOffset, getDaylightSavings, isDaylightSavings; ZoneRulesException. The zones are the ones whose offset never changes |
Clock | systemUTC, systemDefaultZone, system, fixed, offset, tick, tickSeconds, tickMinutes, tickMillis; instant, millis, getZone, withZone; a class extending it |
DayOfWeek, Month | the constants; of, from, getValue, plus, minus; Month.length, minLength, maxLength, firstDayOfYear, firstMonthOfQuarter |
java.util.Date | new Date(), new Date(long), Date.from; getTime, setTime, before, after, compareTo, equals, hashCode, toInstant, toString |
java.sql.Date, Time, Timestamp | the package of the module java.sql. new of the milliseconds; valueOf of a text, of a LocalDate, a LocalTime or a LocalDateTime; toLocalDate, toLocalTime, toLocalDateTime, toString; Timestamp.from, toInstant, getNanos, setNanos, equals, compareTo, before and after of a Timestamp. A wall time is read and written in the host's zone, in the Julian calendar before 1582-10-15 |
URI, URISyntaxException | new URI(String), URI.create; getScheme, getSchemeSpecificPart, getAuthority, getUserInfo, getHost, getPort, getPath, getQuery, getFragment and the getRaw.. of each; isAbsolute, isOpaque, resolve of a URI or a string, equals, hashCode, compareTo, toString; getInput, getReason, getIndex |
HttpClient | newHttpClient; newBuilder with version, followRedirects, executor, connectTimeout, build; send, sendAsync, followRedirects, version, executor, connectTimeout, close, shutdown, shutdownNow, isTerminated; HttpClient.Version, HttpClient.Redirect |
HttpRequest | newBuilder with or without a URI, with uri, header, headers, setHeader, GET, POST, PUT, DELETE, HEAD, method, version, expectContinue, timeout, copy, build; method, uri, headers, bodyPublisher, version, expectContinue, timeout, equals, hashCode, toString; BodyPublishers.ofString with or without a Charset, ofByteArray of an array or a range, ofInputStream, noBody; BodyPublisher.contentLength |
HttpResponse | statusCode, headers, body, uri, request, previousResponse, version, toString; BodyHandlers.ofString with or without a Charset, ofByteArray, ofInputStream, discarding, replacing; BodySubscribers of the same and mapping; a BodyHandler of the program's own choosing one by the ResponseInfo (statusCode, headers, version) |
HttpHeaders | firstValue, firstValueAsLong, allValues, map, HttpHeaders.of, equals, hashCode, toString |
HttpTimeoutException, HttpConnectTimeoutException | of a message; what send throws, and what the future of sendAsync completes with, when a time limit passes |
HttpServer, HttpContext, HttpHandler | HttpServer.create of nothing, of an address and a backlog, or of those with a path, a handler and filters, bind, createContext with or without a handler, removeContext of a path or a context, setExecutor, getExecutor, start, stop, getAddress; getPath, getHandler, setHandler, getServer, getAttributes, getFilters, setAuthenticator, getAuthenticator; handle |
HttpExchange, Request | getRequestMethod, getRequestURI, getProtocol, getRequestHeaders, getRequestBody, getResponseHeaders, sendResponseHeaders, getResponseBody, getResponseCode, close, getHttpContext, getRemoteAddress, getLocalAddress, getAttribute, setAttribute, setStreams, getPrincipal; with |
Filter, HttpHandlers | doFilter, description, Filter.beforeHandler, afterHandler, adaptRequest; new Filter.Chain of filters and a handler, its doFilter; HttpHandlers.of a status, fields and a body, handleOrElse |
Authenticator, BasicAuthenticator, HttpPrincipal | authenticate; Failure, Retry and Success with getResponseCode or getPrincipal; a BasicAuthenticator of a realm, with or without a Charset, getRealm, checkCredentials; new HttpPrincipal of a user and a realm, getUsername, getRealm, getName, equals, hashCode, toString |
Headers | the members of Map; getFirst, add, set; new Headers() of nothing or a map, Headers.of of names and values in turn or of a map |
InetSocketAddress, InetAddress, BindException, UnknownHostException | of a port, of a host and a port, of an InetAddress and a port, createUnresolved; getPort, getHostString, getHostName, getAddress, isUnresolved, equals, hashCode, toString; getHostAddress, getHostName, getAddress, isLoopbackAddress, isAnyLocalAddress, InetAddress.getLoopbackAddress, getByName and getAllByName of an address in numbers or localhost, getByAddress |
String.format, formatted and printf take %d, %s, %S, %f, %e, %E, %x,
%X, %o, %c, %b, %h, %H, %n and %%, with the flags -, 0, +, a space, ,, ( and
#, a width, a precision and an argument index (%2$s).
java.util.regex.Pattern and Matcher take the syntax the Pattern documentation
describes -- classes with unions and intersections, groups (capturing, named, atomic),
lookahead and lookbehind, back references, greedy, reluctant and possessive quantifiers,
the inline flags, \\p{..} properties, \\X and \\b{g} -- and so do String.matches,
replaceAll, replaceFirst and split. A malformed pattern is a
PatternSyntaxException with a JDK's message. A Matcher searches a region
(region, useAnchoringBounds, useTransparentBounds), tells whether a search read the
end of the input (hitEnd, requireEnd), builds a replacement match by match
(appendReplacement, appendTail, replaceAll of a function) and keeps a match
(toMatchResult). Pattern.splitAsStream and Matcher.results answer a stream. See
deviations.
A stream takes its elements from its source one at a time when its last operation asks for
them, so a stage sees an element only once every stage before it let that element through,
and a stream with no end can be cut by limit, takeWhile or findFirst. count() runs
no stage where the source and the stages tell how many elements there are, as a JDK 25
does: a collection, an array or a range through map, peek, sorted, skip, limit
or boxed. A stream is read once; a second operation on it is an IllegalStateException.
[Bergen, Lyon, Oslo, Paris]
{NO=2, FI=1, FR=2}
{NO=Oslo+Bergen, FI=Turku, FR=Lyon+Paris}
IntSummaryStatistics{count=5, sum=3824, min=201, average=764.800000, max=2103}
Paris
55 [1, 2, 4, 8, 16, 32, 64, 128]
4 to,be,or,not
The streams of java.io are over arrays, strings, the standard streams and each other;
there are no files. A PrintStream, a PrintWriter and the two bridges between bytes and
characters take UTF-8 (the default), ISO-8859-1, US-ASCII, UTF-16, UTF-16BE or
UTF-16LE.
12 bytes: 2026 naïve
FIRST
SECOND
A HashMap, a HashSet and a Hashtable find a key by its equals and hashCode, and
walk their keys in the order a JDK's do; a LinkedHashMap and a LinkedHashSet in the
order the keys came in.
origin [0, 1] [Point[x=1, y=1], Point[x=3, y=1]] [not, be, or, to]
pi | 3.14|0042|ff
tried 30
insufficient funds: 30
tried 100
tried 50
2 ok, 1 refused, null
Threads
A Thread is started, joined, interrupted and named as the language says. synchronized
holds the monitor of an object, wait and notify hand it from one thread to another,
and a volatile field is read as the last write left it. What a thread leaves uncaught is
written to standard error with the thread's name and its causes, and ends that thread alone. The program
ends when every thread that is no daemon has.
4000 after worker-3
On the interpreter and the JVM a thread is a virtual thread of the host, and threads run
in parallel. A .wasm has one stack, and its threads take turns on it: a thread runs until
it waits, sleeps, yields or ends, and goes on from there at a later turn. A program whose
threads share what they share under a monitor, a volatile field or an atomic prints the
same on every backend; what the turns change for any other is in
Deviations.
Run on these pages, and the playground, run a program that starts threads as such a
.wasm, compiled in the page (Deviations).
java.util.concurrent has locks, latches, barriers, queues, a concurrent map, executors
-- a pool of a program's own, a scheduled one, a fork/join pool -- and CompletableFuture,
and java.util a Timer, all written over the same monitors. Vector, Hashtable, StringBuffer
and the wrappers of Collections.synchronizedList and the like hold their own monitor
in every member.
{one=3, seven=5, three=5} 8
HTTP
java.net.http has the client. An HttpClient sends an HttpRequest and answers an
HttpResponse whose body is what the handler makes of the reply: send once the reply is
in, sendAsync as a CompletableFuture. Every request goes through
rontolisp:fetch, so one source runs on every transport fetch
has:
| Target | Build | Transport |
|---|---|---|
| Interpreter, JVM | rontolisp App.java, -o App.class | the JDK's HttpClient |
| WASM component | -o app.wasm --component, run with wasmtime run -S http=y | wasi:http |
| Native executable | --native | the executable's own client |
A plain Preview 1 module has no transport: the compile refuses the program, naming the
flags that give it one. java.net is part of java.base; a compact source file imports
the client with import module java.net.http;.
200 application/json
404
A builder refuses what a JDK's refuses, with its message: a restricted or malformed header,
a URI that is no absolute http or https one. followRedirects(Redirect.NORMAL) and
ALWAYS follow a 301, 302, 303, 307 and 308 as a JDK's client does, and
previousResponse() answers the replies on the way. A connection that is refused is a
ConnectException. HttpRequest.Builder.timeout limits how long a reply may take to start
and HttpClient.Builder.connectTimeout how long a connection may take, each a
java.time.Duration: a request that passes one is an HttpTimeoutException or an
HttpConnectTimeoutException. What the transports cannot give and what is not there:
Deviations.
com.sun.net.httpserver has the server: an HttpServer, its contexts, and an HttpHandler
answering an HttpExchange. It serves through the transport of the target, so one source
is a server on each:
| Target | Build | Who listens |
|---|---|---|
| Interpreter, JVM | rontolisp App.java, -o App.class | the program, on the address create was given |
| WASM component | -o app.wasm --component, run with wasmtime serve -S cli=y app.wasm | the host (--addr), which calls the program for each request through wasi:http |
| Native executable | --native | the executable, on the address create was given |
A plain Preview 1 module cannot listen: create throws an IOException naming
--component and --native. A compact source file imports the server with
import module jdk.httpserver;.
A program lives while a server it started runs: main may return or wait, and requests
are answered until stop. A handler runs on a thread of the executor the server was given
and may wait for the program's other threads; a context has its filters
(getFilters) and its authenticator. Under wasmtime serve the host starts the program
for the requests it likes, and the address of create is not bound.
sendResponseHeaders(status, length) announces a body of that length, -1 none, and 0 a
body of a length not told ahead, which goes out chunk by chunk as it is written where the
transport can (under wasmtime serve), and whole elsewhere.
This program serves one context and asks it once from main, so it runs where the target
has threads, the interpreter and the JVM:
200 Hello, Ann!
A server on its own, and how to run it on each target, is
examples/java/http.
What the transports cannot give and what is not there:
Deviations.
What differs from the language and what is refused: Deviations.