JDBC / CATATAN</>↗JDBC15 Apr 2006
This post is about an example for obtaining a connection to MySQL database. For connecting to other database all you have to do is change the url to match to url format for a particular database and of course you have to register a correct JDBC driver of the database you are using. Here are […]
AWT / CATATAN</>↗AWT11 Apr 2006
package org.kodejava.awt; import java.awt.*; public class BeepExample { public static void main(String[] args) { // This is the way we can send a beep audio out. Toolkit.getDefaultToolkit().beep(); } } Using Runtime.exec() method we can do something like the code snippet below to produce beep sound using powershell command. try { Process process = Runtime.getRuntime().exec( new […]
CORE API / CATATAN</>↗Core API07 Apr 2006
In this example we are going to learn how to sort an array of objects. We start by using an array of String objects as can be seen in the code snippet below. We sort the contents of the array using Arrays.sort() method and print the sorted result. It was really simple. String names[] = […]
CORE API / CATATAN</>↗Core API04 Apr 2006
package org.kodejava.util; import java.util.Arrays; public class ArraySearchExample { public static void main(String[] args) { // We create an array of ints where the search will be done. int[] items = {9, 5, 14, 6, 11, 28, 9, 16, 37, 3, 2}; // The Arrays.binarySearch() require us to sort the array // items before we call […]
CORE API / CATATAN</>↗Core API02 Apr 2006
package org.kodejava.util; import java.util.Arrays; public class ArraySortExample { public static void main(String[] args) { // An array of random numbers int[] numbers = {3, 1, 8, 34, 1, 2, 13, 89, 5, 21, 55}; System.out.println("Before: " + Arrays.toString(numbers)); // We need to sort these array elements into a correct order // from the smallest to […]
APACHE COMMONS / CATATAN</>↗Apache Commons01 Apr 2006
To convert from primitive arrays into object type arrays, we can use the Apache Commons Lang library. The Commons Lang provides an ArrayUtils class that does this conversion. To convert the other way just use the toPrimitive() method. package org.kodejava.commons.lang; import org.apache.commons.lang3.ArrayUtils; public class ArrayPrimitiveObjectConversionDemo { public static void main(String[] args) { int[] numbers = […]