K2 Programming Language

A modern, high-performance language designed for building everything from system utilities to web applications.

hello.k2
// Hello World in K2
function main() {
    print("Hello, World!");
    
    // Variables
    var name = "K2";
    var version = 2.0;
    
    print("Welcome to " + name + " " + version);
    
    // Arrays
    var languages = ["K2", "Python", "JavaScript"];
    for (var i = 0; i < languages.length; i++) {
        print("I love " + languages[i]);
    }
    
    return 0;
}

Key Features

High Performance

K2 is designed for speed with a highly optimized runtime and efficient memory management.

Lightweight

The entire K2 runtime is less than 1MB, making it perfect for embedded systems and microservices.

Clean Syntax

K2's syntax is designed to be familiar to developers coming from C-like languages while removing unnecessary complexity.

Memory Safe

K2's memory management prevents common bugs like buffer overflows and memory leaks.

Extensible

Easily extend K2 with modules written in K2, C, or any language that supports C ABI.

Cross-Platform

K2 runs on Windows, macOS, Linux, and embedded platforms with consistent behavior.

Performance

K2 is designed for high performance across a wide range of workloads.

Benchmark: Fibonacci Sequence (n=40)

K2
0.8s
Python
2.7s
JavaScript
1.6s
Ruby
2.3s

Benchmark: JSON Parsing (10MB file)

K2
0.3s
Python
0.9s
JavaScript
0.5s
Ruby
1.2s
Benchmark K2 Python JavaScript Ruby
Binary Tree 1.2s 3.5s 2.1s 4.2s
Regex 0.4s 0.9s 0.6s 1.3s
Matrix Mult. 0.7s 2.2s 1.5s 2.8s
File I/O 0.3s 0.8s 0.7s 1.1s

Code Examples

K2's clean syntax makes it easy to write and understand code.

hello.k2
// Hello World in K2
function main() {
    print("Hello, World!");
    return 0;
}
fibonacci.k2
// Fibonacci sequence in K2
function fibonacci(n) {
    if (n <= 1) {
        return n;
    }
    return fibonacci(n - 1) + fibonacci(n - 2);
}

function main() {
    for (var i = 0; i < 10; i++) {
        print("Fibonacci(" + i + ") = " + fibonacci(i));
    }
    return 0;
}
webserver.k2
// Simple web server in K2
import http

function handleRequest(request, response) {
    response.setHeader("Content-Type", "text/html");
    response.write("<html><body>");
    response.write("<h1>Hello from K2!</h1>");
    response.write("<p>You requested: " + request.url + "</p>");
    response.write("</body></html>");
    response.end();
}

function main() {
    var server = http.createServer(handleRequest);
    server.listen(8080);
    print("Server running at http://localhost:8080/");
    return 0;
}
gui.k2
// Simple GUI application in K2
import gui

function main() {
    var window = gui.createWindow("K2 GUI Example", 400, 300);
    
    var button = gui.createButton("Click Me!", 150, 120, 100, 30);
    button.onClick(function() {
        gui.showMessage("Hello!", "You clicked the button!");
    });
    
    window.add(button);
    window.show();
    
    gui.runMainLoop();
    return 0;
}

Nahir UI Framework

Experience the next generation of K2 programming with our new Nahir UI framework.

Accelerated Rendering

Nahir UI components render in microseconds, providing instant visual feedback and smooth animations.

Component System

Build complex interfaces with reusable, composable components that maintain K2's performance benefits.

Ramdisk Caching

Utilizes the new K2 ramdisk cache system for ultra-fast component state management and rendering.

Responsive Design

Automatically adapts to any screen size with zero performance penalty, perfect for mobile applications.

nahir-example.k2
// Nahir UI Example
import nahir

function main() {
    // Create a new Nahir application
    var app = nahir.createApp("My Nahir App");
    
    // Define the app state
    var state = {
        counter: 0,
        theme: "light"
    };
    
    // Create a component
    var counterComponent = nahir.component("counter", function(props) {
        return nahir.div({ class: "counter-container" }, [
            nahir.h2({}, "Counter: " + props.value),
            nahir.button({
                onClick: function() { props.onIncrement(); }
            }, "Increment"),
            nahir.button({
                onClick: function() { props.onReset(); }
            }, "Reset")
        ]);
    });
    
    // Render the application
    app.render(function() {
        return nahir.div({ class: "app" }, [
            nahir.h1({}, "Nahir UI Example"),
            counterComponent({
                value: state.counter,
                onIncrement: function() { state.counter++; },
                onReset: function() { state.counter = 0; }
            }),
            nahir.button({
                onClick: function() {
                    state.theme = state.theme === "light" ? "dark" : "light";
                    document.body.className = state.theme;
                }
            }, "Toggle Theme")
        ]);
    });
    
    // Start the application
    app.mount("#app");
}

Nahir UI Example

Counter: 0

Download K2

Source Code

Get the latest source code from GitHub

Download Source

Windows Installer

Windows 10/11 installer with GUI support

Download Installer

Linux Package

Debian/Ubuntu/Kali Linux package

Download .deb

Binary Release

Pre-compiled binary for Linux x86_64

Download Binary

K2 Turbo

High-performance K2 interpreter

Download Turbo

Documentation

Complete K2 language documentation

View Documentation

Example Programs

Collection of K2 example programs

Download Examples