The Syntax

Hello World: The Application

The following is the Hello World Application as written in Java. Type it into a text file or copy it out of your web browser, and save it as a file named HelloWorld.java .

class HelloWorld { public static void main (String args[]) { System.out.println("Hello World!); } } To compile this program make sure you're in the same directory HelloWorld.java is in and type javac HelloWorld.java at the command prompt. Hello World is very close to the simplest program imaginable. Although it doesn't teach very much from a programming standpoint, it gives you a chance to learn the mechanics of writing and compiling code. If you're like me your first effort won't compile, especially if you typed it in from scratch rather than copying and pasting. Here are a few common mistakes:

  1. Did you put a semicolon after System.out.println("Hello World) ?
  2. Did you include the closing bracket?
  3. Did you type everything exactly as it appears here? In particular did you use the same capitalization? Java is case sensitive. class is not the same as Class for example.
  4. Were you in the same directory as HelloWorld.java when you typed javac HelloWorld.java?

Once your program has compiled successfully, the compiler places the executable output in a file called HelloWorld.class in the same directory as the source code file. You can then run the program by typing java HelloWorld at the command prompt. As you probably guessed the program responds by printing Hello World! on your screen.

 

Bhopal news
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

freelance web designer india ecommerce web developer | Ecommerce web design, software developer india | Web hosting India Windows hosting | India web hosting Windows hosting India | India software developer | web designer india