HelloWorld : Java Glossary
home H words local find no local find frame, full screen Google search web for topic jump to footer translate with Babelfish by Roedy Green ©1996-2008 Canadian Mind Products
Go to : punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (all)
HelloWorld
HelloWorld is usually the first Java program a novice writes. It is a trivial program that just displays the string "Hello World". This is not very impressive, but getting it to work proves you have your classpath, compiler and runtime all correctly installed and that you understand the basics of compling and running. This is a surprisingly difficult task. So break out the champagne when your little HelloWorld works.
public class HelloWorld
   {
   public static void main ( String [] args )
      {
      System.out.println( "Hello World" );
      } // end main
   } // end class HelloWorld
From the directory where HelloWorld.java lives, to compile it, type:
javac.exe -classpath . HelloWorld.java
and later run it with:
java.exe -classpath . HelloWorld
If this does not work, here are some likely problem areas:
  1. The name of the source file must be HelloWorld.java, precisely, and the name of the public class in your source must be HelloWorld, precisely, including case. If you use notepad, you may have inadvertently named your file hellowworld.txt or helloworld.java.txt.
  2. You specify the .java extension to compile, but leave the .class extension off to execute. How logical!
  3. You may not specify the fully qualified drive and path: e.g.
    java.exe -classpath . C:\TEMP\HelloWorld
    is not permitted.
  4. As a corollary, make sure the current directory is where the HelloWorld.class file is.
  5. You have to get the case exactly correct. e.g.
    java.exe -classpath . Helloworld
    is not permitted.
  6. If your HelloWorld is an Applet rather than an application, you need some HTML commands to invoke it. You don’t just load it in your browser as if it were a web page.
    Applet for more details on composing that HTML
  7. Did you remember to make your class public?
  8. Did you remember to make your main method public and static? It must have a signature exactly like this:
    public static void main ( String [] args )
  9. If you used the abbreviation javac instead of the fully qualified name such as javac.exe, check that the javac.exe you wanted is on the classpath and is the only javac.* on the classpath.
If you have a more complex program, using a package, the name of the class you put on the java command line would be com.mindprod.mypackage.MyClass. MyClass.class needs to live in a directory called C:\com\mindprod\mypackage. The current directory needs to be C:\ for Java to be able to find the class. The full truth is a little more complex, e.g. you can have zip and JAR files too.

CMP_homejump to top
CMP logo
feedback Please email your feedback for publication, errors, omissions, broken/redirected link reports
and suggestions to improve this page to Roedy Green : feedback email
made with CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[65.110.21.43]
Your face IP:[38.103.63.16] The information on this page is for non-military use only.
You are visitor number 15,700. Military use includes use by defence contractors.
You can get a fresh copy of this page from: or possibly from your local J: drive (Java virtual drive/Mindprod website mirror)
http://mindprod.com/jgloss/helloworld.html J:\mindprod\jgloss\helloworld.html