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/2024/smalljava
java path/to/MyProg.java.java#!/usr/bin/env java --source 21
.java///usr/bin/env java --source 21 "$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() { ... }
println, print, readln (since Java 23)~/bin/Audio.java and its shell predecessor ~/bin/audio
record Brick(Point p, Point q)
toString, equals, hashCodestatic Brick parse(String s) { ... }
boolean overlaps(Brick other) { ... }
import static java.lang.System.*; import static java.lang.Math.*; out.println(sqrt(PI));
enumvar, diamond
BufferedReader~/books/cji4/katacoda/MakeLab.java and Json.java
throws Exception to each method that throws a checked exceptionmainpaths.stream().map(Files::readString) // Error: incompatible thrown types...
p -> { try { return p->Files.readstring(p); } catch (IOException ex) { ... } }paths.stream().map(sneaky(Files::readString))
~/binAudio.javasrc/main/java project hierarchy~/books/cji4/katacodaMakeToc.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")
jshell-resolve tech.tablesaw:tablesaw-core:0.43.1
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 MakePassword.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.*;
double[] xData = new double[] { 0.0, 1.0, 2.0 };
double[] yData = new double[] { 2.0, 1.0, 0.0 };
XYChart chart = QuickChart.getChart("Sample Chart", "X", "Y", "y(x)", xData, yData);
BitmapEncoder.getBufferedImage(chart)
cd ~/presentation 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
./jnotebook.jar serverBrowse http://localhost:5002 Edit
~/presentation/notebooks/hello_world.jsh
cd ~/temp/jtaccuino ./gradlew runLoad
~/presentation/jtaccuino-demo.ipynb
