Refresh Your Java - Before Java Interview
We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....
Step 1: Create a .vm file
sayHello.vm:
Hello $name ! How are
you ?
Sample : input this to ve.getTemplate()
import java.io.StringWriter;
import org.apache.velocity.app.VelocityEngine;
import
org.apache.velocity.Template;
import
org.apache.velocity.VelocityContext;
public class
HelloWorld
{
public static void main( String[] args )
throws Exception
{
/* initialize an engine */
VelocityEngine ve = new VelocityEngine();
ve.init();
/* get the Template */
Template t = ve.getTemplate( "sayHello.vm" );
/* create a contex */
VelocityContext context = new VelocityContext();
context.put("name",
"John");
StringWriter writer = new StringWriter();
t.merge( context, writer );
System.out.println( writer.toString()
);
}
}
Output :
Please see below Name is replaced with
"John"
Hello John ! How are you ?
This Portal is intended to put all Java/J2ee related topics at one single place for quick referance, not only Technical , but also the Project Management Related thing such as Development Process methodoogies build process, unit testing etc.,
This Portal has More than 500 Java Interview Questions (also could be Considered as Quick Notes) very neatly separated topic by topic with simple diagrams which makes you easily understandable. Importantly these are from our Realtime expericance.