Posts

Showing posts from June, 2008

-- How to Schedule a Task --

In some application some tasks need to be run periodically for example GUI screen should update the data from server periodically. This java tips illustrate a method of scheduling a task periodically. Developers may use it for repetitive invoking of a method as per their requirements. For this aim, first you have to make a class extending TimerTask abstract class and write code in run method, you want to run repetitively. import java.util.TimerTask; public class Shedule extends TimerTask{ public void run() { // add the task here } } In your main program you can call this code to schedule task: java.util.Timer timer = new java.util.Timer(); Calendar date = Calendar.getInstance(); date.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); date.set(Calendar.HOUR, 0); date.set(Calendar.MINUTE, 0); date.set(Calendar.SECOND, 0); date.set(Calendar.MILLISECOND, 0); //sheduler run now //timer.schedule(new Shedule(), 0, 60 * 60); // Schedule to run every Sun...

-- Encode a URL --

import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; public final class TestURLEncode{ public static void main( String[] args ) throws URISyntaxException, MalformedURLException{ // reserved chars that are not escaped in URLs include: // ; / ? : @ & = + $ , URI uri = new URI( "http", "//www.example.com/you & I 10%? weird & weirder neé", null ); System.out.println( uri.toURL().toString() ); // prints http://www.example.com/you%20&%20I%2010%25?%20wierd%20&%20wierder%20neé // note how it fails to encode é } }

-- Velosity Templates --

Velosity Engine: -> Velocity is an open source templating tool developed by an international volunteer community and hosted by the Apache Software Foundation's Jakarta Project -> It's free and the source code is available under the Apache Software License, a business-friendly open source license -> language - Velocity Template Language (VTL). -> any Aplication using Velosity requires -> 1.0 Template -> 2.0 Corresponding java programme -------------template------------------------ Hello $name! Welcome to Velosity! -------------java programme------------------ import java.io.StringWriter; import org.apache.velocity.app.VelocityEngine; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; public class HelloWorld{ PSVM throws Exception{ VelocityEngine ve=new VelocityEngine(); ve.init(); Template t=ve.getTemplate("src/com/neo/..../myvelocity/helloworld.vm"); VelocityContex...