Home » Home » Writing your first Java program

Writing your first Java program can be a daunting task, but with the right guidance and resources, it can be a fun and rewarding experience. Java is one of the most popular programming languages, used in everything from web development to mobile apps and even in large-scale enterprise applications. In this article, we’ll provide a step-by-step guide on how to write your first Java program.

Read Also-Setting up Java development environment

Step 1: Install Java Development Kit (JDK)

Before you start coding, you’ll need to install the Java Development Kit (JDK) on your computer. The JDK is a software development environment for Java that includes the Java Runtime Environment (JRE), Java compiler, and other development tools. You can download the latest version of the JDK from the official Oracle website.

Step 2: Choose a Text Editor

Once you’ve installed the JDK, you’ll need to choose a text editor to write your code in. There are many popular text editors available, including Eclipse, IntelliJ IDEA, and NetBeans. However, if you’re just starting out, you can use a simple text editor like Notepad or TextEdit.

Step 3: Write Your First Java Program

Now that you have your tools set up, it’s time to write your first Java program. Open your text editor and create a new file. In this file, you’ll write your code. Here’s a simple “Hello, World!” program that you can use as a starting point:

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

This program prints the message “Hello, World!” to the console.

Step 4: Save Your Program

After you’ve written your code, save your program with a .java extension. For example, you can save your “Hello, World!” program as HelloWorld.java.

Step 5: Compile Your Program

To run your Java program, you’ll need to compile it first. Open a command prompt or terminal window and navigate to the directory where you saved your program. Then, enter the following command:

javac HelloWorld.java

This will compile your program and create a new file called HelloWorld.class.

Step 6: Run Your Program

Finally, it’s time to run your program. In the same command prompt or terminal window, enter the following command:

java HelloWorld

This will execute your program and print the message “Hello, World!” to the console.

Congratulations! You’ve just written and executed your first Java program.


Writing your first Java program can seem intimidating, but with the right tools and guidance, it can be a straightforward process. By following the steps outlined in this article, you’ll have a solid foundation to build on as you continue to learn and explore the world of Java programming

Related Posts

One thought on “Writing your first Java program

Leave a Reply

%d bloggers like this: