AWT / NOTES</>↗AWT25 Dec 2009
This example show you how to detect if the Num Lock key is in active mode. If you run the program you will get an output telling you that the Num Lock button is active or not active. package org.kodejava.awt; import java.awt.Toolkit; import java.awt.event.KeyEvent; public class NumLockState { public static void main(String[] args) { Toolkit […]
AWT / NOTES</>↗AWT23 Dec 2009
This example show you how to detect if the Caps Lock key is in active mode. package org.kodejava.awt; import java.awt.Toolkit; import java.awt.event.KeyEvent; public class CapsLockState { public static void main(String[] args) { // Get the locking state of the Caps Lock button. This method // return boolean true value if it is "on". boolean isOn […]
CORE API / NOTES</>↗Core API22 Dec 2009
package org.kodejava.io; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; public class ReadFileIntoByteArray { public static void main(String[] args) throws IOException { File file = new File("README.md"); try (InputStream is = new FileInputStream(file)) { if (file.length() > Integer.MAX_VALUE) { throw new IOException("File is too large."); } int offset = 0; int bytesRead; byte[] bytes = […]
APACHE COMMONS / NOTES</>↗Apache Commons22 Dec 2009
The code below show you how to use the Apache Commons-Lang RandomStringUtils class to generate some random string data. package org.kodejava.commons.lang; import org.apache.commons.lang3.RandomStringUtils; public class RandomStringUtilsDemo { public static void main(String[] args) { // Creates a 64-chars length random string of number. String result = RandomStringUtils.random(64, false, true); System.out.println("random = " + result); // Creates […]
CORE API / NOTES</>↗Core API17 Dec 2009
In this code snippet you will see how to sort the content of an Enumeration object. We start by creating a random numbers and stored it in a Vector. We use these numbers and create a Enumeration object by calling Vector‘s elements() method. We convert it to java.util.List and then sort the content of the […]
SPRING JDBC / NOTES</>↗Spring JDBC15 Dec 2009
The following example show you how to use the Spring’s JdbcTemplate class to insert a record into database. package org.kodejava.spring.jdbc; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.DriverManagerDataSource; import javax.sql.DataSource; import java.sql.Types; import java.util.Date; public class InsertDemo { private static final String INSERT_QUERY = """ INSERT INTO record (title, release_date, artist_id, label_id, created)...