Here you can find the source of getDefaultPrinterName()
public static String getDefaultPrinterName()
//package com.java2s; /*/* ww w .ja v a2 s .co m*/ * Copyright (C) 2015 University of Oregon * * You may distribute under the terms of either the GNU General Public * License or the Apache License, as specified in the LICENSE file. * * For more information, see the LICENSE file. */ import javax.print.*; public class Main { private static String defaultPrinterName = null; private static boolean bWaitForPrinterServer = false; private static long lastQueryTime = 0; public static String getDefaultPrinterName() { if (bWaitForPrinterServer) return defaultPrinterName; bWaitForPrinterServer = true; if (defaultPrinterName == null) { long t = System.currentTimeMillis() / 1000; if ((t - lastQueryTime) < 120) { bWaitForPrinterServer = false; return defaultPrinterName; } PrintService ps = PrintServiceLookup .lookupDefaultPrintService(); lastQueryTime = System.currentTimeMillis() / 1000; String name = null; if (ps != null) { name = ps.getName(); if (name != null && name.length() > 0) defaultPrinterName = name; } } bWaitForPrinterServer = false; return defaultPrinterName; } }