This blog is under construction

Tuesday, 22 March 2016

Simple Java program to print "Hello World"

Let us write a simple Java program to print "Hello World".

/*
 * HelloWorld.java - simple java program to print "Hello World"
 */

public class HelloWorld {
 public static void main(String args[]) {
     // print "Hello World"
  System.out.println("Hello World");
 }
}


Above is the simple Java program which would print "Hello World" on execution.  While saving the Java program, please make sure that the file has .java extension and the name of the file matches with the name of the class that has main() function.  We have stored the above source code in HelloWorld.java and the file names matches exactly with the name of the class in which main() function resides.

Let us compile the above Java program.  Basically, Java compiler would take Java source code as input and provide us bytecode version of the input Java program as output.  As a result of compiling HelloWorld.java, we will get a class file named HelloWorld.class which contains bytecode of HelloWorld.java.

d:\Java>javac HelloWorld.java

Java Virtual Machine would take the bytecode as input and prints the program output on the console.  Let us execute our Java program by providing our class name HelloWorld as command line argument to Java command or Java application launcher.  As a result of program execution, "Hello World" is printed on output screen.

d:\Java>java HelloWorld
Hello World

/* */ Multi-line comments using which we can be used to provide comments in multiple lines to explain code flow or programming logic. These comments are ignored by the compiler
// Single line comments
public access modifier which helps to control the visibility of classes, methods and other members
class HelloWorld class is the Keyword used to declare class. HelloWorld is the class name
main() Method where the program execution begins
static static is the keyword which can be used on variables, methods or blocks. static methods can be called without instantiation. Here, main() is a static method
void Return type of a function. void is used as return type when a function has nothing to return
System.out.println() System is the built in class. out is the object and println() is a built-in method
{ } open and close brace

18 comments:

  1. you have told about fundamental details of java language it is very well nice and interesting too.

    Best Informatica Training Institute in Chennai

    ReplyDelete
  2. Magicjack Support 1-800-653-4096,
    Customer Support For Magicjack
    https://completepcsolution.net/magicjack-support.html
    COMPLETEPCSOLUTION is one of the best way to resolve
    all problems like magicjack technical support,
    magicjack customer suppport and installation,
    magicjack contact number.

    ReplyDelete
  3. Magicjack Support 1-800-653-4096,
    Customer Support For Magicjack
    https://completepcsolution.net/magicjack-support.html
    COMPLETEPCSOLUTION is one of the best way to resolve
    all problems like magicjack technical support,
    magicjack customer suppport and installation,
    magicjack contact number.

    ReplyDelete
  4. Thanks for explore the some wonderful knowledge about the programming. Nice post!!!
    Kids Learning Center Singapore | Creative Learning Center Singapore

    ReplyDelete
  5. 10 very best Programming Languages that you wish to research In 2017
    Read Artical @ https://goo.gl/7NXLxn
    Website design and Developmet service in NY

    ReplyDelete
  6. I aspire to be one of this blogger.Nice i liked the collection
    http://aqtsoft.com/

    ReplyDelete
  7. Very Useful information that i have found. don't stop sharing and Please keep updating us..... Thanks

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete

  9. Really Good blog post about simple java program to print hello.provided a helpful information.keep updating...
    SEO Company in India

    ReplyDelete
  10. Hey Gyss Check out this...

    Softpro Learning Center (SLC)is the training wing of Softpro India Computer Technologies Pvt.
    Limited. SLC established itself in the year 2008.
    SLC offer an intensive and extensive range of training/internship programs for B.Tech, BCA, MCA & Diploma students.
    Softpro Learning Center is a best Summer training institute in Lucknow extends in depth knowledge of technology like .Net, Java, PHP and Android and also an opportunity to practically apply their fundamentals. SLC’s objective is to provide skilled manpower to support the vast development programs.

    ReplyDelete
  11. Thank you for your post. Hawkscode Uk is the leading IT service provider. Hawkscode Uk
    provides web design london services.

    ReplyDelete