SlideShare uma empresa 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

Mais conteúdo relacionado

Mais procurados (20)

Java I/O
Java I/OJava I/O
Java I/O
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in Java
 
JUnit & Mockito, first steps
JUnit & Mockito, first stepsJUnit & Mockito, first steps
JUnit & Mockito, first steps
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Java exception handling ppt
Java exception handling pptJava exception handling ppt
Java exception handling ppt
 
Regular Expressions in Java
Regular Expressions in JavaRegular Expressions in Java
Regular Expressions in Java
 
Exception handling
Exception handlingException handling
Exception handling
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
Java Methods
Java MethodsJava Methods
Java Methods
 
Method overriding
Method overridingMethod overriding
Method overriding
 
java interface and packages
java interface and packagesjava interface and packages
java interface and packages
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
 
this keyword in Java.pptx
this keyword in Java.pptxthis keyword in Java.pptx
this keyword in Java.pptx
 
OOP with Java - Continued
OOP with Java - Continued OOP with Java - Continued
OOP with Java - Continued
 
Java program structure
Java program structureJava program structure
Java program structure
 
Java Socket Programming
Java Socket ProgrammingJava Socket Programming
Java Socket Programming
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
 

Semelhante a Java Hello World Program

[NHN NEXT] Java 강의 - Week1
[NHN NEXT] Java 강의 - Week1[NHN NEXT] Java 강의 - Week1
[NHN NEXT] Java 강의 - Week1Young-Ho Cho
 
Common errors v2
Common errors v2Common errors v2
Common errors v2ASU Online
 
The definitive guide to java agents
The definitive guide to java agentsThe definitive guide to java agents
The definitive guide to java agentsRafael Winterhalter
 
Java Programs
Java ProgramsJava Programs
Java Programsvvpadhu
 
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
 
Java Programs Lab File
Java Programs Lab FileJava Programs Lab File
Java Programs Lab FileKandarp Tiwari
 
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++ ExamsMuhammadTalha436
 
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークGroovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークTsuyoshi Yamamoto
 
Inheritance Slides
Inheritance SlidesInheritance Slides
Inheritance SlidesAhsan Raja
 
Java Generics
Java GenericsJava Generics
Java Genericsjeslie
 
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、GaelykでハンズオンTsuyoshi Yamamoto
 
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...Ayes Chinmay
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Javabackdoor
 

Semelhante 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

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
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 ClassesCeline George
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
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.christianmathematics
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
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.pptxDenish Jangid
 

Último (20)

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
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
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
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.
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
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
 

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/