CORE API / CATATAN</>↗Core API18 Sep 2008
This code example use the Collections.binarySearch() to search an specified object inside a specified collections. Prior to calling the binarySearch() method we need to sort the elements of the collection. If the object is not sorted according to their natural order the search result will be undefined. package org.kodejava.util; import java.util.Arrays; import java.util.LinkedList; import java.util.Collections; […]
CORE API / CATATAN</>↗Core API15 Sep 2008
This example demonstrate how to rotate the elements of a collection object. We can use the java.util.Collections class and call the rotate() method with the collection to rotate and the distance as the parameters. package org.kodejava.util; import java.util.List; import java.util.ArrayList; import java.util.Collections; import java.util.Arrays; public class CollectionRotate { public static void main(String[] args) { List<Integer> […]
CORE API / CATATAN</>↗Core API13 Sep 2008
In this program we read the file contents byte by byte and then print the value in hexadecimal format. As an alternative to read a single byte we can read the file contents into array of bytes at once to process the file faster. package org.kodejava.io; import java.io.FileInputStream; public class HexDumpDemo { public static void […]
SWING / CATATAN</>↗Swing11 Sep 2008
This demo gives examples of using the SwingWorker class. The purpose of SwingWorker is to implement a background thread that you can use to perform time-consuming operations without affecting the performance of your program’s GUI. package org.kodejava.swing; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; import javax.swing.SwingWorker; import javax.swing.WindowConstants; import java.awt.Dimension; impo...
CORE API / CATATAN</>↗Core API11 Sep 2008
This example demonstrate Date‘s class after() method to check if a date is later than another date. package org.kodejava.util; import java.util.Date; import java.util.Calendar; public class DateCompareAfter { public static void main(String[] args) { // Get current date Date today = new Date(); // Add 1 day from the current date. Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, […]
CORE API / CATATAN</>↗Core API10 Sep 2008
This example demonstrate Date‘s class before() method to check if a date is earlier than another date. package org.kodejava.util; import java.util.Date; import java.util.Calendar; public class DateCompareBefore { public static void main(String[] args) { // Get current date Date today = new Date(); // Subtract 1 day from the current date. Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, […]