java hello world program
DESCRIPTION
This presentation explains the 'Hello World' program in Java.TRANSCRIPT
![Page 2: Java Hello World Program](https://reader033.vdocuments.site/reader033/viewer/2022061114/54624953af79599e2c8b4a61/html5/thumbnails/2.jpg)
The Program
First, let us look at the complete program :
public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Hello World” ); }}
The output will be :
Hello World
![Page 3: Java Hello World Program](https://reader033.vdocuments.site/reader033/viewer/2022061114/54624953af79599e2c8b4a61/html5/thumbnails/3.jpg)
public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Hello World” ); }}
public is an access specifier which states that the class is accessible from any other class
![Page 4: Java Hello World Program](https://reader033.vdocuments.site/reader033/viewer/2022061114/54624953af79599e2c8b4a61/html5/thumbnails/4.jpg)
public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Hello World” ); }}
class defines a class or in simpler words – a program
![Page 5: Java Hello World Program](https://reader033.vdocuments.site/reader033/viewer/2022061114/54624953af79599e2c8b4a61/html5/thumbnails/5.jpg)
public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Hello World” ); }}
HelloWorld is the name of the class ( or program ). You can give any other name BUT…
![Page 6: Java Hello World Program](https://reader033.vdocuments.site/reader033/viewer/2022061114/54624953af79599e2c8b4a61/html5/thumbnails/6.jpg)
public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Hello World” ); }}
… that name should follow the rules of identifiers :1. It should begin with a letter2. Lowercase letters, upper case letters and
numbers can be used. Only $ and _ special characters are allowed.
3. Keywords ( certain reserved words ) cannot be used as identifiers.
4. Spaces are not allowed.
![Page 7: Java Hello World Program](https://reader033.vdocuments.site/reader033/viewer/2022061114/54624953af79599e2c8b4a61/html5/thumbnails/7.jpg)
public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Hello World” ); }}
The opening and closing braces specify the starting and ending of the class.
![Page 8: Java Hello World Program](https://reader033.vdocuments.site/reader033/viewer/2022061114/54624953af79599e2c8b4a61/html5/thumbnails/8.jpg)
public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Hello World” ); }}
Within the class, we have a method.
![Page 9: Java Hello World Program](https://reader033.vdocuments.site/reader033/viewer/2022061114/54624953af79599e2c8b4a61/html5/thumbnails/9.jpg)
public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Hello World” ); }}
The method has a header or method declaration ….
![Page 10: Java Hello World Program](https://reader033.vdocuments.site/reader033/viewer/2022061114/54624953af79599e2c8b4a61/html5/thumbnails/10.jpg)
public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Hello World” ); }}
… and a body
![Page 11: Java Hello World Program](https://reader033.vdocuments.site/reader033/viewer/2022061114/54624953af79599e2c8b4a61/html5/thumbnails/11.jpg)
public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Hello World” ); }}
The word public in the method header is the same as the keyword public used for the class. Here, it indicates that other classes can call this method.
![Page 12: Java Hello World Program](https://reader033.vdocuments.site/reader033/viewer/2022061114/54624953af79599e2c8b4a61/html5/thumbnails/12.jpg)
public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Hello World” ); }}
static specifies that we can invoke this method without creating an object of the class.
![Page 13: Java Hello World Program](https://reader033.vdocuments.site/reader033/viewer/2022061114/54624953af79599e2c8b4a61/html5/thumbnails/13.jpg)
public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Hello World” ); }}
void indicates that the method does not return any value.
![Page 14: Java Hello World Program](https://reader033.vdocuments.site/reader033/viewer/2022061114/54624953af79599e2c8b4a61/html5/thumbnails/14.jpg)
public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Hello World” ); }}
main is the name of the method. For a program to be run, the name of the method should always be main.
![Page 15: Java Hello World Program](https://reader033.vdocuments.site/reader033/viewer/2022061114/54624953af79599e2c8b4a61/html5/thumbnails/15.jpg)
public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Hello World” ); }}
With the parentheses are the arguments.
![Page 16: Java Hello World Program](https://reader033.vdocuments.site/reader033/viewer/2022061114/54624953af79599e2c8b4a61/html5/thumbnails/16.jpg)
public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Hello World” ); }}
It takes a String array as an arguments and stores it in the variable args.
![Page 17: Java Hello World Program](https://reader033.vdocuments.site/reader033/viewer/2022061114/54624953af79599e2c8b4a61/html5/thumbnails/17.jpg)
public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Hello World” ); }}
A String is a group of letters. An array is a group of Strings.
![Page 18: Java Hello World Program](https://reader033.vdocuments.site/reader033/viewer/2022061114/54624953af79599e2c8b4a61/html5/thumbnails/18.jpg)
public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Hello World” ); }}
The parameters to main method are passed through command line.
![Page 19: Java Hello World Program](https://reader033.vdocuments.site/reader033/viewer/2022061114/54624953af79599e2c8b4a61/html5/thumbnails/19.jpg)
public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Hello World” ); }}
This line prints the message to the screen. Anything within the quotes is displayed on the screen.
![Page 20: Java Hello World Program](https://reader033.vdocuments.site/reader033/viewer/2022061114/54624953af79599e2c8b4a61/html5/thumbnails/20.jpg)
public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Hello World” ); }}
System is a predefined class. out is a member of that class and println is a method.
![Page 21: Java Hello World Program](https://reader033.vdocuments.site/reader033/viewer/2022061114/54624953af79599e2c8b4a61/html5/thumbnails/21.jpg)
public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Welcome to JavaWithUs.com” ); }}
The above modified program prints
Welcome to JavaWithUs.com
![Page 22: Java Hello World Program](https://reader033.vdocuments.site/reader033/viewer/2022061114/54624953af79599e2c8b4a61/html5/thumbnails/22.jpg)
To understand the HelloWorld program in a better way, read the following article :
http://www.javawithus.com/tutorial/the-hello-world-program
Learn Java through the tutorials on our website.http://www.javawithus.com/tutorial/