Friday, 26 July 2013

How do I default printer service in java ?


Code :


package experiment.java.printing;

import javax.print.PrintService;
import javax.print.PrintServiceLookup;

public class getDefaultPrinter{
    public static void main(String str[]){
        try{
        //Get print server as your local setting ( Printer)
        PrintService services = PrintServiceLookup.lookupDefaultPrintService();          
        System.out.println("Default Printer Name ::"+services.getName());
       
    }catch(Exception e){
        System.out.println("Error in get Default Printer service::"+e);
       
    }
       
    }
   
}


Example of Enumeration in java

import java.util.Enumeration;
import java.util.Vector;

/*
    Example of Enumaration with Vector
    @Author Manoj
*/

class MyEnumaration{
    public static void main(String str[]){
        Vector<String> vtr=new Vector<String>();
        vtr.add("Hi");
        vtr.add("Tester");
        vtr.add("How");
        vtr.add("Are");
        vtr.add("You?");
        Enumeration enumobj=vtr.elements();
        while(enumobj.hasMoreElements()){
        System.out.println(enumobj.nextElement());
           
        }
       
    }
}

OUTPUT:-


Hi
Tester
How
Are
You?


Read more about Enumeration.