CORE API / CATATAN</>↗Core API12 Sep 2009
This example show you how to count the number of a character occurrences in a string. We show two ways to do it, using the String.replaceAll(String regex, String replace) method and creating a loop that check every char in the String and count the matched char. package org.kodejava.lang; public class CharCounter { public static void […]
APACHE COMMONS / CATATAN</>↗Apache Commons07 Sep 2009
We can use the code below to convert the content of an InputStream into a String. At first, we use FileInputStream create to a stream to a file that going to be read. IOUtils.toString(InputStream input, String encoding) method gets the content of the InputStream and returns a string representation of it. package org.kodejava.commons.io; import org.apache.commons.io.IOUtils; […]
APACHE COMMONS / CATATAN</>↗Apache Commons03 Sep 2009
This example using the Apache Commons FileUpload library to create a simple application for uploading files. The program is divided into two parts, a form using JSP and a servlet for handling the upload process. To run the sample you need to download the Commons FileUpload and Commons IO get the latest stable version. The […]
CORE API / CATATAN</>↗Core API30 Agt 2009
The code below helps you find the number of a specified weekday (Monday, Tuesday, Wednesday, etc.) between two dates. The solution we used below is to loop between the two dates and check if the weekday of those dates are equals to the day we want to count. package org.kodejava.util; import java.util.Calendar; public class DaysBetweenDate […]
SWING / CATATAN</>↗Swing27 Agt 2009
The Swing javax.swing.Timer object fires the action event after the delay time specified in the constructor passed. For some reasons you might want the Timer class fires immediately after it was started. To achieve this you can set the timer initial delay by calling the setInitialDelay(int initialDelay) method. The example below give you an example […]
SWING / CATATAN</>↗Swing25 Agt 2009
In this example you’ll see how to use java.swing.Timer class to create a text clock program. package org.kodejava.swing; import javax.swing.*; import java.awt.*; import java.util.Calendar; import java.text.DateFormat; import java.text.SimpleDateFormat; public class TimerDemo extends JFrame { public static final DateFormat df = new SimpleDateFormat("hh:mm:ss"); public TimerDemo() throws HeadlessException { initUI(); } public static void main(String[] args) { […]