SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
kamal kotecha
 

Was ist angesagt? (20)

This keyword in java
This keyword in javaThis keyword in java
This keyword in java
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
11 constructors in derived classes
11 constructors in derived classes11 constructors in derived classes
11 constructors in derived classes
 
Generics in java
Generics in javaGenerics in java
Generics in java
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Java multi threading
Java multi threadingJava multi threading
Java multi threading
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
 
Chapter 2 Java Methods
Chapter 2 Java MethodsChapter 2 Java Methods
Chapter 2 Java Methods
 
Java constructors
Java constructorsJava constructors
Java constructors
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Java- Nested Classes
Java- Nested ClassesJava- Nested Classes
Java- Nested Classes
 
Java Arrays
Java ArraysJava Arrays
Java Arrays
 
JDBC ppt
JDBC pptJDBC ppt
JDBC ppt
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Kürzlich hochgeladen (20)

Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
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
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
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
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
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
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
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
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 

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/