JAVA Say’s Hello!

Astha Chauhan
3 min readMay 30, 2021

Finally, you decided to learn Java after juggling through various programming languages for God knows how long, I know “Been there, done that” it’s not easy to choose a language but it’s all cool now since you are here.

Now let's start with a tinnie tiny program of making Java say “Hello World!!”

Java has a lot of rules which we will keep discussing while going down the path, keep taking notes as these rules are what make Java “The Best”.

Unsaved Java Program of Hello World on Eclipse IDE

#Rule-1

A Java Program will always consist of a “class” whose name must be the same as the filename which in this case is Main.java where .java is an extension used for saving Java Programs.

  • Java is a case-sensitive language, therefore “MyClass” and “myclass” have different meanings.
  • I personally use Eclipse for making Java Programs, but you are free to choose any IDE that works best for you.
  • Let’s break down this code and understand it bit by bit.
  • #1st Line → public class Main → This line uses keyword class to declare that a new class is being defined, where Main is an identifier i.e. the name of the class.
  • Definition of the class would lie between the opening “{” and closing braces “}”.
  • #2nd Line public static void main(String[] args) → It begins the main method which is a must to have in every Java Program, this line initiates the execution of the program.

→ Public, we have already discussed this in brief, let’s talk about “static” which is a keyword which when applied makes any method static.

Cool, but why do we use it?? one might ask.

Good question, Allow me to tell you… well, when using a static method it’s not required to create an object in order to invoke the method, therefore, saving our precious memory.

void is the return type of the method which means the method does not return any value.

String[] args declares a parameter args, which is an array of instances of the class string. Here, args receives any command-line arguments present when the program is executed.

  • #3 Line System.out.println(“Hello World!!”) → This line uses the built-in method println() which outputs the string “Hello World!!”.

This line initiates with System.out which we will cover later but as of now let’s say System is a predefined class that provides access to the system and out is the output stream that is connected to the console.

In order to run the program, 1 method is to right-click on the program, select Run as then click on 1 Java Application as shown below:

Running the program in Eclipse IDE

After compiling, the output would be like this:

Compiled Java code in Eclipse IDE

GREAT!! Our 1st program compiled successfully

You deserve a pat on your back mate!!

You just did an awesome start!! Let’s not stop now..

Things too complicated to be discussed here will be discussed in upcoming blogs in greater detail, no worries, expect more.

More Blogs Coming Your Way!!!

Signing off,

Astha Chauhan

--

--