ZIP AND GZIP / NOTES</>↗Zip and GZIP16 May 2008
The code below shows how to decompress and extract files from a zip archive. In the example we use the java.util.zip.ZipInputStream class. package org.kodejava.util.zip; import java.io.*; import java.util.zip.ZipInputStream; import java.util.zip.ZipEntry; public class UnzipDemo { public static void main(String[] args) { String zipName = "data.zip"; try (FileInputStream fis = new FileInputStream(zipName); ZipInputStream zis = new ZipInputStream(new […]
CORE API / NOTES</>↗Core API15 May 2008
The following code can be used to validate if a string contains a valid date information. The pattern of the date is defined by the java.text.SimpleDateFormat object. When the date is not valid a java.text.ParseException will be thrown. package org.kodejava.text; import java.text.SimpleDateFormat; import java.text.ParseException; public class DateValidation { public static void main(String[] args) { SimpleDateFormat […]
CORE API / NOTES</>↗Core API13 May 2008
To get Java Home directory we can obtain it from system properties using the java.home key. package org.kodejava.lang; public class JavaHomeDirectory { public static void main(String[] args) { String javaHome = System.getProperty("java.home"); System.out.println("JAVA HOME = " + javaHome); } } On my computer this code give me the following output: JAVA HOME = C:\Program Files\Java\jdk-17
CORE API / NOTES</>↗Core API10 May 2008
This example show you how to get operating system active user’s login name. We can obtain the username of current user by reading system properties using the user.name key. package org.kodejava.lang; public class GettingUserName { public static void main(String[] args) { String username = System.getProperty("user.name"); System.out.println("username = " + username); } }
JSP / NOTES</>↗JSP06 May 2008
This example show you how to obtain web application context path in JSP using Expression Language (EL) feature of JSP. To get the context path we can utilize the pageContext, it is an implicit object that available on every JSP pages. From this object you can get access to various object such as: servletContext session […]
SERVLET / NOTES</>↗Servlet03 May 2008
The context path always comes first in a request URI. The path starts with a “/” character but does not end with a “/” character. When I have a web application with the URL like http://localhost:8080/myapp` then/myapp` is the context path. For servlets in the default (root) context, this method returns "" (empty string). package […]