Getting access to all printers configured in machine

This post explains how to programmatically get access to all printers configured in a machine. Java provides lookup facitlity through PrintServiceLookup class. This class has static methods through which we can get a reference to all the printers. We use the lookupPrintServices method in the PrintServiceLookup class. The api definition is as shown below public…… Continue reading Getting access to all printers configured in machine

Executing scripts written in a file using java

This post explain how to execute javascript code stored in a file. We create an instance of FileReader representing the physical file and pass it to eval method of an instance of ScriptEngine. Please refer to previous posts to know more about ScriptEngine and ScriptEngineManager The javascript code in the file that has to be…… Continue reading Executing scripts written in a file using java

Executing scripts using java

This post explain how to execute code written in scripting language like php or javascript etc in java. The scripts are executed by calling eval on an instance of ScriptEngine interface. An instance of ScriptEngine is used to represent scripting language specific engines. For example in case of JavaScript, Mozilla Rhino provided out of the…… Continue reading Executing scripts using java

Getting access to default printer

This post explains how to programmatically get access to a printer configured as default printer in a machine. Java provides PrintServiceLookup class, which provides static methods through which we can get a reference to the printer. Each printer installed in a machine is represented by an instance of PrintService interface. The PrintService interface provides methods…… Continue reading Getting access to default printer

Writing json data using Jackson JsonGenerator

The below post explains how to write json data to file using JsonGenerator. JsonGenerator writes the data to a file in streaming way, helping the developer using the api to avoid creating an object representation of the data. We can get an instance of JsonGenerator with the help of an instance of JsonFactory as shown…… Continue reading Writing json data using Jackson JsonGenerator

PushBackReader Demo

This post explains PushBackReader class in java. This reader allows us to put the data read from the input stream back into the stream and reread it again. The below explains how to use it Main Class package IO; import java.io.PushbackReader; import java.io.StringReader; public class PushBackReaderDemo { public static void main(String[] args) throws Exception {…… Continue reading PushBackReader Demo

Intercepting hibernate CRUD operations

This post explains how to intercept hibernate create, read, update and delete operations, so that we can add our own logic that has to be performaned before CRUD operations. The different use case where we need to intercept these hibernate operations are as follows 1) Every entity in the applications has common fields for example…… Continue reading Intercepting hibernate CRUD operations

Retrieving JsonParser Settings

This post explains how to get json parser default settings. import java.io.File; import java.io.IOException; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonParser.Feature; public class ProcessingDemo2 { public static void main(String[] args) throws JsonParseException, IOException { File file = new File(“jsondata.json”); JsonFactory jsonFactory = new JsonFactory(); JsonParser jsonParser = jsonFactory.createParser(file); for(Feature feature : Feature.values()) { System.out.println(feature.name()…… Continue reading Retrieving JsonParser Settings