SlideShare una empresa de Scribd logo
1 de 19
Descargar para leer sin conexión
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

Más contenido relacionado

Destacado

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
 

Destacado (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
 

Similar a 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
 

Similar a 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
 

Más de 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
 

Último

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
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
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 

Último (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
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
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
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 ...
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 

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