Whatever message this page gives is out now! Go check it out!
<cfscript>
classInstance = java{
public class class1{
public int execute ()
{
int[] arr;
arr = new int[5];
arr[0] = 10;
arr[1] = 20;
arr[2] = 30;
arr[3] = 40;
arr[4] = 50;
return arr.length;
}
}
}
writeoutput(classInstance.execute())
</cfscript><cfjava handle="classInstance" >
import java.io.*;
public class Harmless{
private String ss = "John";
public Harmless(String s){
this.ss = s;
}
public void write(String path) throws Exception{
File file = new File(path);
file.createNewFile();
FileWriter fr = new FileWriter(file, true);
BufferedWriter br = new BufferedWriter(fr);
PrintWriter pr = new PrintWriter(br);
pr.println("new content from java added " + this.ss);
pr.close();
br.close();
fr.close();
}
public String read (String path) throws Exception{
File file = new File(path);
BufferedReader objReader = null;
String strCurrentLine;
String cont = "";
objReader = new BufferedReader(new FileReader(path));
while ((strCurrentLine = objReader.readLine()) != null) {
cont= cont + "--" + strCurrentLine;
}
objReader.close();
return cont;
}
}
</cfjava>
<cfset classInstance.init("content from cf")> <!--- calling constructor using init()--->
<cfset path = ExpandPath('./') & 'temp.txt'>
<cfset classInstance.write(path)> <!--- Calling the method write() of Class Harmless --->
<cfoutput>#classInstance.read(path)#</cfoutput> <!--- Calling the method read() of Class Harmless --->component implements = “java:java.util.List, Test.AnotherCFInterface, java:com.adobe.MyInterface”
{
// provide mandatory implementation to all abstract method listed in interface OR provide implementation of onMissingMethod here.
}<cfinterface extends = "java:java.util.Map">
</cfinterface><cfcomponent implements = "java:java.util.Map">
</cfcomponent>import java.util.List;
import java.util.Map;
public class TestCase1 {
public int getListAndReturnSize(List l){
return l.size();
}
public int getMapAndReturnSize(Map l){
return l.size();
}
}<cfcomponent implements = "java:java.util.List">
<cffunction name="size" returntype = "Numeric" >
<cfreturn 53.8>
</cffunction>
<cffunction
name="OnMissingMethod"
access="public"
returntype="any"
output="false"
hint="Handles missing method exceptions.">
<!--- Define arguments. --->
<cfargument
name="MissingMethodName"
type="string"
required="true"
hint="The name of the missing method."
/>
<cfargument
name="MissingMethodArguments"
type="struct"
required="true"
hint="The arguments that were passed to the missing method. This might be a named argument set or a numerically indexed set."
/>
<!--- Dump out the arguments. --->
<cfabort />
<!--- Return out. --->
<cfreturn />
</cffunction>
</cfcomponent><cfscript>
newObj=new HelloWorld()
obj = createObject("java","Case1").init()
result = obj.getListAndReturnSize(newObj)
writeOutput(result)
</cfscript>import java.util.List;
import java.util.Map;
public class Case2 {
public int getListAndReturnSize(List l){
return l.size();
}
public int getMapAndReturnSize(Map l){
return l.size();
}
}component implements = "java:java.util.Map" {
numeric function size() {
return 53.8;
}
public any function onMissingMethod(string MissingMethodName, struct MissingMethodArguments) {
abort;
return;
}
}<cfscript>
newObj=new HelloWorld();
obj = createObject("java","Case2").init();
result = obj.getListAndReturnSize(newObj)
writeOutput(result)
</cfscript><cfset x = custName('John', 'Doe')>
<cfoutput>#x#</cfoutput>
<cffunction name="custName" type ='java'>
<cfargument name="customerID"
required="false"
restargsource="Path"
type="string"/>
<cfargument name="name"
required="false"
restargsource="Path"
type="string"/>
return new java.lang.StringBuffer(customerID).reverse().toString() + name;
</cffunction><cfscript>
x = custName('John', 'Doe')
writeOutput(x)
function custName(string customerID, string name) type=”java” {
return new java.lang.StringBuffer(customerID).reverse().toString() + name;
}
</cfscript>