A guide to modern Java (Java 17)
This is a Work in progress, it should be ready when the next LTS of Java (Java 17) will be released.
All the codes run with Java 14 with the preview features enabled.
- genesis.md
- basic_types.md
- methods.md
- jshell_vs_java.md
- numbers.md
- control_flow.md
- interface.md
- lambda.md
- list_and_map.md
- string_formatting.md
- encapsulation.md
- equals_hashCode_toString.md
- contract.md
- modifable_vs_mutalble.md
- null_and_optional.md
- inheritance.md
- exception.md
- enum.md
- internal_classes.md
- implementing_interface.md
- generics.md
- wrapper.md
- variance.md
- limitation_of_generics.md
- stream.md
- collector.md
- data_structure.md
- sort.md
Each chapter comes with executable examples that you can run using jshell.
To get the examples, just clone this repository
git clone http://github.com/forax/java-guide
Then run jshell (at least Java 14 version)
jshell --enable-preview
Then you can copy paste the examples inside jshell and see by yourself.
To quit use '/exit', to enable verbose error messages '/set feedback verbose', otherwise to get the help type '/help'
You can run it directly in your browser
You need to have docker already installed, then
- get the docker image from dockerhub
docker pull forax/java-guide
- run the docker image in a container
docker run -p 8888:8888 forax/java-guide
- open your browser using the
tokenId
printed on the consolefirefox http://localhost:8888/?token=tokenId
You need to have python3 and Java 14 already installed, then
- clone this repository
git clone http://github.com/forax/java-guide cd java-guide
- install jupyter
pip install notebook
- install the ijava 1.3.0 kernel (from Spencer Park)
wget https://github.com/SpencerPark/IJava/releases/download/v1.3.0/ijava-1.3.0.zip python3 install.py --sys-prefix
- patch it with the repository file
kernel.json
list all kernels to see if the java kernel is installedthen copy the filejupyter kernelspec list
kernel.json
to the java kernel directorycp kernel.json /path/to/jupyter/kernels/java
- set the env compiler option enabling the preview features
export IJAVA_COMPILER_OPTS="--enable-preview -source 14"
- run the notebook
cd jupyter jupyter notebook
The markdown files (.md) and the jupyter files (.ipynb) are derived/generated from the jshell files using a small Java script.
Using java 14
java --enable-preview build/build.java