Java Hello World Program

12,088 views

Published on

This presentation explains the 'Hello World' program in Java.

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
12,088
On SlideShare
0
From Embeds
0
Number of Embeds
10,545
Actions
Shares
0
Downloads
24
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Java Hello World Program

  1. 1. Java Hello World ProgramBy JavaWithUs ( www.javawithus.com )
  2. 2. The ProgramFirst, 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
  3. 3. public class HelloWorld {public static void main ( String[] args ) {System.out.println ( “Hello World” );}}public is an access specifier which states thatthe class is accessible from any other class
  4. 4. public class HelloWorld {public static void main ( String[] args ) {System.out.println ( “Hello World” );}}class defines a class or in simpler words – aprogram
  5. 5. public class HelloWorld {public static void main ( String[] args ) {System.out.println ( “Hello World” );}}HelloWorld is the name of the class ( orprogram ). You can give any other nameBUT…
  6. 6. 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 andnumbers can be used. Only $ and _ specialcharacters are allowed.3. Keywords ( certain reserved words ) cannot beused as identifiers.4. Spaces are not allowed.
  7. 7. public class HelloWorld {public static void main ( String[] args ) {System.out.println ( “Hello World” );}}The opening and closing braces specify thestarting and ending of the class.
  8. 8. public class HelloWorld {public static void main ( String[] args ) {System.out.println ( “Hello World” );}}Within the class, we have a method.
  9. 9. public class HelloWorld {public static void main ( String[] args ) {System.out.println ( “Hello World” );}}The method has a header or methoddeclaration ….
  10. 10. public class HelloWorld {public static void main ( String[] args ) {System.out.println ( “Hello World” );}}… and a body
  11. 11. public class HelloWorld {public static void main ( String[] args ) {System.out.println ( “Hello World” );}}The word public in the method header is thesame as the keyword public used for theclass. Here, it indicates that other classescan call this method.
  12. 12. public class HelloWorld {public static void main ( String[] args ) {System.out.println ( “Hello World” );}}static specifies that we can invoke thismethod without creating an object of theclass.
  13. 13. public class HelloWorld {public static void main ( String[] args ) {System.out.println ( “Hello World” );}}void indicates that the method does notreturn any value.
  14. 14. public class HelloWorld {public static void main ( String[] args ) {System.out.println ( “Hello World” );}}main is the name of the method. For aprogram to be run, the name of the methodshould always be main.
  15. 15. public class HelloWorld {public static void main ( String[] args ) {System.out.println ( “Hello World” );}}With the parentheses are the arguments.
  16. 16. public class HelloWorld {public static void main ( String[] args ) {System.out.println ( “Hello World” );}}It takes a String array as an arguments andstores it in the variable args.
  17. 17. public class HelloWorld {public static void main ( String[] args ) {System.out.println ( “Hello World” );}}A String is a group of letters. An array is agroup of Strings.
  18. 18. public class HelloWorld {public static void main ( String[] args ) {System.out.println ( “Hello World” );}}The parameters to main method are passedthrough command line.
  19. 19. 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 onthe screen.
  20. 20. public class HelloWorld {public static void main ( String[] args ) {System.out.println ( “Hello World” );}}System is a predefined class. out is amember of that class and println is amethod.
  21. 21. public class HelloWorld {public static void main ( String[] args ) {System.out.println ( “Welcome to JavaWithUs.com” );}}The above modified program printsWelcome to JavaWithUs.com
  22. 22. To understand the HelloWorld program in abetter way, read the following article :http://www.javawithus.com/tutorial/the-hello-world-programLearn Java through the tutorials on ourwebsite.http://www.javawithus.com/tutorial/
  23. 23. Presentation bywww.javawithus.com

×