JDBC / CATATAN</>↗JDBC25 Okt 2006
Here is another example on how to read data from a ResultSet returned by executing an SQL query in a database. We start by creating a connection to the database. Creates a PreparedStatement to execute a query to get some data from the books table. After executing the PreparedStatement we will have a ResultSet object. […]
CORE API / CATATAN</>↗Core API21 Okt 2006
package org.kodejava.util; import java.util.Arrays; import java.util.Collections; public class ArrayMinMax { public static void main(String[] args) { // Creates an array of integer numbers in it. Integer[] numbers = {8, 2, 6, 7, 0, 1, 4, 9, 5, 3}; // To get the minimum or maximum value from the array we can // use the Collections.min() […]
CORE API / CATATAN</>↗Core API20 Okt 2006
Prior to Java 1.6 the java.io.File class doesn’t include a method to change a read only file attribute and make it writable. To do this on the old days we have to utilize or called operating system specific command. In Java 1.6 a new method named setWritable() was introduced to do exactly what the method […]
CORE API / CATATAN</>↗Core API19 Okt 2006
This code demonstrate how we can modify file attribute to be read only. File class has a setReadOnly() method to make file read only and a canWrite() method to know whether it is writable or not. package org.kodejava.io; import java.io.File; public class FileReadOnlyExample { public static void main(String[] args) throws Exception { File file = […]
CORE API / CATATAN</>↗Core API14 Okt 2006
If you want to know the free memory, and the total memory available in the Java runtime environment then you can use the following code snippet to check. package org.kodejava.lang; public class MemoryExample { public static void main(String[] args) { long freeMemory = Runtime.getRuntime().freeMemory(); long totalMemory = Runtime.getRuntime().totalMemory(); System.out.println("Free Memory = " + freeMemory); System.out.println("Total […]
CORE API / CATATAN</>↗Core API14 Okt 2006
Since Java 1.5 (Tiger) the java.net.InetAddress class introduces isReachable() method that can be used to ping or check if the address specified by the InetAddress is reachable. package org.kodejava.net; import java.net.InetAddress; public class PingExample { public static void main(String[] args) { try { InetAddress address = InetAddress.getByName("172.16.2.0"); // Try to reach the specified address within […]