package info.istlab.dp.dp1; import java.awt.Desktop; import java.awt.DisplayMode; import java.awt.GraphicsEnvironment; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.util.Calendar; import java.util.Date; class Singleton { private static Singleton onlyone; public static Singleton getOnlyOne() { if (onlyone == null) onlyone = new Singleton(); return onlyone; } Date created; private Singleton() { created = Calendar.getInstance().getTime(); } public String toString() { return hashCode()+" "+created.toString(); } } public class SingletonTest { public static void main(String[] args) { // Singleton single = new Singleton(); Singleton single1 = Singleton.getOnlyOne(); System.out.println(single1.toString()); SingletonTest.wait(5); Singleton single2 = Singleton.getOnlyOne(); System.out.println(single2.toString()); // Other examples // Desktop.getDesktop() Desktop dp = Desktop.getDesktop(); try { dp.browse(new URI("https://istlab.info/")); } catch (IOException | URISyntaxException e) { e.printStackTrace(); } // GraphicsEnvironment GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment(); DisplayMode dm = genv.getDefaultScreenDevice().getDisplayMode(); System.out.println("Main Display width:"+dm.getWidth()+" height:"+dm.getHeight()); // Runtime rt = Runtime.getRuntime(); } public static void wait(int sec) { try { Thread.sleep(sec * 1000); } catch (InterruptedException e) { e.printStackTrace(); } } }