You are on page 1of 3

Handout

Globsyn Skills
Globsyn Crystals, XI 11 and 12, Block EP, Sector V, Salt Lake Electronics Complex, Kolkata
700 091, India

All information, including graphical representations, etc provided in this presentation is for exclusive use of current
Globsyn Skills students and faculty. No part of the document may be reproduced in any form or by any means, electronic or
otherwise, without written permission of the owner.

First java program


(Developed by Team IRD, Globsyn)
Following java program when executed will print HELLO WORLD in screen:
public class HelloWorld{ // ---------------------------------1
public static void main(String args[]){//-------------2
System.out.println("Hello World...");//------3
}
}
Lets understand different parts of this program:
Line 1: In java everything except (package, import) must be part of a class .
public class HelloWorld defines a class whose name is HelloWorld. Every
class name should start with capital alphabet. This is a important convention in
java. Words public,class are example of keywords in java. Not every class is
public.
Line 2: It is equivalent to main() in C / C++ .this is starting point of a java
program. Its prototype must look like:
public static void main(String args[])
Notice parameter of main() : String args[] . String is a predefined cla ss in
java(note first alphabet(S) is in capital ), which represents anything within double
quotes . Example: abcd. args is an array as this is followed by []. (same like
in C / C++) . This parameter is there to accept command line arguments.
IMPORTANT: main method of java must be defined inside a class.
Line 3: System.out.println("Hello World...");
This line prints a line (Hello world.) in screen. So this is equivale nt to
printf() of C. System is predefined class in java (again note first alphabet is in
capital). It will come up with classnotes describing each part of this line in
gfscommunity. Watch out regularly.
IMPORTANT: To print anything in screen we use: System.out.println(anything
you want to print)
Page: 2 of 3

Version 1.00

Now few additional important points, that you must remember:

Every java program must have extension .java


File name must be same as the public class name (difference between
public class and non public class will be discussed at appropriate time. Now
just remember the syntax). So in this case file name will be:
HelloWorld.java
Command to compile a java program is javac, Syntax: javac
HelloWorld.java
To run a java program command to use is java, syntax: java HelloWorld

IMPORTANT: Java must be installed and PATH must be configured correctly in


order to make java and javac to work properly.

Page: 3 of 3

Version 1.00

You might also like