> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Using ABBYY FlexiCapture SDK in Java

Because Java is platform-independent, it has no special tools for integration with platform-dependent technologies such as COM. Instead, it provides a truly platform-independent but very low-level interface for integration with any native platform – Java Native Interface (JNI). Creating wrappers using JNI is not an easy task: you should write huge amount of code to implement wrappers for all necessary interfaces and methods. But there is no need to do it for FlexiCapture SDK. FlexiCapture SDK provides ready-to-use Java classes for the Engine library. These Java classes can be used directly from Java applications.

## Adding FlexiCapture SDK library to a Java project

ABBYY FlexiCapture SDK includes the **com.abbyy.FCEngine.jar** file, which contains the Java class library for FlexiCapture SDK. You can find it in the **Inc\Java** folder. The path to this file can be specified in **classpath** parameter in the command line and in projects settings in different Java development environments. For example:

```bat theme={null}
%JDK%\bin\Javac -classpath <path>/com.abbyy.FCEngine.jar Hello.java
```

%JDK% is the path to Java Development Kit.

> [!NOTE]
>
> See the supported Java Development Kit version in [System Requirements](https://docs.abbyy.com/flexi-capture/sdk/specifications/systemrequirements.md#jdk-versions).

## Loading and unloading FlexiCapture SDK

To load the [**Engine**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/engine.md) object, you can use the static **Engine** class:

1. Use its **Load** method to load FlexiCapture SDK, and **Unload** method – to unload it. This way is identical to the standard way of loading and unloading the Engine object.
2. Use its **CreateEngineInprocLoader** or **CreateEngineOutprocLoader** methods to load Engine by means of COM. See the description of the [**IEngineLoader**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/iengineloader.md) interface for details. If you use the **CreateEngineOutprocLoader** method for loading, you do not need to call [**IWorkProcessControl::SetParentProcessId**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/iworkprocesscontrol-setparentprocessid.md) method, because it is done automatically.

The following code sample illustrates the use of FlexiCapture SDK in Java.

```java theme={null}
import com.abbyy.FCEngine.*;
public class Hello {
 public static void main( String[] args )
 {
    try {
         // Load the Engine
         IEngineLoader engineLoader = Engine.GetEngineLoader( SamplesConfig.GetDllPath() );
         engineLoader.setCustomerProjectId( SamplesConfig.GetCustomerProjectId() );
         engineLoader.setLicensePath( SamplesConfig.GetLicensePath() );
         engineLoader.setLicensePassword( SamplesConfig.GetLicensePassword() );
         IEngine engine = engineLoader.GetEngine();
         try{
            // Open a project and work with it
            IProject project = engine.OpenProject( "D:\\TestProject\\Testproject.fcproj" );
            ...
         } catch {
            ...
         } finally {
              Engine.Unload();
         }
     } catch( Exception ex ) {
         trace( ex.getMessage() );
     }
  }
...
}
```

For working with the **Engine** object created via an engine loader, the **Engine** class provides the methods which call the corresponding COM functions to marshal the interface pointer across threads:

<table width="100%"><thead><tr><th>**Method**</th><th>**Signature**</th><th>**Comment**</th></tr></thead><tbody><tr><td>**MarshalInterface**</td><td><pre>`long MarshalInterface();`</pre></td><td>Calls the **CoMarshalInterface** COM function to marshal the [**IEngine**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/engine.md) interface. This method should be called on the thread where the engine was created, to ensure that the data needed for creating a proxy object on another thread will be available.Returns the handle to the marshaling data.</td></tr><tr><td>**UnmarshalInterface**</td><td><pre>`IEngine UnmarshalInterface( long handle );`</pre></td><td>Calls the **CoUnmarshalInterface** COM function to unmarshal the [**IEngine**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/engine.md) interface, i.e. create a proxy object with which the client process will be able to interact in the same way as with the engine itself.Takes the handle to the marshaling data (returned by the **MarshalInterface** method) as the input parameter and returns a pointer to the **IEngine** interface.</td></tr></tbody></table>

ABBYY FlexiCapture SDK includes a simple Hello sample in Java. You can access this sample by selecting Start > Programs > ABBYY FlexiCapture 12 SDK > Code Samples Folder > Hello (Java).

## Calling methods with out-parameters

There are several methods in ABBYY FlexiCapture SDK which have out-parameters that receive a new value after the method call and must be passed by reference. These parameters are marked in the type library and in descriptions of methods in this Developer's Help as \[out] or \[in, out].

When working with ABBYY FlexiCapture SDK in Java, you have to use a special **Ref** class to pass a parameter by reference. See examples below.

Example in which the out-parameters are passed by reference to the [**IReadStream::Read**](https://docs.abbyy.com/flexi-capture/sdk/api-reference/ireadstream-read.md) method:

> [accordion] Sample code for out-parameters
>
> ```java theme={null}
> public int Read( Ref _data, int count ) {
>    ...
>    byte[] data = new byte[...];
>    _data.set( data );
> }
> ```
