Ben Forta On Java Methods In ColdFusion

Posted August 28, 2006 at 9:45 AM

Tags: ColdFusion

Ben Forta posted a blog entry about Java properties last week and I took the opportunity to ask him about how safe it was to use the Java methods that underlie the world of ColdFusion. If you have been following my blog, you know that I am loving the Java stuff that is accessible from the ColdFusion application layer. I want to start using more of it in my applications, but I don't want to use stuff that will explode in the next version of ColdFusion.

So I asked Ben Forta how safe it was to use the underlying Java methods, and this is what he had to say:

Ben, those are two different questions. Core Java stuff is not going away, we have no plans on rebuilding CF in something other than Java, so leveraging underlying Java is perfectly safe (and highly reccommended). As for CF internals that are written in Java, well, if they are undocumented then they are not supported and may indeed change or evolve - and service factory definitely falls into that category.

From this, I gathered that things like CreateObject( "java", "java.lang.String" ) are definitely definitely safe as that is part of Core Java. However, when I asked him about the information that is available via the GetMetaData() method, this is what he had to say:

Ben, I guess that would depend on the object. But I think you're safe with that one.

I then asked him about calling Java string methods directly from a ColdFusion variable, as in:

 Launch code in new window » Download code as text file »

  • <cfset strText = "ColdFusion rocks it hardcore!" />
  •  
  • <!--- Call the String::ReplaceAll() method. --->
  • #strText.ReplaceAll( "hardcore", "very hardcore" )#

... Ben Forta said:

Ben, simple CF variables are in fact Java strings, so you can safely use any String class methods on them. FYI, you can always look at #var.getClass().getName()# to see what the underlying class behind a ColdFusion variable is.

And when I asked about things like the ColdFusion Query object's IsFirst(), IsLast(), RemoveRows(), Ben stated:

Those internal query object methods are how CF works its magic (how a cfoutput over a query works, for example). I guess those could change, but I highly doubt that would happen.

From all this, it seems that calling Java methods from a ColdFusion object is fairly acceptable. It's not set in stone, but things like the String object methods seem to be very definite. This is waaaay cool. Thanks Ben!

Download Code Snippet ZIP File

Post Comment  |  Ask Ben  |  Other Searches  |  Print Page




Reader Comments

There are no comments posted for this web log entry.


Post Comment  |  Ask Ben

Recent Blog Comments
Mar 22, 2010 at 3:08 AM
Ask Ben: Selecting XML Attributes Given Other XML Attributes
Thanks for the response. I finally discovered that I was getting this error because I had cfsetting enablecfoutputonly="yes" in Application.cfc, and was neither setting it to false elsewhere nor brac ... read »
Mar 21, 2010 at 8:57 PM
The Bourne Ultimatum Starring Matt Damon And Julia Stiles
late to the party, but my observation is this: rewatch carefully for the platonic nature of the relationship between nicki and jason. she never flirts with him. he never comes on to her. they alway ... read »
Mar 21, 2010 at 7:40 PM
Is Simulating User-Input Events With jQuery Ever A Good Idea?
A couple of things. One you embed the initial state of of more-info in the CSS. IMHO, that behavior should be in jQuery: moreInfo.hide(); It shows that the behavior your toggling and closing is mor ... read »
Mar 21, 2010 at 3:59 PM
Exploring ColdFusion Component Runtime Class Properties And Serialization
@Elliott, according to Ben's experiment, serializeJSON() doesn't access the private data by default - it doesn't even access the getHair() method - so trying to clone a Girl.cfc via serializeJSON/des ... read »
Mar 21, 2010 at 3:49 PM
Ask Ben: Javascript String Replace Method
I'm confused a bit by what you are asking, but if had this sentence: The color, red, is in the style statement; style: red;. and wanted to remove all or change all of the commas, colons, and semi-c ... read »
Mar 21, 2010 at 3:13 PM
Ask Ben: Javascript String Replace Method
I am trying to make a java program to count the number of times that these punctuation marks occur in a body of text: , : ; . ! - ' " ? / \ I am using this piece to ferret out the commas: numcommas ... read »
Mar 21, 2010 at 11:13 AM
A New Wrist Pain
@chiropractor suwanee, Spoken like someone trying to sell something. Other than for minor, temporary relief from some back pain, chiropractic treatment is nothing but placebo effect and quackery. ... read »
Mar 21, 2010 at 6:32 AM
ColdFusion CFPOP - My First Look
Apologies... The field name in the db for C. is "BounceCode" It stores the code / message which is returned in the email. Sorry for the confusion. ... read »