Our Blog > Blog Detail

Web Content Viewer- Asponte Custom Skin


Quick Development Tip: RAD Code Templates

  • Created By: uid=jewers,cn=users,dc=asponte,dc=com uid=jewers,cn=users,dc=asponte,dc=com
  • Updated: February 16, 2016

Code templates in Rational Application Developer (RAD)/Eclipse are a great way to keep Java code blocks consistent. To access the code templates navigate to Preferences -> Java -> Code Style -> Code Templates. Here you can specify the code that is automatically generated by RAD. An important note is these are only added when RAD creates the file/methods. This means that when you create new file in rad these comments and code will be set.




Here are a couple of my code templates:

New Java Files:


* Asponte

* ${user}




import java.util.logging.Level;

import java.util.logging.Logger;



Class Body:

/** Logger class name */

private static String CLASS_NAME = ${type_name}.class.getName();

/** Logger object */

private static Logger s_log = Logger.getLogger(CLASS_NAME);


You will notice I have several ${variables}. These variables will automatically populate in the context of your new file. There are two types of variables: variables defined by RAD and user defined variables. Sometimes as in the case of ${type_declaration} in "New Java Files" the variables could be required.


The next area we will look at is Preferences -> Java -> Editor -> Templates. These templates can be inserted anytime, not just at RAD creation. This makes these templates more versatile than the Code Templates we looked at before. Here are three that I use all time:


final String METHOD_NAME = "${enclosing_method}";

boolean isTraceEnabled = ${log:var(java.util.logging.Logger)}.isLoggable(Level.FINER);

boolean isDebugEnabled = ${log:var(java.util.logging.Logger)}.isLoggable(Level.FINEST);

boolean isErrorEnabled = ${log:var(java.util.logging.Logger)}.isLoggable(Level.SEVERE);

if(isTraceEnabled) {

   ${log:var(java.util.logging.Logger)}.entering(CLASS_NAME, METHOD_NAME,new Object[]{${enclosing_method_arguments}});




if(isTraceEnabled) {

   ${log:var(java.util.logging.Logger)}.exiting(CLASS_NAME, METHOD_NAME);



if(isDebugEnabled) {

   final String MESSAGE = ": ${cursor}";

    StringBuilder debugBuilder = new StringBuilder();






When I create a new method I type "addEn" and the press Ctrl+Space and "addEntering" will be automatically added defining method name and my logging status and then place the cursor at the end of the method block.



These tips can help to speed up your development time and keep some consistency throughout your code. A third advantage for me is everytime I create a method and see my 3 logging levels I am reminded to think about what I should log while coding and not after when something has broken.

Contact Form- Asponte Custom Skin


Contact Us


Call Us 888-926-9434
Complementary Content