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.
This is a programming bootcamp onlyThe 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.
The activities here are designed to follow those in the previous Java bootcamp.
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.
Lambdas Streams
TODO about
TODO CODE
TODO SAMPLE OUTPUT
Rolling your Own Data Structures Implementing Trees from Scratch
TODO about
TODO CODE
TODO SAMPLE OUTPUT
Interfaces
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
TODO about
TODO SAMPLE SHELL SESSION
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.
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:
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
Animation
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
Invoking Web APIs
TODO about
TODO CODE
TODO SAMPLE OUTPUT
Threads
TODO about
TODO CODE
TODO SAMPLE OUTPUT
Networking Primitives
TODO about
TODO CODE
TODO SAMPLE OUTPUT
We’ve covered: