Hello world using java

Today we shall start our programming in java with a very basic program which all of us know is Hello world.The best advantage of Java programming is there is no need to include any header files.But every Java program should include minimum of a class.Therefore we need to write the main function in the class.To store the file we should name it with the name of the class which contain the main function.

Main program:In java program since main is written in a class it should follow all the rules of a general member function.Therefore we use all the key words as public,static,void while define a main function.We declare main as static because it is common to all the objects declared in the class.It should be accessed by all the objects of the class hence it is made public.Finally the return type of the function is void.We should pass an array of the strings to the main function.

In this program we use the output statement System.out.print(” “); to print the statement.We should know the meaning of this statement.Here the print function is defined in print stream class. But in system class an instances of the class print stream is defined as static and is named as out.Since the function in the static object is invoked using it’s class name, hence we use system.out.print for print statement.

With all the stuff keeping the mind we shall know write the code.Here I am using the class name as hello and we should use the same name to the file name.

class hello
{
   public static void main(Stirng a[])
     {
            System.out.print("Hello world");
      }
}

Hence the output is:Hello world
You can download the code from:

https://docs.google.com/file/d/0BxVG8Ozr6fvhdVJMSjNYcG1TbzA/edit?usp=sharing

Advertisements

About Anuroop D

Very enthusiastic about technology and likes to share my knowledge through blogging. Has Bachelor's in Information Technology and currently pursuing my Master's in Computer Science.
This entry was posted in Java and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s