PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Call to JavaLoad
  • Error
  • Parameters that must be passed to the Java function
  • Note
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
JavaExecuteFunction (Function)
In French: JavaExécuteFonction
Starts a specific static function of a given Java class.
Caution:
  • The path of the class to run must be specified by JavaLoad.
  • The Java class run must implement the following method: "static public <Return Type> <Function Name>".
Example
WINDEVWEBDEV - Server codeReports and QueriesWindowsJavaAjax
// Paths where the classes will be sought
// Note: Specify the names of folders/directories and the names of .jar or .zip
// (and not just the name of .class)
sPathJavaClass is string = fExeDir()
IF JavaLoad(sPathJavaClass) THEN
// Java class to use
// Note: If the class is already found in a sub-folder of .Jar,
// specify the folder. For example: "singlejar/Application"
sJavaClass is string = "Application"
// Function of the class
sJavaFunction is string = "sum"
Res is real
Res = JavaExecuteFunction(sJavaClass, sJavaFunction, javaDoubleReal, 1.55, 2.35)
Info(Res)
ELSE
Error("Incorrect Java locations", ErrorInfo())
END
// JAVA code
import java.awt.*;
import java.awt.event.*;

public class Application {
   public static double sum (double a, double b) {
       return a + b;
   }
}
Syntax
JavaExecuteFunction(<Class Name> , <Function Name> , <Return Type> [, <Parameter 1> , ... [, <Parameter N>]])
<Class Name>: Character string (with quotes)
Name of the class containing the function to run. This parameter is case sensitive: it must exactly correspond to the name specified in the class. If the class is contained in one or more packages, the full path of this class must be specified with the "/" character as separator. Example: "MyPackage/MySubPackage/MyClass".
<Function Name>: Character string (with quotes)
Name of the Java function to run. This parameter is case sensitive: it must exactly correspond to the name specified in the class.
<Type of Return>: Integer constant
Return type of the Java function among the following values:
javaBooleanType of return value: Boolean.
javaCharType of return value: Character.
javaStringType of return value: String.
javaStringUnicodeType of return value: Unicode String.
javaStringUTF8Type of return value: String in UTF8 format.
javaIntegerType of return value: Integer.
javaShortIntegerType of return value: Short Integer.
javaLongIntegerType of return value: Long Integer.
javaByteType of return value: Byte.
javaRealType of return value: Real.
javaDoubleRealType of return value: Double Real.
javaVoidType of return value: Void.
<Parameter 1>: Type corresponding to each parameter
Parameters expected by the Java function. These parameters must have the same type as the parameters expected by the Java function. Only the simple types can be used (see the Notes).
<Parameter N>: Type corresponding to each parameter
Parameters expected by the Java function. These parameters must have the same type as the parameters expected by the Java function. Only the simple types can be used (see the Notes).
Remarks

Call to JavaLoad

  • A single call to JavaLoad must be performed in a WINDEV application or in a WEBDEV site.
    Java JavaLoad can be called as many times as necessary.
  • One of the following versions of SUN Java virtual machine is required: version 1.1, 1.2 (or sub-version), 1.3 (or sub-version), 1.4, 1.5 or 6.

Error

  • If an error occurs when running the specified class, the corresponding error message is displayed in a message box and the WINDEV application (or the WEBDEV site) is stopped.
  • Possible reasons for the problem (class not found for example):
    • wrong syntax in the class name (wrong case, class contained in a package and full path not specified, ...)
    • class compiled with a version of SUN Java virtual machine and run with an earlier version of JRE, ...

Parameters that must be passed to the Java function

Only the "simple" types can be used: integer, real, string, boolean. Using another WLanguage type triggers a WLanguage error.
Therefore, you cannot call a Java function containing "byte" or "short" parameters. To call this Java function with JavaExecuteFunction, the "byte" or "short" parameters of the Java function must be changed into "int" parameters.

Note

The ".class" file is the result of the compilation of one or more files containing Java code. It does not contain the source code of the application but an intermediate format ("bytecode") intended to be interpreted by the Java virtual machine (JVM).
Related Examples:
WD JAVA Calls Training (WINDEV): WD JAVA Calls
[ + ] WD JAVA Calls is an example containing two configurations of project:
- A "Windows Application" configuration that is used to create the executable of the application
- A "Java Application" configuration that is used to create the Java archive (.JAR) of the application
This example is supplied with a JAR archive named "JavaFunction" external to the application.
It presents the call to the methods of classes of this JAR archive via the WLanguage function named JavaExecuteFunction.
This example also explains how a memory table can be filled (identical in Java mode and in Windows mode)
Components
WINDEVWEBDEV - Server codeReports and Queries wd230jav.dll
Java wd230java.jar
Linux wd230jav.so
Minimum required version
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment