DEV Community

Cover image for 3. Exercise: Write, compile and run a Java program
Raghav Khanna
Raghav Khanna

Posted on

1 1

3. Exercise: Write, compile and run a Java program

3.1. Write source code
The following Java program is developed under Linux using a text editor and the command line. The process on other operating system should be similar, but is not covered in this description.

Select or create a new directory which will be used for your Java development. In this description the path \home\vogella\javastarter is used. On Microsoft Windows you might want to use c:\temp\javastarter. This path is called javadir in the following description.

Open a text editor which supports plain text, e.g., gedit under Linux or Notepad under Windows and write the following source code.

// a small Java program
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}

Save the source code in your javadir directory with the HelloWorld.java filename. The name of a Java source file must always equal the class name (within the source code) and end with the .java extension. In this example the filename must be HelloWorld.java, because the class is called HelloWorld

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more