This course is an introduction to the concepts and practices of information representation, computer algorithms, hardware fundamentals, and computer program design and implementation. This course allows students to write, compile, debug, run, analyze and evaluate computer programs written in a current object-oriented language. Edward Hogan
As of 2022, there are three LTS versions of Java: Java8, Java11, and Java17. The assignments and projects that I've written for the class use features that were introduced later than Java11 .
Java8
March 2014 released
Premier Support Until March 2022
Java8 supports generics, annotations, lambda functions, and limited type inference.
Java11
Sept. 2018 released
Premier Support Until September 2023
Java11 supports enhanced Local-Variable type inference, and enhanced Lambda Parameters .
type inference:
public Set<Move> getMoves(PlyrSym sym) { var ret = new HashSet<Move>(); for (var x=0;x <3; x++) { for (var y=0;y <3; y++) { if (board.boxes[x][y].isEmpty() ) { ret.add(new Move(sym,x,y)); } } } return ret; }
Java17
Sept. 2021 released
Premier Support Until September 2026
Java17 supports Switch Expressions, enhanced instanceof, records, and Sealed Classes .
switch expression:
instanceof:
private void paintO(Graphics g) {
var grph = g.create();
if (grph instanceof Graphics2D grph2d) {
double x = getWidth();
double y = getHeight();
var strk = new BasicStroke((float)(x/50 + y/50 +2));
var circ = new Ellipse2D.Double(0.1*x, 0.1*y,0.8*x, 0.8*y);
grph2d.setStroke(strk);
grph2d.draw(circ);
}
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() instanceof JComponent compo) {
var constra = layOut.getConstraints(compo);
int x = (constra.gridx -1)/2;
int y = (constra.gridy -1)/2;
compBoxes[x][y].sym = PlyrSym.X;
this.revalidate();
this.repaint();
}
}
record:
static public record SqrLoc(int x, int y) {
public SqrLoc {
if (x<0 || x>2 || y<0 || y>2 )
throw new java.lang.IllegalArgumentException(); }
public boolean isCenter() {
return (1 == this.x && 1 == this.y);
}
public boolean isCorner() {
return ((0 == this.x || 2 == this.x) &&
(0 == this.y || 2 == this.y));
}
public boolean isSide() {
return ((1 == this.x && ( 0 == this.y || 2 == this.y )) ||
(1 == this.y && ( 0 == this.x || 2 == this.x )) );
}
}
sealed: