Message in a Bottle #SongsInCode



This afternoon I did something extraordinarily productive and created an extended #SongsInCode rendition of Message in a Bottle that compiles. Now all somebody in this distant future needs to do is create a new class to fetch Sting's bottle and read his message!

public class Sting {
  public static void main(String[] args) {
    Bottle oceanBottle = new Bottle("SOS!");

public class Bottle {
  String message = "";
  boolean opened = false;
  public Bottle(String message) {
    this.message = message;
  public void pullCork() {
    opened = true;
  public String getMessage() throws NotOpenException {
    if (opened)
      return message;
      throw new NotOpenException();

public class NotOpenException extends Throwable {
  public NotOpenException() {
    super("You haven't opened the bottle yet!");

Author bio and support


Ruben Schade is a technical writer and infrastructure architect in Sydney, Australia who refers to himself in the third person. Hi!

The site is powered by Hugo, FreeBSD, and OpenZFS on OrionVM, everyone’s favourite bespoke cloud infrastructure provider.

If you found this post helpful or entertaining, you can shout me a coffee or send a comment. Thanks ☺️.