+
System.out.println("Hell" + 0 + " world");
prints Hell0 world
const
keyword, final
can be used to declare constant 'variables'.boolean
in Java, not bool.default
in function signature: To mention that this definition is the default implementation of this function
interface
.volatile
: used to indicate that a variable may be used by mutliple threads ??javap name.class
: tries to convert a class file back to java file ??API:
switch(exp) {
case One -> 1;
case Two -> 2;
default -> 3;
}
See:
https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html
Example in above link:
Arrays.sort(rosterAsArray,
compareByAge(a, b)
(a, b) -> Person. );
can be achieved with
Arrays.sort(rosterAsArray, Person::compareByAge);
ie, kind of like the usual way of using functions in Haskell.
default
methods: 'A default method is a public non-abstract instance method, that is, a non-static method with a body, declared in an interface type.'ʳ@FunctionalInterface
The value would take the role of the function that was left abstract.
Can think of functions more like values ??
String concat(String s)
vs Function<String, String> concat
See:
$
in identifiers$
is allowed in identifiers, but it is meant to be used selectively by convention.
TL;DR: Better not use it.
From oracle website:
The $ character should be used only in mechanically generated source code or, rarely, to access pre-existing names on legacy systems.
See:
?
: Used as an unknown/any type in generic functions<? super R>
: A class which is a super class of R
R <: ?
<? extends T>
: A class which is derived from class T
? <: T
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/function/Function.html
Interface | Type |
---|---|
Function<A ,B> | A -> B |
BiFunction<A, B, C> | (A, B) -> C |
BinaryOperator<T> | (T, T) -> T |
UnaryOperator<T> | T -> T |
apply
: apply arg function to given argsidentity
: make identity functionandThen
: goes from left to rightcompose
: goes from right to leftThese two are apparently the same, but with argument order reversed.
a.andThen(b)
is same as b.compose(a)
I guess g.compose(f)
is there to be more in line of what we mean when we say g ∘ f
in theory. ie, first do f
and then do g
.
While writing in Java, often the andThen
version is more convenient.
See:
Enforces a form of subtyping ??
See:
There are 8 primitive data types in Java. Some of them:
Primitive | Wrapper |
---|---|
float |
Float |
double |
Double |
char |
Character |
boolean |
Boolean |
string |
String |
https://en.wikipedia.org/wiki/Primitive_wrapper_class_in_Java
double
, not float
Double
Double dD = 3.14;
floatValue(); // is type Float
dD.
double dd = 3.14;:w
float) dd; // is type Float ?? (
https://stackoverflow.com/questions/32837783/convert-double-to-float-in-java
https://programming.guide/java/list-of-java-exceptions.html
java.lang.instrument
package.
null
.
void
is actually like unit
.null
.Doubts: