CORE API / NOTES</>↗Core API28 Sep 2008
This examples shows how to get a path name or location from where our class is loaded. package org.kodejava.lang; public class CodeSourceLocation { public static void main(String[] args) { CodeSourceLocation csl = new CodeSourceLocation(); csl.getCodeSourceLocation(); } private void getCodeSourceLocation() { // The location from where the class is loaded. System.out.println("Code source location: " + getClass().getProtectionDomain().getCodeSource().getLocation()); […]
CORE API / NOTES</>↗Core API25 Sep 2008
In this example we use the String‘s class matches() methods to match a string to be a valid email address based on the given regex. This example also demonstrate the power of regular expression to validate an email address. Using regular expression makes it easier to validate data such as email address. After the code […]
JSP / NOTES</>↗JSP24 Sep 2008
In this example you can learn how to include a JSP fragment into another JSP page. This is a common practice when creating a web application where we usually have a navigation section, the main content and the footer of a web page. Using the include directive make it simpler to maintain the fragment of […]
SERVLET / NOTES</>↗Servlet22 Sep 2008
The configuration below gives us example how to define a welcome-files to our web application. The welcome file is default file to be loaded by a servlet container when we access a URL without telling which page to load. <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0"> <welcome-file-list> <welcome-fi...
CORE API / NOTES</>↗Core API18 Sep 2008
This code example use the Collections.binarySearch() to search an specified object inside a specified collections. Prior to calling the binarySearch() method we need to sort the elements of the collection. If the object is not sorted according to their natural order the search result will be undefined. package org.kodejava.util; import java.util.Arrays; import java.util.LinkedList; import java.util.Collections; […]
CORE API / NOTES</>↗Core API15 Sep 2008
This example demonstrate how to rotate the elements of a collection object. We can use the java.util.Collections class and call the rotate() method with the collection to rotate and the distance as the parameters. package org.kodejava.util; import java.util.List; import java.util.ArrayList; import java.util.Collections; import java.util.Arrays; public class CollectionRotate { public static void main(String[] args) { List<Integer> […]