Java web app tutorial for beginners: build your first app

You know some Java, you have written console programs or a few classes, and now you want to see something running in a browser. Most guides at this point throw HTML, JavaScript, a template engine and a build pipeline at you before the first page shows up.
This java web app tutorial for beginners takes a shorter path. With webforJ, a full-stack Java framework, you build the page in Java, generate a working project in a minute and run it with one Maven command. By the end you will have a first Java web app on screen, a button that reacts to clicks, and a clear idea of where to go next.
What you need before you start
Two tools are enough:
- A JDK, version 21 or higher.
- Maven, to build and run the project.
Run java -version and mvn -v in a terminal to check both. If one is missing, the prerequisites page lists where to download each and how to install them. Any editor with Java support works, such as IntelliJ IDEA or Visual Studio Code.
You do not need to know HTML, CSS or JavaScript to follow along.
Step 1: Generate the project
The quickest way to make a website with Java is to let a generator create the skeleton. Open startforJ in your browser and fill in a few fields:
- Give the app a name, a group ID and an artifact ID.
- Pick the HelloWorld archetype. It is the starter made for beginners.
- Leave Runs on at its default, the servlet container.
- Download the ZIP and open the folder in your editor.
Prefer the terminal? The getting started page also shows the Maven command that generates the same project. The HelloWorld archetype page describes what the starter contains.
Step 2: Start the app
Open a terminal in the project folder, the one that holds pom.xml, and run:
mvn
A generated project sets its default Maven goal, so plain mvn compiles the code and serves the app on an embedded Jetty server. If you want the explicit form, mvn jetty:run starts the same server. The Jetty page explains what each part does.
Open the address the console prints and you will see a text field and a button. That is a working first Java web app, and you have not written a line yet.
Step 3: Read the entry class
Every webforJ app has one class that extends App. In the starter it is called Application:
@Routify(packages = "com.samples.views")
@AppTitle("webforJ Hello World")
@StyleSheet("ws://app.css")
public class Application extends App {
}
The class body is empty because the annotations do the work:
@Routifytells webforJ which package holds your views.@AppTitlesets the title on the browser tab.@StyleSheetlinks a CSS file for custom styling.
Change the @AppTitle text, save, and reload the page to see the tab title change. Small edits like this are the fastest way to learn what each piece does.
Step 4: Read the first view
The page you saw in the browser comes from a view class. A view is a normal Java class that builds its UI with components:
@Route("/")
public class HelloWorldView extends Composite<FlexLayout> {
private final FlexLayout self = getBoundComponent();
private TextField hello = new TextField("What is your name?");
private Button btn = new Button("Say Hello");
public HelloWorldView(){
self.setDirection(FlexDirection.COLUMN);
self.setMaxWidth(300);
self.setStyle("margin", "1em auto");
btn.setTheme(ButtonTheme.PRIMARY)
.addClickListener(e ->
Toast.show("Welcome to webforJ Starter " + hello.getValue() + "!", Theme.GRAY));
self.add(hello, btn);
}
}
Take it in small pieces:
@Route("/")maps this class to the home URL.Composite<FlexLayout>makes the class a reusable component built around a layout.getBoundComponent()gives you that layout.TextFieldandButtonare webforJ components. You create them withnew, like any Java object.self.add(hello, btn)puts them on the page.
The layout, the field and the button all live in one Java file. No template sits next to it and no second language is involved. The app basics page walks through both classes in more detail.
Step 5: Handle a button click
Look at the middle of the constructor. The button gets a click listener with addClickListener, and the listener shows a toast that reads the text field with hello.getValue().
Here is what happens when you click:
- The browser reports the click to your Java code.
- Your lambda runs on the server, in Java.
- The lambda reads the field's value and shows the toast.
You never write a fetch call or an endpoint. The event handler is plain Java, so you can use the debugger, set breakpoints and reuse your own classes inside it.
Try changing the message in the lambda, or change the button label in the Button constructor. Reload and click. Each change takes seconds, which is the point of starting with a tiny app.
Step 6: Add a second page
A real app has more than one page. Each view class carries its own @Route, and @Routify finds them in the views package. To add a page, create another class next to the first, give it a different route such as @Route("about"), and build its content the same way.
Routes also support parameters, nesting and navigation guards when your app grows. The routing overview covers them.
What to build after this
This small Java web example has the shape of every webforJ app: one entry class, any number of views, components added in Java and events handled in Java. From here, pick the direction that matches what you want to build:
| You want to | Read |
|---|---|
| Add more pages and links between them | Routing |
| See every ready-made component | UI components |
| Go deeper on the button you just used | Button |
When you are ready for a longer build, the documentation also has a step-by-step tutorial that grows a customer management app, starting from project setup.
Next step
Generate your own project at startforJ, run mvn, and change one thing in the first view. Then follow the getting started guide for the remaining options.
Frequently asked questions
Do I need to learn JavaScript to build a Java web app?
No. In webforJ you write the UI, the layout and the event handling in Java. The browser side is handled by the framework, so a beginner can stay in one language from the first view to a finished app.
What is the simplest way to make a website with Java?
Generate a project with startforJ, run mvn and edit the starter view. That gives you a running page in minutes, with routing and components already in place, and you grow it one view at a time.
Which Java version and build tool does a first Java web app need?
Java 21 or higher and Maven. Archetypes generate Maven projects, and an existing Gradle build also works. The prerequisites page lists the download links and the commands to check your setup.
Entwickelst du etwas mit webforJ?
Sprechen Sie mit dem Team über Ihr Projekt, eine Migration oder ob webforJ das Richtige für Sie ist.



