User Guide

Table Of Contents
Using Java objects 933
Java considerations
Keep the following points in mind when you write a ColdFusion page that uses a Java class object:
The Java class name is case-sensitive. You must ensure that the Java code and the CFML code
use Employee as the class name.
Although Java method and field names are case-sensitive, ColdFusion variables are not case-
sensitive, and ColdFusion does any necessary case conversions. As a result, the sample code
works even though the CFML uses emp.firstname and emp.lastname; the Java source code uses
FirstName and LastName for these fields.
If you do not call the constructor (or, as in this example, comment it out), ColdFusion
automatically invokes the default constructor when it first uses the class.
Using an alternate constructor
The following ColdFusion page explicitly calls one of the alternate constructors for the Employee
object:
<html>
<body>
<cfobject action="create" type="java" class="Employee" name="emp">
<cfset emp.init("John", "Doe", 100000.00, 10)>
<cfset firstname=emp.firstname>
<cfset lastname=emp.lastname>
<cfset salary=emp.GetSalary()>
<cfset grade=emp.GetJobGrade()>
<cfoutput>
Employee name is #firstname# #lastname#<br>
Employee salary #DollarFormat(Salary)#<br>
Employee Job Grade #grade#
</cfoutput>
</body>
</html>
In this example, the constructor takes four arguments: the first two are strings, the third is a float,
and the fourth is an integer.
Java and ColdFusion data type conversions
ColdFusion does not use explicit types for variables, while Java is strongly typed. However,
ColdFusion data does use a number of underlying types to represent data.