CORE API / CATATAN</>↗Core API11 Apr 2007
For instance, you have a collection of objects in an List object, and you want to do some logic based on the object’s class. This can easily be done using the instanceof operator. The operator returns true if an object is an instance of a specified class, if not it will return false. The instanceof […]
APPLET / CATATAN</>↗Applet07 Apr 2007
By default, the applet will usually have a grey background when displayed in a web browser. If you want to change it then you can call the setBackground(java.awt.Color) method and choose the color you want. Defining the background color in the init() method will change the color as soon as the applet initialized. package org.kodejava.applet; […]
CORE API / CATATAN</>↗Core API05 Apr 2007
package org.kodejava.lang; public class StringReplace { public static void main(String[] args) { String text = "The quick brown fox jumps over the lazy dog"; System.out.println("Before: " + text); // The replace method replace all occurrences of character // 'o' with 'u' and returns a new string object. text = text.replace('o', 'u'); System.out.println("After : " + […]
CORE API / CATATAN</>↗Core API03 Apr 2007
package org.kodejava.lang; public class CharArrayCopyExample { public static void main(String[] args) { char[] data = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'}; // Copy all value in the char array and create a new string out of it. String text = String.valueOf(data); System.out.println(text); // Copy a sub array from the char array […]
CORE API / CATATAN</>↗Core API02 Apr 2007
package org.kodejava.lang; public class TrimStringExample { public static void main(String[] args) { String text = " tattarrattat "; System.out.println("Original = " + text); System.out.println("text.length() = " + text.length()); // The trim() method will result a new string object with a leading and // trailing while space removed. text = text.trim(); System.out.println("Result = " + text); […]
CORE API / CATATAN</>↗Core API29 Mar 2007
This example give you an example using java.text.DecimalFormat class to add leading zeros to a number. For another method you can read the see the earlier example on How do I add leading zeros to a number?. package org.kodejava.text; import java.text.DecimalFormat; import java.text.NumberFormat; public class NumberFormatLeadingZerosExample { public static void main(String[] args) { NumberFormat formatter […]