190 likes | 455 Views
A Beginners Guide to Java Integration in ColdFusion. Rick Root. Who Am I?. It just doesn’t seem right to have a slide with bullet points that prompt me to talk about myself. About This Session. Extend ColdFusion with “core” java Extend ColdFusion with external java libraries
E N D
A Beginners Guide to Java Integration in ColdFusion Rick Root
Who Am I? • It just doesn’t seem right to have a slide with bullet points that prompt me to talk about myself.
About This Session • Extend ColdFusion with “core” java • Extend ColdFusion with external java libraries • We will not talk about JVM tuning, writing CFX Custom Tags in Java, or writing your own Java classes.
Who Are You? • ColdFusion newbs • Never really used Java in ColdFusion • Just here for the networking
Using Core Java Functionality • Java Objects • Data Types • Creating and Initializing Java Objects • JavaCast() • Examples
Java Objects • It all starts with java.langObject • Java objects have methods, so ColdFusion variables do to. • Example 1
Data Types – Java vs. CF • Strictly typed, very picky! • Don’t assume! • Example 2
Creating and Initializing Java Objects • In Java, create and initialize all at once, ie:foo = new ClassName(arguments) • In CF, use CreateObject() and init() methodfoo = CreateObject(“java”,”path.to.ClassName”); foo.init(arguments); • Multiple constructors / overloaded methods foo.init(“string”);foo.init(someint);
JavaCast() • Force a ColdFusion variable to be a specific data type • Example 3 & 4
String Concatenation Example • Object creation is expensive • Strings are immutable • Java StringBuffer object can help! • Example 5
Using Third Party Libraries • Where to Install • Java Loader • Examples
Installing Third Party Libraries • Standalone: <cfroot>/lib • Multi-server Install, all instances: <jrunroot>/servers/lib • Multi-server install, specific Instance: <jrunroot>/servers/<instancename> /cfusion.ear/cfusion.war /WEB-INF/cfusion/lib • Anywhere you want!
Using JavaLoader • javaloader.cfc – Mark Mandel • Access classes without requiring them to be in the server CLASSPATH • Javaloader.riaforge.org • Example 6
Examples • Generating Excel Files • Creating delimited text files • Extracting JPEG image metadata
Generating Excel Files • Apache POI – API to interface with Microsoft Office files • http://poi.apache.org • Create Excel files in native format • Use more Excel features • Example 7
Creating Delimited Files • JavaCSV makes it easy • Choose your delimiter • Automatic quoting when data contains your delimiter or even newlines • Example 8
Extracting JPEG Image Metadata • Digital cameras store lots of metadata in captured images • Timestamp • Exposure • Camera model • Lots of stuff I don’t understand! • Example 9
Wrap Up • Rick Root • rick.root@gmail.com • http://www.opensourcecf.com/