CORE API / CATATAN</>↗Core API28 Mei 2006
In this example you will see how to delete a file in Java. To delete a file we start by creating a File object that represent the file to be deleted. We use the exists() method to check if the file is exists before we try to delete it. To delete the file we call […]
CORE API / CATATAN</>↗Core API25 Mei 2006
The example here show you how to get an IP or host address using the java.net.InetAddress class. To get an instance of InetAddress we call a static method of this class, the method is getLocalHost(), which return the local host address. Next, to get the IP address we can call the getHostAddress() method. package org.kodejava.net; […]
APACHE COMMONS / CATATAN</>↗Apache Commons22 Mei 2006
This code snippet show you how to use HashCodeBuilder and EqualsBuilder class from the Apache Commons Lang library to implement the hashCode() and equals() method of an object. To use both of these classes, we just need to create instance of these classes and append the properties that we will use to calculate the hashcode […]
APACHE COMMONS / CATATAN</>↗Apache Commons17 Mei 2006
package org.kodejava.commons.lang; public class ObjectHashCodeDemo { public static void main(String[] args) { Book book1 = new Book(1L, "Spring Boot in Action", "Craig Walls"); Book book2 = new Book(2L, "Docker in Action", "Jeff Nickoloff"); Book book3 = book1; System.out.println("book1.hashCode() = " + book1.hashCode()); System.out.println("book2.hashCode() = " + book2.hashCode()); System.out.println("book3.hashCode() = " + book3.hashCode()); } } package […]
CORE API / CATATAN</>↗Core API17 Mei 2006
Sometimes you need to return an empty collection from your Java methods. The java.util.Collections utility class have three different static constants for creating empty List, Set and Map. Collections.EMPTY_LIST Collections.EMPTY_SET Collections.EMPTY_MAP There are also methods when you want to create type-safe empty collections. Collections.emptyList() Collections.emptySet() Collections.emptyMap() Bellow it the code example. package org.kodejava.util; import java.util.*; […]
APACHE COMMONS / CATATAN</>↗Apache Commons13 Mei 2006
The following code snippet shows you how to write strings of data into a file using the Apache Commons IO library. We can use the FileUtils.writeStringToFile() method to do it. This method accepts the file object where the data will be stored, the data itself, and the encoding. package org.kodejava.commons.io; import org.apache.commons.io.FileUtils; import java.io.File; import […]