Create your First Program in Java

To write code in Java, you must first have JDK (Java Development Kit) and a Java Development IDE such as Eclipse or NetBeans, installed on your computer. If you do not have these then please go ahead and install them first.

To create a program in Java, follow these steps:

  • Launch Eclipse: Open Eclipse by double-clicking on the Eclipse icon or running the application from the installed location.
  • Create a new Java project: Click on "File" in the menu bar, then select "New" and choose "Java Project". Enter a name for your project, such as "MyFirstProject", and click "Finish".
  • Create a new Java class: Right-click on the newly created project in the "Package Explorer" (left sidebar) and select "New" -> "Class". Enter a name for your class, such as "MyExample", and make sure to check the "public static void main(String[] args)" option. Click "Finish". For example:

  • Write the Java code: Inside the newly created class, you will see the main method automatically generated. Add your Java code within the body of the main method. For example, you can use the following code to print "Hello World" to the console:
package example.test;

public class MyExample {

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

  • Save the file: After writing your code, save the file by clicking on "File" -> "Save" or using the Ctrl + S (Cmd + S on macOS) shortcut.
  • Run the program: To run the program, right-click on the Java file in the "Package Explorer" and select "Run As" -> "Java Application". You should see the output "Hello, World" printed in the Eclipse console.

Congratulations! You have created and executed your first Java program. You can modify and experiment with the code to further explore Java programming.