Java Hello World Program (JNNC Technologies)


Java Hello World Program


In this post, we will see how to write first java program. This post is intended only for java beginner.
Index for this post:
hello world program will be a very simple program which will print “Hello World” to console.
Before running the program, you need to make sure java is properly installed on your machine.

Prerequisite for running a java program:

  • install the JDK if you don’t have installed it, download the JDK and install it.
  • set path of the jdk/bin directory. you can follow this link for setting the path
  • create simple hello world  java program
  • compile and run the java program
You can either write a program in IDE such eclipse or you can simply write in in text editor.
You need to save this file as “HelloWorld.java”.

Let’s run this program

If you run this program in eclipse ide, you can simply right click and on “run as java application”.
You can compile this java program using command line as below:
javac helloworld.java
You can run the program using command line as below:
java helloworld
When you run above program, you will get below output:
Hello, World!

How this java program works

This is a comment in java and this statement will be ignored at run time.
As java is object oriented programming, every java application should have class definition.
This is called main method in java. This is entry point for this program.
public: This is access modifier which is used to define visibility. Here main method will be visible to all other classes.
static: As this will be executed by JVM, it should be static.There should be no need to create object of this call.
void: This main method will not return anything.
main: “main” is method name here.
String args[]: you can pass arguments to java program using args[] array.
System.out.println is used to print anything on console.As we have passed “Hello, World!” here, it will print “Hello, World!” to console.
that’s all about Java hello world program.

0 Comments

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();