CORE API / NOTES</>↗Core API20 Jun 2006
In this example you will learn how to convert decimal number to binary number. To convert decimal number to binary we can use Integer.toBinaryString() method. This method takes a single parameter of integer and return a string that represent the equal binary number. If you want to convert the other way around, from binary string […]
CORE API / NOTES</>↗Core API19 Jun 2006
This example will show you how to get the size of a file. To obtain the size of a file you can use the File‘s length() method. The length() method return the file size in bytes. package org.kodejava.io; import java.io.File; public class FileSize { public static void main(String[] args) { File file = new File("README.md"); […]
CORE API / NOTES</>↗Core API15 Jun 2006
To get file last modification date we can use the lastModified() method of the File class. This method returns a long value. After getting this value you can create an instance of java.util.Date class and pass this value as the parameter. This Date will hold the file’s last modification date. package org.kodejava.io; import java.io.File; import […]
CORE API / NOTES</>↗Core API11 Jun 2006
To convert decimal number (base 10) to hexadecimal number (base 16) we can use the Integer.toHexString() method. This method takes an integer as parameter and return a string that represent the number in hexadecimal. To convert back the number from hexadecimal to decimal number we can use the Integer.parseInt() method. This method takes two argument, […]
AWT / NOTES</>↗AWT10 Jun 2006
Here you see a code sample to read an image file. This code will work either the image file is located in a file folder or inside a jar file. You can use javax.imageio.ImageIO class to read the image file. package org.kodejava.awt; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.IOException; import java.io.InputStream; public class ReadingImage { public […]
CORE API / NOTES</>↗Core API09 Jun 2006
package org.kodejava.network; import java.net.InetAddress; import java.net.UnknownHostException; public class HostNameExample { public static void main(String[] args) { try { InetAddress address = InetAddress.getLocalHost(); System.out.println("Hostname: " + address.getHostName()); } catch (UnknownHostException e) { e.printStackTrace(); } } } An example of output produce by the code snippet above is: Hostname: Krakatau