JAVA Hello World Program
A Java Hello World program is the traditional program that you will find everywhere on the web and this program is probably the simplest program that you can write and make it actually do something. Hello World program doesn't do much, it just displays one line of text on the screen but it is a complete java program that will actually compile and run.
Source Code of Hello World Java program:
|
A Closer look at Hello World Program :
The first line of the code declares a public class named HelloWorld. Declaring a class public means that it can be accessed by name form any place (talk more about Access specifiers letter). In second line we declare a main method. Every class file that can be executed form command line should have a main method just like this one. When ever we run a Java program the compilers looks for a main method to starts with. A main method is always declared as public so that it can be accessible from any where and static so it exist without a object being created. The main method takes a string array argument as parameter. We can pass a string array from command line at the time of running java program. Now inside the main method there is only one line of code that calls to the println method that prints a line of text.
The text that written after the "System.out.println("Hello World");" is known as comment. A Comment is not part of the actual code i.e. the compiler will not compile a comment. Comments are only used for increasing the readability of code. To make something a comment use two forward slashes(//) in front of it.
No comments:
Post a Comment