The AWT gives you access to screen information, although "external" is subjective as you might have 2 built-in monitors or 2 external ones.
At a basic level, you can count the monitors at any moment:
int numberOfMonitors = 0;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();
for (int j = 0; j < gs.length; j++) {
GraphicsDevice gd = gs[j];
GraphicsConfiguration[] gc = gd.getConfigurations();
if (gc.getType() == TYPE_RASTER_SCREEN) numberOfMonitors++;
}
System.out.println("Number of monitors: " + numberOfMonitors);
To detect the attachment of a new monitor, you will need to poll for the result.
This is a pure Java solution; to my knowledge if you want anything more accurate than this then you'll probably need to call some native tools on the platform(s) you are targeting. For example, probing sysfs in Linux.