Ben Forta On Java Methods In ColdFusion

Posted August 28, 2006 at 9:45 AM by Ben Nadel

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:

  • <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!



Reader Comments

Dec 15, 2010 at 7:20 AM // reply »
12 Comments

yea Ben! Using java functions in ColdFusion is good practice in terms of performance and ease of use some times. For an example removeRows function really gem. Really it saved my time and smooth functionality achievement when dealing with QueryNew based queries.

It will be great if some one(including me) document more java methods useful in ColdFusion development.

Thanks,
Raghuram Reddy Gottimukkula
Adobe Certified Advanced ColdFusion Developer
Hyderabad India


Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
Jun 18, 2013 at 9:20 PM
Mapping AngularJS Routes Onto URL Parameters And Client-Side Events
I couldn't find examples of passing multiple arguments using the when() routing statement so figured out through trial and error that you can pass multiple arguments using the following format: .whe ... read »
Jun 18, 2013 at 3:39 PM
Experimenting With The Amazon Simple Storage Service (S3) API Using ColdFusion
Hi Ben, THANKS! While not bleeding edge, it is new to me & I like learning new things every day! ... read »
Jun 18, 2013 at 12:30 PM
Disabling Auto-Correct And Auto-Capitalize Features On iPhone Inputs
Also spellcheck="false" should be mentioned as part of html5 specs ... read »
Jun 18, 2013 at 8:40 AM
Using Named Functions Within Self-Executing Function Blocks In Javascript
Hi Ben, you forgot to mention the most important thing for named self-executing functions - they can be referenced by name ONLY inside their execution context (which is parens in this case), it mean ... read »
dee
Jun 18, 2013 at 7:01 AM
My Safari Browser SQLite Database Hello World Example
hai ben, this program is really good i could understand the concept but i dint know how to save it and how to open it as you have done in the video can u give that details pls ... read »
Jun 18, 2013 at 6:04 AM
Clearing Inline CSS Properties With jQuery
Thanks a lot for for post! It helped me a lot... after being stuck since 24 hrs.. found solution from your post. Thanks again! ... read »
Jun 18, 2013 at 2:31 AM
SOTR 2013 - The Best Conference I Never Went To
I keep watching it, should keep me happily distracted until SotR14 ;) ... read »
Jun 17, 2013 at 9:45 PM
What If All User Interface (UI) Data Came In Reports?
@Jonah, As I was reading what you wrote, it occurred to me that maybe I do something similar to that in some of my client-side code. In an application I'm working on, there are a bunch of unrelated ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools