rediff ILAND
Welcome Guest, | Create your own iLand| Sign In  | New User? Get Started
BLOGS
iLand
Blogs
Friends/Contributors
Guestbook  
 
Sasikumar M
Categories
Technical
Writing
Work
Software
e-learning
Books
PP
Science
My Top Posts
Programming Prog...
What is an RSS feed?
RSS Feed 
thelittlesasi.rediffiland.com/  
Friday 5 December, 2008
 12:30 | 10/Nov/2007 |  0 Comment(s)
  Add Sasikumar M as Friend     Write to Sasikumar M     Forward this link
PP: Hello

From the days of the famous book on C language by Kernighan and Ritchie, it is customary in teaching a programming language to start with a hello to the world. It is also perhaps the simplest program to write, so we will not violate this tradition.
To produce some output from your program, you use the notation

 System.out.println("Hello, world!");

Type everything including the dots as it is. You can recognise the "print" word there reminding you that it is going to print something on your screen. The "ln" following indicates that the next output will start on a fresh line.

Replace the "YOUR PROGRAM" in the template with the above line, and try compiling and running the program. The program will look like:

public class Myclass {
    public static void main (String arg[]) {
         System.out.println("Hello, World!");
    }
}


Instead of "Hello, World!", you can put any text inside. Text enclosed in double quotation marks is called a String in Java. Do not use text containing quotation marks - they need a little special treatment. So, dont try: "Should I try " in the string"

Try, "Welcome, World" and other variants. Only simple text.

As I mentioned above, the 'ln' indicates that the next output on the screen will start on a new line. Let us try this:

    System.out.println("Hello, ");
    System.out.println("World!");

You will see that "Hello" and "World" are coming on two different lines. Try this now:

    System.out.print("Hello, ");

    System.out.println("World!");

Note that the first line is now just "print", and not "println". This tells the system not to move to the next line. This code will produce "Hello, World!" in one line.

That is our first little program....

Category: PP | Permalink