ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / Windows functions / Java functions
  • 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/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
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
WINDEVWindowsJava
// 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> , <Type of return> [, <Parameter 1> [... [, <Parameter N>]]])
<Class name>: Character string
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
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.
javaByteType of return value: Byte.
javaCharType of return value: Character.
javaDoubleRealType of return value: Double Real.
javaIntegerType of return value: Integer.
javaLongIntegerType of return value: Long Integer.
javaRealType of return value: Real.
javaShortIntegerType of return value: Short Integer.
javaStringType of return value: String.
javaStringUnicodeType of return value: Unicode String.
javaStringUTF8Type of return value: String in UTF8 format.
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, etc.)
    • 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 to "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)
Component: wd290jav.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 06/22/2023

Send a report | Local help