Fundamentals 12 min read

How to Build Your First Java Application from Scratch

This tutorial walks you through installing the JDK, creating a HelloJava.java source file with Notepad, compiling it using javac, running it with the java interpreter, and explains the basic structure, comments, class definition, and main method of a Java program.

Lisa Notes
Lisa Notes
Lisa Notes
How to Build Your First Java Application from Scratch

This guide assumes the JDK is already installed and the Java environment variables are configured.

1. Create the source file

Open Windows Notepad, type the following code, and save it as HelloJava.java in a folder such as D:\examples\java01 using the ANSI encoding and the Text Document (*.txt) type.

// HelloJava.java – a simple program that prints a greeting
public class HelloJava {
    public static void main(String[] args) {
        System.out.println("Hello Java!");
    }
}

2. Compile the source file

Open a Command Prompt, change to the directory containing the source file, and run: javac HelloJava.java This creates a HelloJava.class byte‑code file that the JVM can execute.

3. Run the program

In the same command window, execute: java HelloJava The output should be: Hello Java! If you see this message, your first Java application works correctly.

4. Basic structure of a Java program

A Java source file typically contains three parts:

Comments – ignored by the compiler but useful for documentation.

Class definition – the HelloJava class in this example.

main() method – the entry point of every Java application.

4.1 Types of comments

Single‑line comment : starts with // and continues to the end of the line.

Multi‑line comment : starts with /* and ends with */. Useful for longer explanations.

Documentation comment : starts with /** and ends with */. Tools like Javadoc can generate HTML documentation from these.

4.2 Class definition

The keyword class defines a class. In this example the class is declared as public class HelloJava. Only one public class may exist per source file, and the file name must match the public class name.

4.3 main() method

The signature public static void main(String[] args) is fixed; it tells the JVM where to start execution. The method body (enclosed in braces) contains the statements that run when the program starts.

5. Additional notes

The order of the modifiers public and static does not matter, but the conventional order is public static.

The main() method must be followed by a pair of braces; the code inside is the method body.

Every Java program must contain exactly one class with a main() method to be executable.

Output is performed via the System.out.println call, which writes to the standard console.

By following these steps you have created, compiled, and executed a minimal Java application and learned the essential components of a Java source file.

JavaCompilationJDKcommentsCommandLineHelloWorldMainMethod
Lisa Notes
Written by

Lisa Notes

Lisa's notes: musings on daily life, work, study, personal growth, and casual reflections.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.