Compiling and running a Java program


Saturday, November 25, 2023

Compiling a Java Program

You can use any text editor, from Windows Notepad to more advanced ones like Notepad++ or Visual Studio Code.

You can also use integrated development environments like Eclipse or NetBeans to develop Java programs.

Create a new file named HelloWorld.java and write the following code:

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello world");
    }
}

Open a console and run the following command to compile a .java file into a .class file that will be executed on the Java virtual machine:

javac HelloWorld.java

A .class file is generated, which will be executed on the Java virtual machine:

Running a Java Program

To run the program, you just need to execute the following command using the .class file generated in the previous step:

java HelloWorld

Share it

Share it on your social media and challenge your friends to solve programming problems. Together, we can learn and grow.

Copied

The code has been successfully copied to the clipboard.

More Exercises

Continue improving your Java programming skills with our selection of practical exercises from the lesson. Click on Practice and challenge your knowledge!

1

History of Java

Explore the history of Java, an innovative programming language that revolutionized computing. From its creation in the '90s to its current impact.

Introduction to Java

Know the features of the language and prepare the necessary tools to create the first program with Java.

Fundamentals concepts
Practice exercises

Keep learning

C# Programming Course

Free programming course with practical exercises and solutions in C#. Start learning right now!

CookieOwn and third party cookies to improve our services. If you go on surfing, we will consider you accepting its use.