Write Hello World program in JAVA

0
881

Whatever scripting language you learn, the first program you will execute is Hello world program using that technology. It is a kind of tradition in your programming world, Am I correct? I still remember my college days where the first program I learned was Hello world in Java. Let me add one more point, it took me around 1 week to execute it correctly. Initially it was a tough task but once I cleared my concepts, it was as easy as liking your Facebook friend’s photo. Stick with me for Java Tutorials and I will guide you with steps you need to take care about. I will try to make these complex things simplify for you. In this tutorial, we are going to show you how to write your first program Hello World in Java programming language. You can use any of the IDE (Integrated Development Environment) to write your Java code.

  1. Eclipse – Download Eclipse from ME
  2. Netbeans – Downloas Netbeans from ME
  3. JCreator – Download JCreator from ME
  4. BlueJ – Download BlueJ from ME
  5. JDeveloper – Download JDeveloper from ME
  6. Simple text editor, etc.

Watch Hello World on YouTube

For this tutorial, I am using Netbeans IDE 7.2.1. Netbeans IDE is used for commercial as well as personal use. It has a built-in GUI builder with a support for additional plug-ins to extend your developing needs.

Netbeans IDE to write Hello world program in Java

Steps to Write your First JAVA program

Step 1 :  Create your new Application.

  • Click on the New Project under the File menu.

In NetBeans, Open new Project under File menu

  • Choose the ‘Java Application‘ under the category ‘Java‘ and click on Next.

Choose Java Application under Java category

  • Now, give any desired Project name (e.g – FirstPhpRingApp) and click on Finish.

Add Project Name to your New Java application

  • Congratulations Genius!!! Your empty project is created. Follow below steps to learn How to Write Hello world program in Java and How to execute the program in Java.

Empty Java project created in Netbeans

Step 2 :  Writing code in your Main class

  • Expand your project tree in the Project Explorer and locate the Main class (FirstPhpRingApp.java) under the default package folder.

Package explorer in NetBeans

  • Double click on the class and you will be able to access its source code.

Double click on Main class to access Source code

  • public static void main(String[] args) {}   is the main method of the class. When you execute the Java class with the Java Interpreter, run-time system starts by calling the class’s main method. This main method, then calls the other methods as required to run the Java application.
  1. public – It is an access specifier. It means that anyone can access it and here anyone means JVM ( Java Virtual Machine).
  2. static – It means that you can run this method without creating an instance of Main class, since it belongs to main class and not its object.
  3. void – It is a return type. Since, we are not returning anything hence void.
  4. main – It is the name of the method.
  5. arguments – These are what we get inside the method when we run the program.

Write the following code in the main method of your Java Program for printing the “Hello World!” text.

Write system.out.println (''Hello World'') in main class

Step 3 : Executing “Hello World” program

  • You can execute your Hello World program in multiple ways in Netbeans IDE –
  1. Either you can click on ‘Run Project‘ under the ‘Run’ Menu.
  2. Or, you can straightaway click on Play button placed on the ‘Run’ toolbar.

Execute Hello world program in Java

  • After you execute the program, you will be able to see ‘Hello World!‘ text in the Output window at the bottom of the Netbeans IDE.

Output of Hello world program in NetBeans IDE

This article (Hello World Program) is written to make you familiar with Java class’s main method and the ways to execute your Java application in Netbeans IDE. There are many more tutorials lined up, so stay tune !!! Hello world program in Java is a starting point in your programming life cycle. I hope i was able to clear some concepts of Java through this post. Any queries or feedback are welcome as comments below.

VN:F [1.9.22_1171]
Your Feedback hels to Improve
Rating: 9.2/10 (9 votes cast)
VN:F [1.9.22_1171]
Rating: +6 (from 6 votes)
Write Hello World program in JAVA, 9.2 out of 10 based on 9 ratings