Advanced Java Bootcamp

Let’s do some activities that touch on some of the Java language beyond the basics.

About This Bootcamp

This is the second in a series of Java bootcamps that teach you the language with a set of activities designed for in-person classroom use; therefore, they are presented with very little information here on this page. The activities here are not overly technical. Technical details can be learned by asking questions during the classroom exercises.

Learning Objectives

By the end of this bootcamp, you will have a good understanding of:
  • ...
  • ...
  • ...
  • ...
  • ...
This is a programming bootcamp only

The activities here a designed to expose you to elements of the Java programming language. They do not cover “enterprise” programming techniques such as organizing apps with Maven, using frameworks such as Spring, or building networked or web applications.

There will some material on unit testing, graphics, and threads, at least, so hopefully you will find the page somewhat useful.

Prerequisites

The activities here are designed to follow those in the previous Java bootcamp.

Activities

We’ll work through these activities in order. As you type in and run each program (or perform the shell exercises), try to predict what each Java construct does, and how it is similar to and different from, those in the languages you know already.

Fun Fun Function

Lambdas Streams

TODO about

TODO CODE

TODO SAMPLE OUTPUT

A Journey in the Forest

Rolling your Own Data Structures Implementing Trees from Scratch

TODO about

TODO CODE

TODO SAMPLE OUTPUT

Pod Racing

Interfaces

crash.gif

You and your friends set out to build some racing pods. Because you haven’t had much experience in building these things, the pods aren’t all that great. They tend not to respond at all to your commands while you are in them: they have a mind of their own. Some start out able to go fast then they just stop working. Others jerkily speed up and slow down. Some go slow for a bit then unexpectedly accelerate. Rather than risking your lives actually getting in those things, you decide to simulate a race in software.

TODO CODE

TODO SAMPLE OUTPUT

JShell Interlude

JShell

TODO about

TODO SAMPLE SHELL SESSION

⛔️ DO NOT ENTER ⛔️

Graphics Swing Panel Painting invokeLater

Up to now, we’ve only worked on the command line, with text. It’s time for some graphics. We’ll begin with a rather simple app that just draws a static picture.

DoNotEnterSign.java
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import javax.swing.SwingUtilities;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

/**
 * A panel maintaining a picture of a Do Not Enter sign.
 */
public class DoNotEnterSign extends JPanel {
    private static final long serialVersionUID = 7148504528835036003L;

    /**
     * Called by the runtime system whenever the panel needs painting.
     */
    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);

        var center = new Point(getWidth() / 2, getHeight() / 2);
        var radius = Math.min(getWidth() / 2, getHeight() / 2) - 5;
        var diameter = radius * 2;
        var innerRadius = (int) (radius * 0.9);
        var innerDiameter = innerRadius * 2;
        var barWidth = (int) (innerRadius * 1.4);
        var barHeight = (int) (innerRadius * 0.35);

        g.setColor(Color.WHITE);
        g.fillOval(center.x - radius, center.y - radius, diameter, diameter);
        g.setColor(Color.RED);
        g.fillOval(center.x - innerRadius, center.y - innerRadius, innerDiameter,
                innerDiameter);
        g.setColor(Color.WHITE);
        g.fillRect(center.x - barWidth / 2, center.y - barHeight / 2, barWidth,
                barHeight);
    }

    /**
     * A little driver in case you want a stand-alone application.
     */
    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            var panel = new DoNotEnterSign();
            panel.setBackground(Color.GREEN.darker());
            var frame = new JFrame("A simple graphics program");
            frame.setSize(400, 300);
            frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            frame.getContentPane().add(panel, BorderLayout.CENTER);
            frame.setVisible(true);
        });
    }
}

When run, a new window should appear, looking something like this:

donotenterapp.png

Exercise: Add to the drawing the words “DO NOT” above the bar, and “ENTER” below.

Java Petting Zoo

User Interaction Buttons Event Handling

Users interact with graphics applications with clicks, motion, and even entering text into fields. As a short introduction, let’s introduce buttons, which when clicked, allow you to virtually pet a virtual animal.

TODO CODE

TODO SAMPLE OUTPUT

Robot Soccer

Animation

robotsoccer.png

You've been hired to build a robot soccer team, but you’ve been having trouble raising funds, because you forgot to take Dr. Choi’s entrepreneurship classes. With no money for robot players, you decide to make the soccer balls themselves robotic! Your main ball relentlessly powers toward the goal. The enemies are themselves robotic soccer balls which relentlessly charge toward the player. Money is so tight you can’t even afford proper power engines; each ball just starts at an initial velocity and, subject to friction, slows down until it stops. Before building your robots, you wish to build a simulation so you can better program actual robot balls.

TODO CODE

TODO SAMPLE OUTPUT

Trivia Game

Invoking Web APIs

TODO about

TODO CODE

TODO SAMPLE OUTPUT

Dining Philosophers

Threads

TODO about

TODO CODE

TODO SAMPLE OUTPUT

Sharing is Caring

Networking Primitives

TODO about

TODO CODE

TODO SAMPLE OUTPUT

Summary

We’ve covered:

  • Java Programming