SlideShare una empresa de Scribd logo
1 de 23
Java Hello World Program
By JavaWithUs ( www.javawithus.com )
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
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
public class HelloWorld {
public static void main ( String[] args ) {
System.out.println ( “Hello World” );
}
}
class defines a class or in simpler words – a
program
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…
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 letter
2. 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.
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.
public class HelloWorld {
public static void main ( String[] args ) {
System.out.println ( “Hello World” );
}
}
Within the class, we have a method.
public class HelloWorld {
public static void main ( String[] args ) {
System.out.println ( “Hello World” );
}
}
The method has a header or method
declaration ….
public class HelloWorld {
public static void main ( String[] args ) {
System.out.println ( “Hello World” );
}
}
… and a body
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.
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.
public class HelloWorld {
public static void main ( String[] args ) {
System.out.println ( “Hello World” );
}
}
void indicates that the method does not
return any value.
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.
public class HelloWorld {
public static void main ( String[] args ) {
System.out.println ( “Hello World” );
}
}
With the parentheses are the arguments.
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.
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.
public class HelloWorld {
public static void main ( String[] args ) {
System.out.println ( “Hello World” );
}
}
The parameters to main method are passed
through command line.
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.
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.
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
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/
Presentation by
www.javawithus.com

Más contenido relacionado

La actualidad más candente

Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
Abhilash Nair
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
kamal kotecha
 

La actualidad más candente (20)

Java conditional statements
Java conditional statementsJava conditional statements
Java conditional statements
 
java 8 new features
java 8 new features java 8 new features
java 8 new features
 
Java IO Package and Streams
Java IO Package and StreamsJava IO Package and Streams
Java IO Package and Streams
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
Java interface
Java interfaceJava interface
Java interface
 
Java String
Java String Java String
Java String
 
Learn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat ShahriyarLearn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat Shahriyar
 
React hooks
React hooksReact hooks
React hooks
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
 
JAVA OOP
JAVA OOPJAVA OOP
JAVA OOP
 
JavaScript Conditional Statements
JavaScript Conditional StatementsJavaScript Conditional Statements
JavaScript Conditional Statements
 
Java - Generic programming
Java - Generic programmingJava - Generic programming
Java - Generic programming
 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsCore Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika Tutorials
 
JDBC
JDBCJDBC
JDBC
 
WHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVAWHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVA
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 

Similar a Java Hello World Program

Common errors v2
Common errors v2Common errors v2
Common errors v2
ASU Online
 
Lec 5 13_aug [compatibility mode]
Lec 5 13_aug [compatibility mode]Lec 5 13_aug [compatibility mode]
Lec 5 13_aug [compatibility mode]
Palak Sanghani
 
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
Tsuyoshi Yamamoto
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
backdoor
 

Similar a Java Hello World Program (20)

Common errors
Common errorsCommon errors
Common errors
 
java input & output statements
 java input & output statements java input & output statements
java input & output statements
 
[NHN NEXT] Java 강의 - Week1
[NHN NEXT] Java 강의 - Week1[NHN NEXT] Java 강의 - Week1
[NHN NEXT] Java 강의 - Week1
 
Common errors v2
Common errors v2Common errors v2
Common errors v2
 
The definitive guide to java agents
The definitive guide to java agentsThe definitive guide to java agents
The definitive guide to java agents
 
Java Programs
Java ProgramsJava Programs
Java Programs
 
Lec 5 13_aug [compatibility mode]
Lec 5 13_aug [compatibility mode]Lec 5 13_aug [compatibility mode]
Lec 5 13_aug [compatibility mode]
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
 
Java Programs Lab File
Java Programs Lab FileJava Programs Lab File
Java Programs Lab File
 
Inheritance
InheritanceInheritance
Inheritance
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
 
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークGroovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトーク
 
Inheritance Slides
Inheritance SlidesInheritance Slides
Inheritance Slides
 
OOP Lab Report.docx
OOP Lab Report.docxOOP Lab Report.docx
OOP Lab Report.docx
 
Java Generics
Java GenericsJava Generics
Java Generics
 
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
 
Manual tecnic sergi_subirats
Manual tecnic sergi_subiratsManual tecnic sergi_subirats
Manual tecnic sergi_subirats
 
OOPs & Inheritance Notes
OOPs & Inheritance NotesOOPs & Inheritance Notes
OOPs & Inheritance Notes
 
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 

Último

Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Último (20)

Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 

Java Hello World Program

  • 1. Java Hello World Program By JavaWithUs ( www.javawithus.com )
  • 2. 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
  • 3. 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
  • 4. public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Hello World” ); } } class defines a class or in simpler words – a program
  • 5. 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…
  • 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 letter 2. 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.
  • 7. 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.
  • 8. public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Hello World” ); } } Within the class, we have a method.
  • 9. public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Hello World” ); } } The method has a header or method declaration ….
  • 10. public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Hello World” ); } } … and a body
  • 11. 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.
  • 12. 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.
  • 13. public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Hello World” ); } } void indicates that the method does not return any value.
  • 14. 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.
  • 15. public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Hello World” ); } } With the parentheses are the arguments.
  • 16. 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.
  • 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 a group of Strings.
  • 18. public class HelloWorld { public static void main ( String[] args ) { System.out.println ( “Hello World” ); } } The parameters to main method are passed through command line.
  • 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 on the screen.
  • 20. 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.
  • 21. 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
  • 22. 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/