> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-framework/module-development/capabilities/bifs.md).

# BIFs

BIFs are custom functions that extend BoxLang's built-in function library. Create them in **pure BoxLang** or **Java**.

{% tabs %}
{% tab title="🟦 BoxLang BIFs" %}
Place `.bx` files in your module's `bifs/` folder. They are auto-discovered and compiled at runtime.

**File:** `bifs/Greet.bx`

```js
/**
 * Returns a greeting message
 *
 * @param name The name to greet (required)
 * @param greeting The greeting prefix (default: "Hello")
 *
 * @return The formatted greeting string
 */
function invoke(
    required string name,
    string greeting = "Hello"
) {
    return "#greeting#, #name#!"
}
```

**Usage from BoxLang:**

```js
result = greet( "World" )
// → "Hello, World!"

result = greet( name = "World", greeting = "Hi" )
// → "Hi, World!"
```

**Features:**

* ✅ No compilation — just create the file
* ✅ Auto-discovered by folder scanning
* ✅ Supports `@BoxMember` annotation for member methods
* ✅ Full access to BoxLang runtime via injected services
  {% endtab %}

{% tab title="☕ Java BIFs" %}
Extend the `BIF` class and annotate with `@BoxBIF`. Registered via ServiceLoader.

**File:** `src/main/java/ortus/boxlang/modules/mymodule/bifs/Greet.java`

```java
import ortus.boxlang.runtime.bifs.BIF;
import ortus.boxlang.runtime.bifs.BoxBIF;
import ortus.boxlang.runtime.bifs.BoxMember;
import ortus.boxlang.runtime.context.IBoxContext;
import ortus.boxlang.runtime.scopes.ArgumentsScope;
import ortus.boxlang.runtime.scopes.Key;
import ortus.boxlang.runtime.types.Argument;
import ortus.boxlang.runtime.types.BoxLangType;

@BoxBIF
@BoxMember( type = BoxLangType.STRING )
public class Greet extends BIF {

    public Greet() {
        declaredArguments = new Argument[] {
            new Argument( true, Argument.STRING, Key.name ),
            new Argument( false, Argument.STRING, Key.greeting, "Hello" )
        };
    }

    @Override
    public Object _invoke( IBoxContext context, ArgumentsScope arguments ) {
        String name     = arguments.getAsString( Key.name );
        String greeting = arguments.getAsString( Key.greeting );
        return greeting + ", " + name + "!";
    }
}
```

**ServiceLoader Config:** `src/main/resources/META-INF/services/ortus.boxlang.runtime.bifs.BIF`

```
ortus.boxlang.modules.mymodule.bifs.Greet
```

**Features:**

* ✅ Compiled performance — no runtime compilation
* ✅ Full Java ecosystem access
* ✅ Better IDE tooling and type safety
* ✅ Can implement complex Java interfaces
  {% endtab %}
  {% endtabs %}

## Member Functions

Register BIFs as member methods on BoxLang types:

{% tabs %}
{% tab title="BoxLang" %}

```js
/**
 * @BoxMember string
 */
function shout( required string text ) {
    return text.ucase() & "!!!"
}
```

Usage: `"hello".shout()` → `"HELLO!!!"`
{% endtab %}

{% tab title="Java" %}

```java
@BoxBIF
@BoxMember( type = BoxLangType.STRING )
public class StringShout extends BIF {
    // ... implementation
}
```

Usage: `"hello".shout()` → `"HELLO!!!"`
{% endtab %}
{% endtabs %}

## When to Use Which

| Criteria          | BoxLang BIFs        | Java BIFs          |
| ----------------- | ------------------- | ------------------ |
| Complexity        | Simple logic        | Complex algorithms |
| Performance       | Good for most cases | Critical paths     |
| Dependencies      | None or minimal     | External JARs      |
| Development speed | Fast iteration      | Requires rebuild   |
| Team skills       | BoxLang developers  | Java developers    |

## Next Steps

* [Components](/boxlang-framework/module-development/capabilities/components.md) — Create custom BoxLang tags
* [Interceptors](/boxlang-framework/module-development/capabilities/interceptors.md) — Listen to runtime events
* [Services](/boxlang-framework/module-development/capabilities/services.md) — Global runtime services (Java only)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://boxlang.ortusbooks.com/boxlang-framework/module-development/capabilities/bifs.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
