Getting Started

This page is intended to help you get started using Expr4j.
You can raise issues and ask questions on Github, but please read this page first before doing so.



Latest versions of Expr4j can be found on Maven Central and Github.

The Java Docs can be found in the maven distributable or online here. You can browse the source here.

All binaries builds posted on Maven Central and Github are compiled under Java 1.8 and have no dependencies.

Adding to Classpath




Command Line

The Basics


Following are some of the most commonly used imports for Expr4j:

Evaluating Expressions

Following code is the simplest way to use Expr4j library for evaluating an expression string. It uses the Dual Stack implementation of Shunting Yard by default.

You can specify which implementation of ShuntingYard to use in the following manner:

Adding User Defined Functions

You can define your own functions in the following manner:

Functions names can consist of uppercase letters, lowercase letters, and digits. However, first character must not be a digit.
You cannot override pre-defined functions.

Removing User Defined Functions

You can remove any functions you have defined in the following manner:

You cannot remove pre-defined functions.

Supported Operators and Functions

You can see the list of operators and functions supported by the latest version at Github Supported Operators page.

Alternatively, you can see the list of operators and functions supported by your environment (including user defined functions) using the code below:


There are a number of scenarios where Expr4jException are thrown. Expr4jException is a sub-class of RuntimeException.

Exceptions like these are typically thrown when the evaluation of the expression has failed due to an incorrect expression string. They can also be thrown while defining a function or trying to remove one.

All exceptions are unchecked. However, it is recommended that you handle Expr4jException if using in production.