Message in a Bottle #SongsInCode

Software

Sting

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!

Sting.java

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

Bottle.java

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;
    else
      throw new NotOpenException();
  }
}

NotOpenException.java

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

Author bio and support

Me!

Ruben Schade is a technical writer and IaaS engineer in Sydney, Australia who refers to himself in the third person in bios. Wait, not BIOS… my brain should be EFI by now.

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

If you found this post helpful or entertaining, you can shout me a coffee or buy some silly merch. Thanks!