Java Wrapper

Pre-compiled Binaries

Pre-compiled binaries can be downloaded from Java. Development binaries coming from the buildbot server can be found at Java.

Download the platform-independent.7z file and expand it to a folder called platform-independent using 7-zip. Download the special Java shared library for your system architecture to the same location from either Java (release) or Java (development). Copy the Example.java file to the same location. You will need to have a copy of some version of java.

When you are finished, you should have a folder layout something like

main
 |- CoolProp.dll
 |- Example.java
 |- platform-independent
    |- AbstractState.java
    |- Configuration.java
    |- ...

Usage

At the console, run:

javac *.java
java Example

There is example code at the end of this page

User-Compiled Binaries

Common Requirements

Compilation of the Java wrapper requires a few common wrapper pre-requisites

Linux & OSX

  1. Download a zip file of the Java Development Kit (JDK) for Java from Oracle downloads. If you are in a 32-bit system, download the 32-bit system, else download the 64-bit version.

  2. Expand the zip file you downloaded

  3. Add the bin folder of the JDK that you installed. For instance, add this:

    export /path/to/java/SDK/bin:$PATH
    
to ~/.profile where the path /path/to/java/SDK/bin points to the absolute path for the bin folder of your Java installation.

Windows

Download and run the JDK installer from Oracle downloads. If you are in a 32-bit system, download the 32-bit system, else download the 64-bit version.

Build

Linux and OSX

Once the dependencies are installed, you can run the builder and tests using:

# Check out the sources for CoolProp
git clone https://github.com/CoolProp/CoolProp --recursive
# Move into the folder you just created
mkdir -p  CoolProp/build && cd CoolProp/build
# Build the makefile using CMake
cmake .. -DCOOLPROP_JAVA_MODULE=ON -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Release
# Make the java files
cmake --build .
# Run the integration tests
ctest --extra-verbose

If you want to change the package that CoolProp resides in, you can do so by changing the cmake call to read:

cmake .. -DCOOLPROP_JAVA_MODULE=ON -DBUILD_TESTING=ON -DCOOLPROP_SWIG_OPTIONS="-package package.name"

where package.name is replaced with the desired name

Windows (32-bit and 64-bit)

You need to just slightly modify the building procedure:

# Check out the sources for CoolProp
git clone https://github.com/CoolProp/CoolProp --recursive
# Move into the folder you just created
cd CoolProp
# Make a build folder
mkdir build && cd build
# Build the makefile using CMake
cmake .. -DCOOLPROP_JAVA_MODULE=ON -DBUILD_TESTING=ON
# Make the Java shared library
cmake --build . --config Release (drop the --config Release if you use MinGW)
# Run the integration tests
ctest --extra-verbose

If you want to change the package that CoolProp resides in, you can do so by changing the cmake call to read:

cmake .. -DCOOLPROP_JAVA_MODULE=ON -DBUILD_TESTING=ON -DCOOLPROP_SWIG_OPTIONS="-package package.name"

where package.name is replaced with the desired name

Example Code

public class Example {
    static {
        System.loadLibrary("CoolProp");
    }

    public static void main(String argv[]){
        System.out.println("**************** INFORMATION ***************");
        System.out.println("This example was auto-generated by the language-agnostic dev/scripts/example_generator.py script written by Ian Bell");
        System.out.println("CoolProp version:" + " " + CoolProp.get_global_param_string("version"));
        System.out.println("CoolProp gitrevision:" + " " + CoolProp.get_global_param_string("gitrevision"));
        System.out.println("CoolProp Fluids:" + " " + CoolProp.get_global_param_string("FluidsList"));
        // See http://www.coolprop.org/coolprop/HighLevelAPI.html#table-of-string-inputs-to-propssi-function for a list of inputs to high-level interface;
        System.out.println("*********** HIGH LEVEL INTERFACE *****************");
        System.out.println("Critical temperature of water:" + " " + CoolProp.Props1SI("Water", "Tcrit") + " " + "K");
        System.out.println("Boiling temperature of water at 101325 Pa:" + " " + CoolProp.PropsSI("T", "P", 101325, "Q", 0, "Water") + " " + "K");
        System.out.println("Phase of water at 101325 Pa and 300 K:" + " " + CoolProp.PhaseSI("P", 101325, "T", 300, "Water"));
        System.out.println("c_p of water at 101325 Pa and 300 K:" + " " + CoolProp.PropsSI("C", "P", 101325, "T", 300, "Water") + " " + "J/kg/K");
        System.out.println("c_p of water (using derivatives) at 101325 Pa and 300 K:" + " " + CoolProp.PropsSI("d(H)/d(T)|P", "P", 101325, "T", 300, "Water") + " " + "J/kg/K");
        System.out.println("*********** HUMID AIR PROPERTIES *****************");
        System.out.println("Humidity ratio of 50% rel. hum. air at 300 K, 101325 Pa:" + " " + CoolProp.HAPropsSI("W", "T", 300, "P", 101325, "R", 0.5) + " " + "kg_w/kg_da");
        System.out.println("Relative humidity from last calculation:" + " " + CoolProp.HAPropsSI("R", "T", 300, "P", 101325, "W", CoolProp.HAPropsSI("W", "T", 300, "P", 101325, "R", 0.5)) + " " + "(fractional)");
        System.out.println("*********** INCOMPRESSIBLE FLUID AND BRINES *****************");
        System.out.println("Density of 50% (mass) ethylene glycol/water at 300 K, 101325 Pa:" + " " + CoolProp.PropsSI("D", "T", 300, "P", 101325, "INCOMP::MEG-50%") + " " + "kg/m^3");
        System.out.println("Viscosity of Therminol D12 at 350 K, 101325 Pa:" + " " + CoolProp.PropsSI("V", "T", 350, "P", 101325, "INCOMP::TD12") + " " + "Pa-s");
        // If you don't have REFPROP installed, disable the following lines;
        System.out.println("*********** REFPROP *****************");
        System.out.println("REFPROP version:" + " " + CoolProp.get_global_param_string("REFPROP_version"));
        System.out.println("Critical temperature of water:" + " " + CoolProp.Props1SI("REFPROP::Water", "Tcrit") + " " + "K");
        System.out.println("Boiling temperature of water at 101325 Pa:" + " " + CoolProp.PropsSI("T", "P", 101325, "Q", 0, "REFPROP::Water") + " " + "K");
        System.out.println("c_p of water at 101325 Pa and 300 K:" + " " + CoolProp.PropsSI("C", "P", 101325, "T", 300, "REFPROP::Water") + " " + "J/kg/K");
        System.out.println("*********** TABULAR BACKENDS *****************");
        AbstractState TAB = AbstractState.factory("BICUBIC&HEOS", "R245fa");
        TAB.update(input_pairs.PT_INPUTS, 101325, 300);
        System.out.println("Mass density of refrigerant R245fa at 300 K, 101325 Pa:" + " " + TAB.rhomass() + " " + "kg/m^3");
        System.out.println("*********** SATURATION DERIVATIVES (LOW-LEVEL INTERFACE) ***************");
        AbstractState AS_SAT = AbstractState.factory("HEOS", "R245fa");
        AS_SAT.update(input_pairs.PQ_INPUTS, 101325, 0);
        System.out.println("First saturation derivative:" + " " + AS_SAT.first_saturation_deriv(parameters.iP, parameters.iT) + " " + "Pa/K");
        System.out.println("*********** LOW-LEVEL INTERFACE *****************");
        AbstractState AS = AbstractState.factory("HEOS", "Water&Ethanol");
        DoubleVector z = new DoubleVector(); z.add(0.5); z.add(0.5);;
        AS.set_mole_fractions(z);
        AS.update(input_pairs.PQ_INPUTS, 101325, 1);
        System.out.println("Normal boiling point temperature of water and ethanol:" + " " + AS.T() + " " + "K");
        // If you don't have REFPROP installed, disable the following block;
        System.out.println("*********** LOW-LEVEL INTERFACE (REFPROP) *****************");
        AbstractState AS2 = AbstractState.factory("REFPROP", "Methane&Ethane");
        DoubleVector z2 = new DoubleVector(); z2.add(0.2); z2.add(0.8);;
        AS2.set_mole_fractions(z2);
        AS2.update(input_pairs.QT_INPUTS, 1, 120);
        System.out.println("Vapor molar density:" + " " + AS2.keyed_output(parameters.iDmolar) + " " + "mol/m^3");
    }
}

Example Code Output

**************** INFORMATION ***************
This example was auto-generated by the language-agnostic dev/scripts/example_generator.py script written by Ian Bell
CoolProp version: 6.1.0
CoolProp gitrevision: 7864c2614ce5a0ef972386ee7f39859f0d3f8038
CoolProp Fluids: 1-Butene,Acetone,Air,Ammonia,Argon,Benzene,CarbonDioxide,CarbonMonoxide,CarbonylSulfide,cis-2-Butene,CycloHexane,Cyclopentane,CycloPropane,D4,D5,D6,Deuterium,Dichloroethane,DiethylEther,DimethylCarbonate,DimethylEther,Ethane,Ethanol,EthylBenzene,Ethylene,EthyleneOxide,Fluorine,HeavyWater,Helium,HFE143m,Hydrogen,HydrogenChloride,HydrogenSulfide,IsoButane,IsoButene,Isohexane,Isopentane,Krypton,m-Xylene,MD2M,MD3M,MD4M,MDM,Methane,Methanol,MethylLinoleate,MethylLinolenate,MethylOleate,MethylPalmitate,MethylStearate,MM,n-Butane,n-Decane,n-Dodecane,n-Heptane,n-Hexane,n-Nonane,n-Octane,n-Pentane,n-Propane,n-Undecane,Neon,Neopentane,Nitrogen,NitrousOxide,Novec649,o-Xylene,OrthoDeuterium,OrthoHydrogen,Oxygen,p-Xylene,ParaDeuterium,ParaHydrogen,Propylene,Propyne,R11,R113,R114,R115,R116,R12,R123,R1233zd(E),R1234yf,R1234ze(E),R1234ze(Z),R124,R125,R13,R134a,R13I1,R14,R141b,R142b,R143a,R152A,R161,R21,R218,R22,R227EA,R23,R236EA,R236FA,R245ca,R245fa,R32,R365MFC,R40,R404A,R407C,R41,R410A,R507A,RC318,SES36,SulfurDioxide,SulfurHexafluoride,Toluene,trans-2-Butene,Water,Xenon
*********** HIGH LEVEL INTERFACE *****************
Critical temperature of water: 647.096 K
Boiling temperature of water at 101325 Pa: 373.1242958476844 K
Phase of water at 101325 Pa and 300 K: liquid
c_p of water at 101325 Pa and 300 K: 4180.6357765560715 J/kg/K
c_p of water (using derivatives) at 101325 Pa and 300 K: 4180.6357765560715 J/kg/K
*********** HUMID AIR PROPERTIES *****************
Humidity ratio of 50% rel. hum. air at 300 K, 101325 Pa: 0.011095529705199761 kg_w/kg_da
Relative humidity from last calculation: 0.5 (fractional)
*********** INCOMPRESSIBLE FLUID AND BRINES *****************
Density of 50% (mass) ethylene glycol/water at 300 K, 101325 Pa: 1061.1793077204613 kg/m^3
Viscosity of Therminol D12 at 350 K, 101325 Pa: 5.228837990955358E-4 Pa-s
*********** REFPROP *****************
REFPROP version: 9.1.1.10
Critical temperature of water: 647.096 K
Boiling temperature of water at 101325 Pa: 373.1242958476988 K
c_p of water at 101325 Pa and 300 K: 4180.635776577876 J/kg/K
*********** TABULAR BACKENDS *****************
Mass density of refrigerant R245fa at 300 K, 101325 Pa: 5.648128257046375 kg/m^3
*********** SATURATION DERIVATIVES (LOW-LEVEL INTERFACE) ***************
First saturation derivative: 4058.5197550507155 Pa/K
*********** LOW-LEVEL INTERFACE *****************
Normal boiling point temperature of water and ethanol: 357.2729801723433 K
*********** LOW-LEVEL INTERFACE (REFPROP) *****************
Vapor molar density: 0.44146562515945176 mol/m^3