APACHE COMMONS / NOTES</>↗Apache Commons09 Jul 2008
Using the FileUtils.deleteDirectory() from the Apache Commons IO library, we can simplify the process of deleting directory and everything below it recursively. package org.kodejava.commons.io; import org.apache.commons.io.FileUtils; import java.io.File; import java.io.IOException; public class DeleteDirectory { public static void main(String[] args) { try { File directory = new File("F:/Temp"); // Deletes a directory recursively. When a deletion […]
APACHE COMMONS / NOTES</>↗Apache Commons05 Jul 2008
This example demonstrates how to create a human-readable file size using the FileUtils class of the Apache Commons IO library. The byteCountToDisplaySize() method take the file size in bytes and return a human-readable display of the file size in bytes, kilobytes, megabytes, gigabytes, etc. package org.kodejava.commons.io; import org.apache.commons.io.FileUtils; import java.io.File; public class ReadableFileSize { public […]
BASIC / NOTES</>↗Basic03 Jul 2008
The @SuppressWarnings annotation tells the compiler to suppress the warning messages it normally shows during compilation time. It has some level of suppression to be added to the code, these level including: all, deprecation, fallthrough, finally, path, serial and unchecked. package org.kodejava.basic; import java.util.Calendar; import java.util.Date; public class SuppressWarningsExample { @SuppressWarnings(value={"deprecation"}) public static void main(String[] […]
BASIC / NOTES</>↗Basic29 Jun 2008
We use the @Override annotation as part of method declaration. The @Override annotation is used when we want to override methods and want to make sure have overridden the correct methods. As the annotation name we know that there should be the same method signature in the parent class to override. That means using this […]
BASIC / NOTES</>↗Basic28 Jun 2008
To mark a method as deprecated we can use the JavaDoc @deprecated tag. This is what we did since the beginning of Java. But when a new metadata support introduced to the Java language we can also use annotation. The annotation for marking method as deprecated is @Depreated. The difference between these two that the […]
CORE API / NOTES</>↗Core API24 Jun 2008
This example using the Java Compiler API introduced in JDK 1.6 to programmatically compile a Java class. Here we’ll compile the Hello.java. The process of compiling can be start by obtaining a JavaCompiler from the ToolProvider.getSystemJavaCompiler(). The simplest way to compile is by calling the run() method of the compiler and passing the first three […]