Slide navigation: Forward with space bar, →, or swipe left. Backwards with ← or swipe right. Switch slides with PgDn and PgUp.
Slides at https://horstmann.com/presentations/2025/javaone
java
path/to/MyProg.java
.java
#!/usr/bin/env java --source 25
.java
///usr/bin/env java --source 25 "$0" "$@" ; exit $?
~/bin/BackupFileFilter.java
class MyClass { void main() { ... } ... }
String[]
parameterpublic
, protected
, static
, but why?class MyClass
, but just
var variable = initialValue; Type method(
Type param, ... ) { ... }
void main() { ... }
IO
class with static println
, print
, readln
~/bin/Audio.java
and its shell predecessor ~/bin/audio
brick = [ { 'x': 0, 'y': 0 }, { 'x': 10, 'y': 20 }]
record Brick(Point topLeft, Point bottomRight)
toString
, equals
, hashCode
record Brick(...) { static Brick parse(String s) { ... } boolean overlaps(Brick other) { ... } }
enum
var userIdMap = new HashMap<String,User>();beats
userIdMap = {} # Map from user ID to User object
import static java.lang.System.*; import static java.lang.Math.*; err.println(sqrt(PI));
var
, diamondList.of
, Map.of
var seasons = List.of("Spring", "Summer", "Fall", "Winter");
map
, filter
, count
, collect
BufferedReader
~/books/cji4/katacoda/MakeLab.java
and Json.java
cd ~/presentation/figlet rm -rf deps jpm install com.github.lalyos:jfiglet:0.0.9 ls -al deps java --enable-preview -cp deps/\* HelloWorld.java
throws Exception
to each method that throws a checked exceptionmain
paths.stream().map(Files::readString) // Error: incompatible thrown types...
p -> { try { return p->Files.readstring(p); } catch (IOException ex) { ... } }
paths.stream().map(sneaky(Files::readString))
src/main/java
project hierarchy~/data/bin
Audio.java
~/books/cji4/katacoda
MakeLab.java
javac WinMove.java native-image WinMove ./winmove
$ time ./winmove move r real 0m0.298s $ time java WinMove move l real 0m0.364s $ time java WinMove.java move r real 0m0.790s
$ ls -lh winmove -rwxrwxr-x 1 cay cay 15M Aug 29 21:12 winmove
Pattern attributePattern = Pattern.compile("^\t(?<name>[A-Z][^:]*): (?<value>.*)$"); var line = "\tActive Port: analog-input-mic"; attributePattern.matcher(line) $3.matches() $3.group("name")
jpm
for experimenting with third party librariescd ~/presentation/tablesaw rm -rf deps jpm install tech.tablesaw:tablesaw-core:0.43.1 jshell --class-path deps/\* import tech.tablesaw.api.*; Table.read().url("https://raw.githubusercontent.com/gmsharpe/edumore/master/data/elections.csv")
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS org.eclipse.angus:jakarta.mail:2.0.3
//COMPILE_OPTIONS ... //RUNTIME_OPTIONS ...
jbang export fatjar mail/MailTest.java
sdk use java 21.0.2-graalce jbang export native WinMove.java
jbang init --template=cli Demo.java
jbang --interactive mail/MailTest.java
jbang edit -b --live --verbose --open=emacs Demo.java
jbang --debug=*:9999 Demo.java
!pip install jbang # change to pip3 if pip command not found import jbang jbang.exec("trust add https://github.com/jupyter-java") print(jbang.exec("install-kernel@jupyter-java --java 21 --enable-preview").stdout)
%maven org.knowm.xchart:xchart:3.5.2 import org.knowm.xchart.*; import java.util.stream.*; double[] xData = IntStream.range(0, 100).asDoubleStream().map(i -> 2 * Math.PI * i / 100).toArray(); double[] yData = DoubleStream.of(xData).map(x -> Math.sin(x) + Math.cos(2 * x)).toArray(); XYChart chart = QuickChart.getChart("Sample Chart", "x", "y", "y(x)", xData, yData); BitmapEncoder.getBufferedImage(chart)
cd ~/jupyter bin/jupyter notebookLoad chart.ipynb
Visit https://colab.research.google.com/github/jupyter-java/anywhere/blob/main/getting-started.ipynb
Runtime → Change runtime type → Runtime type dropdown
jtaccuinoLoad
~/presentation/jtaccuino-demo.ipynb
cd ~/presentation ./jnotebook.jar server
Browse http://localhost:5002
Edit ~/presentation/notebooks/hello_world.jsh