SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Downloaden Sie, um offline zu lesen
Riccardo Rigon
Java for Hydrologists
Hello World
R.Rigon-IltavolodilavorodiRemowolf
Tuesday, July 16, 13
“Copy the work of other smart people’
http://lin-ear-th-inking.blogspot.it/2013/03/10-step-program-for-developers.html
Tuesday, July 16, 13
Objectives
Writing and commenting “Hello World”
Introduction
•This is kind of a parallel of the section “Building a Java Program” by BE.
•Second section of DJE is a little different, but many notions can be useful.
R. Rigon
Tuesday, July 16, 13
Preliminary operations
if you are working within Eclipse
•Create a new Java project within Eclipse
•Create a new Java package
•Create a new Java file
For all of these operations, please refer to the Lars
Vogel Eclipse Tutorial
R. Rigon
Work alone
Tuesday, July 16, 13
package org.geoframe.first;
public class HelloWorld {
! public static void main(String[] args) {
System.out.println("Pietro ciao!");
! }
}
this, which is one of the simplest program
It is saved in a file whose name must be: HelloWorld.java
Copy in the new file
R. Rigon
First Program
Tuesday, July 16, 13
A Java package is a mechanism for organizing Java classes into
namespaces similar to the modules of Modula.
Java packages can be stored in compressed files called JAR files,
allowing classes to download faster as a group rather than one at a
time.
Programmers also typically use packages to organize classes
belonging to the same category or providing similar functionality.
Classes in the same package can access each other's package-access
members.
package org.geoframe.first;
R. Rigon
Packages
Tuesday, July 16, 13
package org.geoframe.first;
public class HelloWorld {
! public static void main(String[] args) {
System.out.println("Pietro ciao!");
! }
}
This, which is one of the simplest program
In Java one file can contain one single public class, which is a construct like
the above
Copy in the new file
R. Rigon
Modifiers
Tuesday, July 16, 13
public means :
is in the programming jargon a modifier. A private class is visible
outside the package that contains it.
It does not apply only to classes but also to Packages and Worlds.
Alternative to public for classes) are: private, protected (an no modifier)
•private means that the class is hided from other classes within the package.
•protected is a version of public restricted only to subclasses
* See also the Chapter “Access Control” in BE book, and for generic information also the Building a Java
program in DJE book
R. Rigon
Modifiers
Tuesday, July 16, 13
This, which is one of the simplest program
Hello World is the name of the class. In Java you need to build a class to do
something
Copy in the new file
package org.geoframe.first;
public class HelloWorld {
! public static void main(String[] args) {
System.out.println("Pietro ciao!");
! }
}
R. Rigon
Class Names
Tuesday, July 16, 13
package org.geoframe.first;
public class HelloWorld {
! public static void main(String[] args) {
System.out.println("Pietro ciao!");
! }
}
this, which is one of the simplest program
To be executed the class needs to contain a main( ) method (or routine). The
argument of the method main is a String[ ] object. args is not used but the
compiler still needs it.
Copy in the new file
R. Rigon
main( )
Tuesday, July 16, 13
package org.geoframe.first;
public class HelloWorld {
! public static void main(String[] args) {
System.out.println("Pietro ciao!");
! }
}
This, which is one of the simplest program
The main(String[ ] args ) method has usually 3 modifiers:
•public
•static
•void
Copy in the new file
R. Rigon
Methods’ Modifiers
Tuesday, July 16, 13
public modifier has already be seen as in the case of classes
here, however is applied to a method, a special method indeed. Since the method
is public, it is visible outside the class, and can be shared with other classes.
R. Rigon
Methods’ Modifiers
Tuesday, July 16, 13
static (a few things to explain here):
a static method
http://www.javatutorialhub.com/java-static-variable-methods.html
• It is a method which belongs to the class and not to the object (instance)
• A static method can access only static data. It can not access non-static data
(instance variables)
• A static method can call only other static methods and can not call a non-
static method from it.
R. Rigon
Methods’ Modifiers
Tuesday, July 16, 13
static (a few things to explain here):
a static method
http://www.javatutorialhub.com/java-static-variable-methods.html
• A static method can be accessed directly by the class name and doesn’t need
any object
• Syntax : <class-name>.<method-name>
• A static method cannot refer to “this” or “super” keywords in anyway
Side Note:
• main method is static , since it must be be accessible for an application to
run , before any instantiation takes place.
R. Rigon
Methods’ Modifiers
Tuesday, July 16, 13
void:
is the return type. Since main( ) does not return anything, the void keyword is
used
R. Rigon
Methods’ Modifiers
Tuesday, July 16, 13
package org.geoframe.first;
public class HelloWorld {
! public static void main(String[] args) {
System.out.println("Pietro ciao!");
! }
}
System.out.println( )
Java comes with a lot of libraries. These do not need to be imported. This, for
instance is a method (println) of the class System.out
R. Rigon
The method and the System
Tuesday, July 16, 13
package org.geoframe.first;
public class HelloWorld {
! public static void main(String[] args) {
System.out.println("Pietro ciao!");
! }
}
System.out.println( )
This stackoverflow post clarify better what it does:
http://stackoverflow.com/questions/12002170/what-is-system-out-println-in-system-out-println-in-java
R. Rigon
The method and the System
Tuesday, July 16, 13
Execution
•Inside Eclipse
•Outside Eclipse
All of the above information is available from the Vogella website
•in OMS3
Please look at the appropriate slides
R. Rigon
Making it to work
Tuesday, July 16, 13
Thank you for your attention.
G.Ulrici,2000?
It ends here
Tuesday, July 16, 13

Weitere ähnliche Inhalte

Andere mochten auch

14.3 evaporazione dai suoli
14.3 evaporazione dai suoli14.3 evaporazione dai suoli
14.3 evaporazione dai suoliRiccardo Rigon
 
14.4 traspirazione dalle piante
14.4 traspirazione dalle piante14.4 traspirazione dalle piante
14.4 traspirazione dalle pianteRiccardo Rigon
 
14.1 fondamenti termodinamici-evaporazione
14.1 fondamenti termodinamici-evaporazione14.1 fondamenti termodinamici-evaporazione
14.1 fondamenti termodinamici-evaporazioneRiccardo Rigon
 
14.2 trasporto di vapore
14.2 trasporto di vapore14.2 trasporto di vapore
14.2 trasporto di vaporeRiccardo Rigon
 
8 probability overview-it
8   probability overview-it8   probability overview-it
8 probability overview-itRiccardo Rigon
 
Lezione introduttiva costruzioni Idrauliche
Lezione introduttiva costruzioni IdraulicheLezione introduttiva costruzioni Idrauliche
Lezione introduttiva costruzioni IdraulicheRiccardo Rigon
 
Using Git Inside Eclipse, Pushing/Cloning from GitHub
Using Git Inside Eclipse, Pushing/Cloning from GitHubUsing Git Inside Eclipse, Pushing/Cloning from GitHub
Using Git Inside Eclipse, Pushing/Cloning from GitHubAboutHydrology Slides
 
7 inferenza statisticae-statisticadescrittiva
7 inferenza statisticae-statisticadescrittiva7 inferenza statisticae-statisticadescrittiva
7 inferenza statisticae-statisticadescrittivaRiccardo Rigon
 

Andere mochten auch (16)

19a telerilevamento
19a telerilevamento19a telerilevamento
19a telerilevamento
 
19b telerilevamento
19b  telerilevamento19b  telerilevamento
19b telerilevamento
 
Peakflow
PeakflowPeakflow
Peakflow
 
0-RealBooksOfHydrology
0-RealBooksOfHydrology0-RealBooksOfHydrology
0-RealBooksOfHydrology
 
14.3 evaporazione dai suoli
14.3 evaporazione dai suoli14.3 evaporazione dai suoli
14.3 evaporazione dai suoli
 
14.4 traspirazione dalle piante
14.4 traspirazione dalle piante14.4 traspirazione dalle piante
14.4 traspirazione dalle piante
 
14.1 fondamenti termodinamici-evaporazione
14.1 fondamenti termodinamici-evaporazione14.1 fondamenti termodinamici-evaporazione
14.1 fondamenti termodinamici-evaporazione
 
14.2 trasporto di vapore
14.2 trasporto di vapore14.2 trasporto di vapore
14.2 trasporto di vapore
 
8 iuh theory-ci
8 iuh theory-ci8 iuh theory-ci
8 iuh theory-ci
 
8 probability overview-it
8   probability overview-it8   probability overview-it
8 probability overview-it
 
Lezione introduttiva costruzioni Idrauliche
Lezione introduttiva costruzioni IdraulicheLezione introduttiva costruzioni Idrauliche
Lezione introduttiva costruzioni Idrauliche
 
Using Git Inside Eclipse, Pushing/Cloning from GitHub
Using Git Inside Eclipse, Pushing/Cloning from GitHubUsing Git Inside Eclipse, Pushing/Cloning from GitHub
Using Git Inside Eclipse, Pushing/Cloning from GitHub
 
7 inferenza statisticae-statisticadescrittiva
7 inferenza statisticae-statisticadescrittiva7 inferenza statisticae-statisticadescrittiva
7 inferenza statisticae-statisticadescrittiva
 
14.8 ecosistemi-et
14.8 ecosistemi-et14.8 ecosistemi-et
14.8 ecosistemi-et
 
WFIUH
WFIUHWFIUH
WFIUH
 
1 introduction to hydrology
1   introduction to hydrology1   introduction to hydrology
1 introduction to hydrology
 

Ähnlich wie 2 jfh-yourveryfirstprogram

GuiReflectAppbuild.xml Builds, tests, and runs the pro.docx
GuiReflectAppbuild.xml      Builds, tests, and runs the pro.docxGuiReflectAppbuild.xml      Builds, tests, and runs the pro.docx
GuiReflectAppbuild.xml Builds, tests, and runs the pro.docxshericehewat
 
java basic for begginers
java basic for begginersjava basic for begginers
java basic for begginersdivaskrgupta007
 
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)Mihail Stoynov
 
Dev labs alliance top 20 basic java interview questions for sdet
Dev labs alliance top 20 basic java interview questions for sdetDev labs alliance top 20 basic java interview questions for sdet
Dev labs alliance top 20 basic java interview questions for sdetDevLabs Alliance
 
Session 11 - OOP's with Java - Packaging and Access Modifiers
Session 11 - OOP's with Java - Packaging and Access ModifiersSession 11 - OOP's with Java - Packaging and Access Modifiers
Session 11 - OOP's with Java - Packaging and Access ModifiersPawanMM
 
API workshop: Deep dive into Java
API workshop: Deep dive into JavaAPI workshop: Deep dive into Java
API workshop: Deep dive into JavaTom Johnson
 
Top 20 basic java interview questions for SDET
Top 20 basic java interview questions for SDETTop 20 basic java interview questions for SDET
Top 20 basic java interview questions for SDETDevLabs Alliance
 
Dev labs alliance top 20 basic java interview question for sdet
Dev labs alliance top 20 basic java interview question for sdetDev labs alliance top 20 basic java interview question for sdet
Dev labs alliance top 20 basic java interview question for sdetdevlabsalliance
 
Develop Android/iOS app using golang
Develop Android/iOS app using golangDevelop Android/iOS app using golang
Develop Android/iOS app using golangSeongJae Park
 
Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using ReflectionGanesh Samarthyam
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010Rich Helton
 

Ähnlich wie 2 jfh-yourveryfirstprogram (20)

3 jf h-linearequations
3  jf h-linearequations3  jf h-linearequations
3 jf h-linearequations
 
Java 9 Features
Java 9 FeaturesJava 9 Features
Java 9 Features
 
Java
JavaJava
Java
 
GuiReflectAppbuild.xml Builds, tests, and runs the pro.docx
GuiReflectAppbuild.xml      Builds, tests, and runs the pro.docxGuiReflectAppbuild.xml      Builds, tests, and runs the pro.docx
GuiReflectAppbuild.xml Builds, tests, and runs the pro.docx
 
java basic for begginers
java basic for begginersjava basic for begginers
java basic for begginers
 
Viva file
Viva fileViva file
Viva file
 
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
 
Dev labs alliance top 20 basic java interview questions for sdet
Dev labs alliance top 20 basic java interview questions for sdetDev labs alliance top 20 basic java interview questions for sdet
Dev labs alliance top 20 basic java interview questions for sdet
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
Session 11 - OOP's with Java - Packaging and Access Modifiers
Session 11 - OOP's with Java - Packaging and Access ModifiersSession 11 - OOP's with Java - Packaging and Access Modifiers
Session 11 - OOP's with Java - Packaging and Access Modifiers
 
API workshop: Deep dive into Java
API workshop: Deep dive into JavaAPI workshop: Deep dive into Java
API workshop: Deep dive into Java
 
Top 20 basic java interview questions for SDET
Top 20 basic java interview questions for SDETTop 20 basic java interview questions for SDET
Top 20 basic java interview questions for SDET
 
Dev labs alliance top 20 basic java interview question for sdet
Dev labs alliance top 20 basic java interview question for sdetDev labs alliance top 20 basic java interview question for sdet
Dev labs alliance top 20 basic java interview question for sdet
 
Develop Android/iOS app using golang
Develop Android/iOS app using golangDevelop Android/iOS app using golang
Develop Android/iOS app using golang
 
Java For Automation
Java   For AutomationJava   For Automation
Java For Automation
 
3b jf h-readingdatafromconsole
3b jf h-readingdatafromconsole3b jf h-readingdatafromconsole
3b jf h-readingdatafromconsole
 
01 spring-intro
01 spring-intro01 spring-intro
01 spring-intro
 
CHAPTER 3 part1.pdf
CHAPTER 3 part1.pdfCHAPTER 3 part1.pdf
CHAPTER 3 part1.pdf
 
Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using Reflection
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010
 

Mehr von AboutHydrology Slides (18)

RoccoPancieraMesiano sept25 2013
RoccoPancieraMesiano sept25 2013RoccoPancieraMesiano sept25 2013
RoccoPancieraMesiano sept25 2013
 
Luca Brocca seminario trento
Luca Brocca seminario trentoLuca Brocca seminario trento
Luca Brocca seminario trento
 
Water platform 2011-2014
Water platform 2011-2014Water platform 2011-2014
Water platform 2011-2014
 
La piattaforma acqua
La piattaforma acquaLa piattaforma acqua
La piattaforma acqua
 
La convenzione delle alpi
La convenzione delle alpiLa convenzione delle alpi
La convenzione delle alpi
 
Introduction to post_gis
Introduction to post_gisIntroduction to post_gis
Introduction to post_gis
 
9 precipitations - rainfall
9   precipitations - rainfall9   precipitations - rainfall
9 precipitations - rainfall
 
14 snow hydrology-part1
14 snow hydrology-part114 snow hydrology-part1
14 snow hydrology-part1
 
13 solar radiation
13   solar radiation13   solar radiation
13 solar radiation
 
15 Evapotranspiration
15   Evapotranspiration15   Evapotranspiration
15 Evapotranspiration
 
6 measurement&representation
6   measurement&representation6   measurement&representation
6 measurement&representation
 
5 hydrology quantities-measures_instruments_activities
5   hydrology quantities-measures_instruments_activities5   hydrology quantities-measures_instruments_activities
5 hydrology quantities-measures_instruments_activities
 
11 modern-iuh
11   modern-iuh11   modern-iuh
11 modern-iuh
 
10 water in soil-rev 1
10   water in soil-rev 110   water in soil-rev 1
10 water in soil-rev 1
 
4 introduction to uDig
4   introduction to uDig4   introduction to uDig
4 introduction to uDig
 
3 introduction gis
3   introduction gis3   introduction gis
3 introduction gis
 
2 hydro-geomorphology
2  hydro-geomorphology2  hydro-geomorphology
2 hydro-geomorphology
 
0-RealBookStyleAndNotation
0-RealBookStyleAndNotation0-RealBookStyleAndNotation
0-RealBookStyleAndNotation
 

Kürzlich hochgeladen

Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
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
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 

Kürzlich hochgeladen (20)

Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
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"
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
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
 
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
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 

2 jfh-yourveryfirstprogram

  • 1. Riccardo Rigon Java for Hydrologists Hello World R.Rigon-IltavolodilavorodiRemowolf Tuesday, July 16, 13
  • 2. “Copy the work of other smart people’ http://lin-ear-th-inking.blogspot.it/2013/03/10-step-program-for-developers.html Tuesday, July 16, 13
  • 3. Objectives Writing and commenting “Hello World” Introduction •This is kind of a parallel of the section “Building a Java Program” by BE. •Second section of DJE is a little different, but many notions can be useful. R. Rigon Tuesday, July 16, 13
  • 4. Preliminary operations if you are working within Eclipse •Create a new Java project within Eclipse •Create a new Java package •Create a new Java file For all of these operations, please refer to the Lars Vogel Eclipse Tutorial R. Rigon Work alone Tuesday, July 16, 13
  • 5. package org.geoframe.first; public class HelloWorld { ! public static void main(String[] args) { System.out.println("Pietro ciao!"); ! } } this, which is one of the simplest program It is saved in a file whose name must be: HelloWorld.java Copy in the new file R. Rigon First Program Tuesday, July 16, 13
  • 6. A Java package is a mechanism for organizing Java classes into namespaces similar to the modules of Modula. Java packages can be stored in compressed files called JAR files, allowing classes to download faster as a group rather than one at a time. Programmers also typically use packages to organize classes belonging to the same category or providing similar functionality. Classes in the same package can access each other's package-access members. package org.geoframe.first; R. Rigon Packages Tuesday, July 16, 13
  • 7. package org.geoframe.first; public class HelloWorld { ! public static void main(String[] args) { System.out.println("Pietro ciao!"); ! } } This, which is one of the simplest program In Java one file can contain one single public class, which is a construct like the above Copy in the new file R. Rigon Modifiers Tuesday, July 16, 13
  • 8. public means : is in the programming jargon a modifier. A private class is visible outside the package that contains it. It does not apply only to classes but also to Packages and Worlds. Alternative to public for classes) are: private, protected (an no modifier) •private means that the class is hided from other classes within the package. •protected is a version of public restricted only to subclasses * See also the Chapter “Access Control” in BE book, and for generic information also the Building a Java program in DJE book R. Rigon Modifiers Tuesday, July 16, 13
  • 9. This, which is one of the simplest program Hello World is the name of the class. In Java you need to build a class to do something Copy in the new file package org.geoframe.first; public class HelloWorld { ! public static void main(String[] args) { System.out.println("Pietro ciao!"); ! } } R. Rigon Class Names Tuesday, July 16, 13
  • 10. package org.geoframe.first; public class HelloWorld { ! public static void main(String[] args) { System.out.println("Pietro ciao!"); ! } } this, which is one of the simplest program To be executed the class needs to contain a main( ) method (or routine). The argument of the method main is a String[ ] object. args is not used but the compiler still needs it. Copy in the new file R. Rigon main( ) Tuesday, July 16, 13
  • 11. package org.geoframe.first; public class HelloWorld { ! public static void main(String[] args) { System.out.println("Pietro ciao!"); ! } } This, which is one of the simplest program The main(String[ ] args ) method has usually 3 modifiers: •public •static •void Copy in the new file R. Rigon Methods’ Modifiers Tuesday, July 16, 13
  • 12. public modifier has already be seen as in the case of classes here, however is applied to a method, a special method indeed. Since the method is public, it is visible outside the class, and can be shared with other classes. R. Rigon Methods’ Modifiers Tuesday, July 16, 13
  • 13. static (a few things to explain here): a static method http://www.javatutorialhub.com/java-static-variable-methods.html • It is a method which belongs to the class and not to the object (instance) • A static method can access only static data. It can not access non-static data (instance variables) • A static method can call only other static methods and can not call a non- static method from it. R. Rigon Methods’ Modifiers Tuesday, July 16, 13
  • 14. static (a few things to explain here): a static method http://www.javatutorialhub.com/java-static-variable-methods.html • A static method can be accessed directly by the class name and doesn’t need any object • Syntax : <class-name>.<method-name> • A static method cannot refer to “this” or “super” keywords in anyway Side Note: • main method is static , since it must be be accessible for an application to run , before any instantiation takes place. R. Rigon Methods’ Modifiers Tuesday, July 16, 13
  • 15. void: is the return type. Since main( ) does not return anything, the void keyword is used R. Rigon Methods’ Modifiers Tuesday, July 16, 13
  • 16. package org.geoframe.first; public class HelloWorld { ! public static void main(String[] args) { System.out.println("Pietro ciao!"); ! } } System.out.println( ) Java comes with a lot of libraries. These do not need to be imported. This, for instance is a method (println) of the class System.out R. Rigon The method and the System Tuesday, July 16, 13
  • 17. package org.geoframe.first; public class HelloWorld { ! public static void main(String[] args) { System.out.println("Pietro ciao!"); ! } } System.out.println( ) This stackoverflow post clarify better what it does: http://stackoverflow.com/questions/12002170/what-is-system-out-println-in-system-out-println-in-java R. Rigon The method and the System Tuesday, July 16, 13
  • 18. Execution •Inside Eclipse •Outside Eclipse All of the above information is available from the Vogella website •in OMS3 Please look at the appropriate slides R. Rigon Making it to work Tuesday, July 16, 13
  • 19. Thank you for your attention. G.Ulrici,2000? It ends here Tuesday, July 16, 13