CORE API / CATATAN</>↗Core API23 Nov 2007
Here you will find an example on how to sort the values of an array in ascending or descending order. package org.kodejava.util; import java.util.Arrays; import java.util.Collections; public class SortArrayWithOrder { public static void main(String[] args) { Integer[] points = new Integer[5]; points[0] = 94; points[1] = 53; points[2] = 70; points[3] = 44; points[4] = […]
HIBERNATE / CATATAN</>↗Hibernate23 Nov 2007
In the example below you’ll see how to limit the number of records returned by hibernate queries. Limiting the query result is usually use for creating pagination, where we can navigate from page to page of data in our application but only a few of them are read from the database. In hibernate Query object […]
CORE API / CATATAN</>↗Core API18 Nov 2007
In the previous example, How do I load properties from XML file? we read properties from XML file. Now it’s the turn on how to store the properties as XML file. package org.kodejava.io; import java.io.FileOutputStream; import java.nio.charset.StandardCharsets; import java.util.Properties; public class PropertiesToXml { public static void main(String[] args) throws Exception { Properties properties = new […]
CORE API / CATATAN</>↗Core API16 Nov 2007
Reading XML properties can be easily done using the java.util.Properties.loadFromXML() method. Just like reading the properties from a file that contains a key=value pairs, the XML file will also contain a key and value wrapped in the following XML format. <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> <comment>Application Configuration</comment> <entry key="data.folder">D:\AppData</entry> <entry key="...
CORE API / CATATAN</>↗Core API13 Nov 2007
This example will show you how to convert an InputStream into String. In the code snippet below we read a data.txt file, could be from common directory or from inside a jar file. package org.kodejava.io; import java.io.*; import java.nio.charset.StandardCharsets; public class StreamToString { public static void main(String[] args) throws Exception { StreamToString demo = new […]
CORE API / CATATAN</>↗Core API11 Nov 2007
Here you will find how to convert string into java.io.InputStream object using java.io.ByteArrayInputStream class. package org.kodejava.io; import java.io.*; import java.nio.charset.StandardCharsets; public class StringToStream { public static void main(String[] args) { String text = "Converting String to InputStream Example"; // Convert String to InputStream using ByteArrayInputStream // class. This class constructor takes the string byte array […]