CORE API / CATATAN</>↗Core API05 Sep 2006
The following code snippet demonstrates how to get some part from a string. To do this we use the String.substring() method. The first substring() method take a single parameter, beginIndex, the index where substring start. This method will return part of string from the beginning index to the end of the string. The second method, […]
BASIC / CATATAN</>↗Basic02 Sep 2006
When we create a Java application we might want to pass a couple of parameters to our program. To get the parameters passed from the command line we can read it from the main(String[] args) method arguments. To make a class executable we need to create a main() method with the following signatures: public static […]
CORE API / CATATAN</>↗Core API01 Sep 2006
To get the location of temporary directory we can use the System.getProperty(String) method and pass a property key "java.io.tmpdir" as the argument to the method. package org.kodejava.lang; public class TempDirExample { public static void main(String[] args) { // This is the property name for accessing OS temporary directory // or folder. String property = "java.io.tmpdir"; […]
APACHE COMMONS / CATATAN</>↗Apache Commons28 Agt 2006
This example shows how we can use the Apache Commons IO library to simplify a file copy process. package org.kodejava.commons.io; import org.apache.commons.io.FileUtils; import java.io.File; import java.io.IOException; public class FileCopyExample { public static void main(String[] args) { // The source file name to be copied. File source = new File("README.md"); // The target file name to […]
CORE API / CATATAN</>↗Core API26 Agt 2006
package org.kodejava.util; import java.util.Calendar; public class DayYearToDayMonth { public static void main(String[] args) { // Create an instance of calendar for the year 2017 and set the // day to the 180 day of the year. Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, 2021); cal.set(Calendar.DAY_OF_YEAR, 180); // Print the date of the calendar. System.out.println("Calendar date is: " […]
CORE API / CATATAN</>↗Core API22 Agt 2006
The following example using the GregorianCalendar.isLeapYear() method to check if the specified year is a leap year. package org.kodejava.util; import java.util.GregorianCalendar; public class LeapYearExample { public static void main(String[] args) { // Here we show how to know if a specified year is a leap year or // not. The GregorianCalendar object provide a convenient […]