Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Java Copier Frees You from Tedious Coding : Page 3

Transfer the repetitive copy/paste/edit part of your Java programming from your hands to your computer. With the somusar/tjpp Java copier, you can set yourself free of this tedious work.


advertisement

WEBINAR: On-Demand

Unleash Your DevOps Strategy by Synchronizing Application and Database Changes REGISTER >

Somusar/tjpp Does Tedious Coding for You
Multi-property Java classes often require developers to write code to perform a similar action for each property. An example is copying data from a database query result set to the corresponding members of the Java class. Another is the set of accessors and mutators, often referred to as getters and setters. A third is the toString() method returning a string containing the current value of each class property, as in the following example:

public String toString() { String s = "[ propertyA = " + propertyA + " propertyB = " + propertyB + " ]"; return s; }

This method can be very useful when debugging, but writing it can be tedious (as is the case for getters and setters). Moreover, the toString method needs maintenance: if you add a new property to the class, you also have to extend it to include the new property in the return string. This has led many Java programmers to discard it from their classes, even though they appreciate its usefulness.



Somusar/tjpp provides a means to let your computer rapidly do this tedious work for you. The following input automatically produces a standard five-properties Java class (see Listing 1).

public class FiveProperties { $ property(int, a_unique_id, readonly) $ property(double, a_double) $ property(String, a_string) $ property(Object, an_object) $ property(int [][], an_int_array) $ getters $ setters $ to_string }

The class declaration contains a list of properties, complete with type, identifier, and optional flag for immutable properties ("readonly"). Then three lines instruct tjpp to produce getters, setters, and toString for those properties. You can freely add handwritten Java code wherever you like in this input. Tjpp will copy it to the output Java file, including blank lines, comments, and so on. The only exceptions are tjpp command lines, marked by a dollar sign ($) in the first column, which will not be in the Java file--not even as blank lines.

You also can easily write your own macros, and program tjpp to perform whatever repetitive task you meet in your daily work. And you don't need to learn a completely new, complex language syntax to do this.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date