How To Code Hello World In Java

Here’s an example of programming Hello World in java. A Hello World program is usually one of the first programs that is written by someone new to software development or new to programming in a particular language. 


This is a common simple program and is used to show the most basic implementation and structure of a program that is possible in a language. All that a Hello World program will do is start the program and then print Hello World to the screen.

A Simple Hello World Program

Here’s a Hello World program in java below. Let’s break down what’s going on here.

Java Class Declaration

The first line defines the class. Java is an object oriented programming language, and in the java implementation of object oriented program languages there are some rules

  1. All code should be in a class.
  2. The code should be in a class where the first class is the same as the filename prefix.
  3. So the line below tells java we are creating a class called HelloWorld.

Why We Need A Public Static Void Main In Java

The next lines defines the entry point to call the code from the java virtual machine (that runs the code). When this code is called from the JVM it will look for number of things.

  1. There must be a method called main.
  2. That method must be static so that it can be accessed at the class level (java can run static methods at the class or instance level, but not static methods can only be run by creating an instance of a class.
  3. It must have a void return type and accept a string array as input parameters.

Print Hello World

The next line is the action we want to take when this method is called. In this case it’s very simple and we want to print a line saying “Hello World” to the console.

Leave a Comment

Your email address will not be published. Required fields are marked *