CORE API / CATATAN</>↗Core API01 Mei 2006
Prior to Java 1.4 we use java.util.StringTokenizer class to split a tokenized string, for example a comma separated string. Starting from Java 1.4 and later the java.lang.String class introduce a String.split(String regex) method that simplify this process. Below is a code snippet how to do it. package org.kodejava.lang; import java.util.Arrays; public class StringSplit { public […]
CORE API / CATATAN</>↗Core API30 Apr 2006
The following program allows you to run / execute other application from Java using the Runtime.exec() method. package org.kodejava.lang; import java.io.IOException; public class RuntimeExec { public static void main(String[] args) { //String command = "/Applications/Safari.app/Contents/MacOS/Safari"; String command = "explorer.exe"; try { Process process = Runtime.getRuntime().exec(new String[]{command}); } catch (IOException e) { e.printStackTrace(); } } }
CORE API / CATATAN</>↗Core API29 Apr 2006
OS platform has a different symbol used for path separator. Path separator is a symbol that separate one path element from the other. In Windows the path separator is a semicolon symbol (;), you have something like: .;something.jar;D:/libs/commons.jar While in Linux based operating systems the path separator is a colon symbol (:), it looks like: […]
SWING / CATATAN</>↗Swing27 Apr 2006
If you have a JFrame in your Java Swing application and want to center its position on the screen you can use the following code snippets. The first way is to utilize java.awt.Toolkit class to get the screen size. The getScreenSize() method return a java.awt.Dimension from where we can get the width and height of […]
CORE API / CATATAN</>↗Core API23 Apr 2006
Environment variables are a set of dynamic values that can affect a running process, such as our Java program. Each process usually have their own copy of these variables. Now we would like to obtain the available variables in our environment or operating system, how do I do this in Java? Here is a code […]
JDBC / CATATAN</>↗JDBC20 Apr 2006
In this example you’ll learn how to create a program to insert data into a database table. To insert a data we need to get connected to a database. After a connection is obtained you can create a java.sql.Statement object from it, and using this object we can execute some query strings. package org.kodejava.jdbc; import […]