java-guide
A guide to modern Java (Java 17)
This guide is about learning Java from scratch if you know a bit of C or JavaScript.
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.
Note: if you are looking to only what's new in Java 14 I have set of slides for that.
Content
- 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
- class_and_encapsulation.md
- equals_hashCode_toString.md
- contract.md
- modifiable_vs_mutable.md
- null_and_optional.md
- inheritance.md
- exception.md
- enum.md
- nested_classes.md
- array.md
- implementing_interface.md
- generics.md
- wrapper.md
- variance.md
- limitation_of_generics.md
- stream.md
- collector.md
- data_structure.md
- sort.md
Using Java Shell (jshell)
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'
Using Jupyter notebook
on the cloud
You can run it directly in your browser
or using docker
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
or install everything on your laptop
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
from the folderdocker
to the java kernel directorycp docker/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
Build markdown and jupyter files from jshell files
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 --source 14 --enable-preview build/build.java