Welcome to Oorian, the Java web framework that lets you build modern, real-time web applications entirely in Java. If you're coming from Swing, JavaFX, or server-side frameworks like Spring MVC, you'll find Oorian's approach refreshingly familiar yet powerfully different.
What Makes Oorian Different?
Unlike traditional web frameworks that require you to write HTML templates, JavaScript, and manage complex build pipelines, Oorian lets you construct your entire UI programmatically in Java. Every HTML element is a first-class Java object with type-safe properties and methods.
Setting Up Your First Project
Let's create a simple "Hello World" application to understand Oorian's core concepts.
Step 1: Create Your Application Class
@WebListener
public class MyApplication extends Application
{
@Override
protected void registerPackages()
{
registerPackage("com.mycompany.myapp");
}
}
The @WebListener annotation tells your servlet container to initialize Oorian when your application starts. The registerPackage method tells Oorian where to find your page classes.
Step 2: Create Your First Page
@Page("/hello")
public class HelloPage extends HtmlPage
{
@Override
protected void createHead(Head head)
{
head.setTitle("Hello Oorian");
}
@Override
protected void createBody(Body body)
{
H1 heading = new H1();
heading.setText("Hello, Oorian!");
heading.setColor("#2563eb");
body.addElement(heading);
P paragraph = new P();
paragraph.setText("Welcome to your first Oorian application.");
body.addElement(paragraph);
}
}
Understanding the Element Model
In Oorian, every HTML element has a corresponding Java class. These aren't just wrappers—they're full-featured objects with:
- Type-safe properties:
setColor(),setFontSize(),setPadding() - Fluent API: Chain method calls for clean, readable code
- IDE support: Full autocomplete and refactoring capabilities
Adding Interactivity
Let's add a button that responds to clicks:
@Page("/interactive")
public class InteractivePage extends HtmlPage implements MouseClickListener
{
private P messageDisplay;
@Override
protected void createBody(Body body)
{
Button button = new Button("Click Me!");
button.registerListener(this, MouseClickedEvent.class);
body.addElement(button);
messageDisplay = new P();
messageDisplay.setText("No clicks yet.");
body.addElement(messageDisplay);
}
@Override
public void onEvent(MouseClickedEvent event)
{
messageDisplay.setText("Button clicked at " + new Date());
}
}
Notice how event handling works exactly like Swing or JavaFX—implement a listener interface and register for events. When the user clicks the button in their browser, your Java code on the server handles the event and updates the UI.
Choosing Your Communication Mode
Oorian supports three communication modes: AJAX, SSE (Server-Sent Events), and WebSocket. Here's the important part: you don't need to understand how any of these technologies work. Oorian completely hides the implementation details. You write the same Java code regardless of which mode you choose—the framework handles all the underlying communication.
What you do need to understand is when to use each mode:
- AJAX: Simple request-response. Good for basic forms and interactions where the server only responds to user actions.
- SSE (Server-Sent Events): The server can push updates to the browser at any time. Perfect for dashboards, notifications, and live data. This is the default and recommended mode.
- WebSocket: Full bidirectional real-time communication. Best for chat applications, collaborative editing, or when you need the absolute lowest latency.
You can set the communication mode at the application level (affecting all pages) or override it for specific pages:
// Set default for entire application
public class MyApplication extends Application
{
@Override
protected Communication getDefaultCommunication()
{
return Communication.SSE; // Already the default
}
}
// Override for a specific page
@Page(value = "/chat", communication = Communication.WEBSOCKET)
public class ChatPage extends HtmlPage { }
For most applications, the default SSE mode works perfectly. It gives you server push capabilities with excellent browser support and simpler infrastructure requirements than WebSocket.
Next Steps
You've just scratched the surface of what Oorian can do. In upcoming tutorials, we'll explore form handling, integrating UI libraries like SyncFusion and Chart.js, and building complete applications. Welcome to a better way to build Java web applications!