import java.util.List;
public class Prog {
public static void main(String[] args) {
System.out.println(List.of("Hello", "World!"));
}
}
Who learned Java in
school, university, etc.?
🖐🏾
Java became a cornerstone in CS education because:
the runtime simplified coding (e.g. GC)
explicit types and concepts
well-suited for OOP
widely used
Kids/students/grown-ups learn Java for their hobbies:
home automation
static website generation
game modding
Developers move from other languages to Java:
frontend developers
ML/AI developers
developers from other ecosystems
All these learners benefit from:
a simple, straightforward language
a smooth standard library
a powerful runtime
a well-trodden path
Java is successful in business, science, etc. because:
multi-paradigm language
refined programming model
comprehensive standard library
powerful runtime
backwards-compatible evolution
detailed, varied tools
strong, diverse ecosystem
There’s a tension here:
education benefits from a simple, straightforward Java
professional use benefits from a detailed, diverse Java
To stay relevant in education, Java must have an on-ramp.
An on-ramp to Java:
small starting set of language constructs,
APIs, and tools
features that allow quick achievements
gradual expansion to the full set
teaching the language
teaching the tools
teaching the concepts
teaching Java
I’m no teacher/professor
this is inspiration, not instruction
slides at slides.nipafx.dev/teaching-java
(hit "?" to get navigation help)
ask questions at any time
Teaching the Language |
Teaching the Tools |
Teaching the Concepts |
Teaching Java |
Minimal Java code:
import java.util.List;
public class Prog {
public static void main(String[] args) {
System.out.println(List.of("Hello", "World!"));
}
}
imports & visibility
classes & methods
static vs instance
returns & parameters
statements & arguments
Beginners should be able to:
start with a minimal set of language constructs
achieve first results quickly
learn as they go without "delearning"
Remove requirement of:
String[] args
parameter
main
being static
main
being public
the class itself
System.out
(use IO
instead)
imports for java.base
Previews in Java 23 (JEP 477):
// all the code in Prog.java
void main() {
println(List.of("Hello", "World!"));
}
imports & visibility
classes & methods
static vs instance
returns & parameters
statements & arguments
Natural progression:
start with main()
add String[] args
for arguments
add methods to organize code
add fields to share state
explore JDK APIs for more functionality
Ramp up to full language.
Teaching the Language |
Teaching the Tools |
Teaching the Concepts |
Teaching Java |
To write and run a simple Java program, you need:
a JDK
an editor (IDE?)
javac
(build tool? IDE?)
java
(IDE?)
Beginners should be able to run
simple Java programs with
no/fewer/simpler tools!
Oracle’s Java Platform Group developed the Java Playground:
all you need:
tools: browser
concepts: statements & arguments
but:
limited capabilities
(e.g. no file I/O or network)
no persistence
Java 9 added jshell
:
all you need:
tools: JDK, jshell
concepts: statements & arguments
but:
no syntax highlighting
no (smooth) persistence
no progression
An IDE:
makes a few things easier
is itself a complex tool
is almost certainly unknown to beginners
Maybe not the best tool to introduce early.
VS Code:
is better known
has decent Java capabilities
Java 11 added single-file execution (JEP 330):
java Prog.java
tools: JDK, java
but: no progression
Much better for beginners, but just a section of an on-ramp.
If you have a folder:
MyFirstJava
├─ Prog.java
├─ Helper.java
└─ Lib
└─ library.jar
Run with:
java -cp 'Lib/*' Prog.java
Added in Java 22 (JEP 458).
But where do you get dependencies from?
This is an open problem.
Natural progression:
start experiments in playground
to persist work:
download JDK
move to text editor
start with single source file
split into multiple files when code becomes larger
use visibility & packages to add structure
Ramp up until delivery of artifacts is needed.
Teaching the Language |
Teaching the Tools |
Teaching the Concepts |
Teaching Java |
Java is a great OOP language.
OOP is a great paradigm for large systems.
But is OOP the best paradigm to learn first?
OOP hinges on:
abstraction of the domain through classes
combination of state and behavior
encapsulation and visibility
inheritance (at least of types)
Neither easy nor necessary for simple programs.
Programming can be immediately useful:
automation
data analysis
visualization
interactive media
Let learners write simple, useful programs!
⇝ Such programs rarely need OOP.
Simple programs usually interact via terminal.
Use IO
instead of System.{in|out}
:
void print(Object)
& void println(Object)
to write
String readln(String)
to read input
(Auto-imported in a simple source file.)
Simple programs often focus on data:
reading data from disk or remote
parsing various data formats
representation of data as types
mass-processing data
visualizing data
writing data to disk or a remote
NIO.2 makes reading text files straightforward:
var transactions = Path.of("transactions.csv");
for (var line : Files.readAllLines(transactions)) {
// ...
}
HTTP/2 client makes reading remote data
(relatively) straightforward:
var client = HttpClient.newHttpClient();
var request = HttpRequest
.newBuilder(URI.create("http://example.org/"))
.build();
var body = client
.send(request, BodyHandlers.ofString())
.body();
Java has out-of-the-box support for:
XML
😬
Clearly room for improvement!
Records make simple types simple:
record Transaction(
LocalDate date, long cents,
TransactionType type) { }
enum TransactionType { PRIVATE, BUSINESS }
for
-loops, if
statements, etc. are simplest.
But once functions are introduced, streams become available.
JavaFX is powerful but not simple to get started with.
Java lacks beginner-level visualization tools.
NIO.2 makes writing data very simple:
var analysis = "...";
var file = Path.of("analysis.txt");
Files.writeString(file, analysis);
Natural progression:
start with simple terminal interaction
use NIO.2 to read and write local data
use HTTP/2 client to access remote data
use records to model data
use common statements to analyze data
potentially upgrade to streams
Go into more OOP as problems get more complex.
Teaching the Language |
Teaching the Tools |
Teaching the Concepts |
Teaching Java |
Take first steps in the playground.
To get started "for real":
tools: JDK, text editor
code: simple main
and IO
execution with java Prog.java
need arguments? ⇝ add String[] args
need to organize code? ⇝ add methods
need more functionality? ⇝ explore JDK APIs:
e.g. NIO.2 or HTTP/2 client
need to capture data? ⇝ define records
need shared state? ⇝ add fields
need even more functionality? ⇝ explore simple libraries:
e.g. JavaFX for visualization
need more structure? ⇝ split into multiple files
even more ⇝ use visibility & packages
Java can do better is some areas:
managing dependencies without build tool
steering away from outdated APIs
support more data formats out of the box
simplify (data) visualization
At some point:
a more powerful editor would be helpful ⇝ IDE
testing or delivering becomes necessary ⇝ build tool
Welcome to full Java!