GOOGLE GSON / NOTES</>↗Google Gson01 Feb 2010
On the previous example, How do I convert object into JSON? we convert object into JSON string. In this example you will see how to do the opposite, converting JSON string back into object. To convert JSON string to object use Gson.fromJson() method. This method takes the JSON string and the object type of the […]
GOOGLE GSON / NOTES</>↗Google Gson30 Jan 2010
In this example we are using Google Gson to convert an object (Student object) into JSON notation. Practically we can use this library to convert any object in Java, and it is quite simple. You just need to create an instance of Gson class and then call the toJson() method and pass the object to […]
CORE API / NOTES</>↗Core API27 Jan 2010
The code below demonstrates how to create a progress bar in a console program. The trick is to print the progress status using a System.out.print() and add a carriage return character ("\r") at the end of the string to return the cursor position to the beginning of the line and print the next progress status. […]
CORE API / NOTES</>↗Core API23 Jan 2010
This example demonstrates how to use the System.nanoTime() method to calculate processing execution time in higher resolution. The processing time calculated in nanoseconds resolution. package org.kodejava.lang; public class NanoSecondsTimerResolution { public static void main(String[] args) { // Get process execution start time in nanoseconds. long start = System.nanoTime(); System.out.println("Process start… " + start); try { […]
JDOM / NOTES</>↗JDOM21 Jan 2010
This example demonstrate how to convert JDOM Document object to a String using the XMLOutputter.outputString(Document doc) method. package org.kodejava.jdom; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.output.Format; import org.jdom2.output.XMLOutputter; public class JDOMDocumentToString { public static void main(String[] args) { Document document = new Document(); Element root = new Element("rows"); // Creating a child for the root element. […]
CORE API / NOTES</>↗Core API17 Jan 2010
To look up the default print service we can use the javax.print.PrintServiceLookup class lookupDefaultPrintService() method. package org.kodejava.print; import javax.print.PrintService; import javax.print.PrintServiceLookup; public class GetPrinter { public static void main(String[] args) { // Gets the default print service for this environment. Null is returned when // no default print service found. PrintService service = PrintServiceLookup.lookupDefaultPrintService(); if [...