SlideShare une entreprise Scribd logo
1  sur  32
Télécharger pour lire hors ligne
Java goes wild 
Lesson 1: Introduction to Java 
Thierry Wasylczenko
After this course ... 
You will: 
• Know what is the JDK/JRE 
• Be able to set up your development environment 
• Know how to compile and run a Java program 
2
Agenda 
• Bascis 
• How does all of this work? 
• Developer’s environment 
3
Basics 
Success is neither magical nor mysterious. Success is the natural 
consequence of consistently applying the basic fundamentals. 
Jim Rohn “ 
4
Basics 
• Source code is inside files with .java extension 
• The source code is compiled into .class files 
• The class files are executed by a strange thing (covered later) 
5
A Java file 
public class Foo { 
public static void main(String[] args) { 
System.out.println("Hello World!"); 
} 
} 
6
How do I get class files? 
• By compiling all Java files 
$ cd /location/of/java/files 
$ javac Foo.java 
$ ls 
Foo.class Foo.java 
$ 
7
How do I run it? 
• With the java command 
$ java Foo 
Hello World! 
$ 
• Yes you DON’T put the .class extension when you run a class ! 
8
Java Archive 
• aka JAR 
• A collection of compiled Java classes 
• Package of a Java program 
• Can be runnable 
java -jar Foo.jar 
9
That's 
freaking 
AWESOME !
That’s awesome dude. But how 
does all of this work? 
You “ 
11
12 
How does all of this work? 
It is not the beauty of a building you should look at; it's the construction 
of the foundation that will stand the test of time. 
David Allan Coe “
The source code 
• Plain text file 
• File extension: .java 
• Rules for naming each file (covered later) 
13
The bytecode 
14 
• Result of compilation 
• Something in between the source code and the machine’s language 
• Interpreted by the Java Virtual Machine
The Java Virtual Machine 
• aka the JVM 
• Kind of a black box 
• Interprets the Java bytecode 
• Is available on major platforms 
• "Compile once, run everywhere" 
15
A little schema 
Source 
code 
Source 
code 
Byte code JVM 
Byte code JVM 
turns on 
turns on 
java 
java 
javac 
javac 
16
Well man, you’re talking about 
JVM, javac, bytecode and cool 
stuff. But how do I set them up? 
You “ 
17
18 
Developer's environment 
When people think about computer science, they imagine people with 
pocket protectors and thick glasses who code all night. 
Marissa Mayer “
Java Development Kit 
• aka JDK 
• Provides tools 
• javac: java compiler 
• javadoc: generates the documentation 
• ... 
• Includes a Java Runtime Environment 
19
Java Runtime Environment 
• aka JRE 
• Provides tools: 
• java: for running Java applications 
• ... 
20
JAVA_HOME 
• An environment variable 
• Points to the JDK installation 
• Required by some tools such as: 
• IDEs 
• build tools (maven, gradle, ...) 
• ... 
• Used to update the PATH variable 
21
JAVA_HOME: example 
# Unix 
export JAVA_HOME="/path/to/jdk" 
export PATH=$JAVA_HOME/bin:$PATH 
REM Windows 
set JAVA_HOME="C:pathtojdk" 
set PATH=%JAVA_HOME%bin;%PATH% 
22
Avoid spaces in the path of your 
JAVA_HOME. 
JAVA_HOME 
23
JAVA_HOME: test the setup 
To test the setup you can execute the following command: 
24 
$ java -version 
java version "1.8.0_11" 
Java(TM) SE Runtime Environment (build 1.8.0_11-b12) 
Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)
What does JRE stand for? 
• Java Runtime Embeded 
• Java Routine Exclusive 
• Java Runtime Environment 
Start Stop 
25
What is the correct command to 
execute a Java program? 
• java Foo.java 
• java Foo 
• java Foo.class 
Start Stop 
26
1. Set the JAVA_HOME in your 
environment 
2. Verify your setup 
Practice #1 
27
Practice #2 
Given the following code: 
public class Foo { 
public static void main(String[] args) { 
System.out.println("Hello World!"); 
} 
} 
28
1. Copy it in your favorite editor 
2. Save the file as Foo.java 
3. Compile it 
4. Run it 
Practice #2 
29
30
31 
Appendix
Appendix 
• Java Code conventions 
• Not maintained since 1997, may not be accurate 
32

Contenu connexe

Tendances

DevNexus 2019: Migrating to Java 11
DevNexus 2019: Migrating to Java 11DevNexus 2019: Migrating to Java 11
DevNexus 2019: Migrating to Java 11DaliaAboSheasha
 
Using Play Framework 2 in production
Using Play Framework 2 in productionUsing Play Framework 2 in production
Using Play Framework 2 in productionChristian Papauschek
 
Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)Saeed Zarinfam
 
Android secure offline storage - CC Mobile
Android secure offline storage - CC MobileAndroid secure offline storage - CC Mobile
Android secure offline storage - CC MobileSteve De Zitter
 
JavaScript unit testing with Jasmine
JavaScript unit testing with JasmineJavaScript unit testing with Jasmine
JavaScript unit testing with JasmineYuval Dagai
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeansRyan Cuprak
 
Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules uploadRyan Cuprak
 
Building and Managing Projects with Maven
Building and Managing Projects with MavenBuilding and Managing Projects with Maven
Building and Managing Projects with MavenKhan625
 
My first powershell script
My first powershell scriptMy first powershell script
My first powershell scriptDavid Cobb
 
Designing a play framework application
Designing a play framework applicationDesigning a play framework application
Designing a play framework applicationVulcanMinds
 
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...Hackito Ergo Sum
 

Tendances (13)

Maven
Maven Maven
Maven
 
DevNexus 2019: Migrating to Java 11
DevNexus 2019: Migrating to Java 11DevNexus 2019: Migrating to Java 11
DevNexus 2019: Migrating to Java 11
 
Using Play Framework 2 in production
Using Play Framework 2 in productionUsing Play Framework 2 in production
Using Play Framework 2 in production
 
Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)Web application development using Play Framework (with Java)
Web application development using Play Framework (with Java)
 
Android secure offline storage - CC Mobile
Android secure offline storage - CC MobileAndroid secure offline storage - CC Mobile
Android secure offline storage - CC Mobile
 
Omfw 2013
Omfw 2013Omfw 2013
Omfw 2013
 
JavaScript unit testing with Jasmine
JavaScript unit testing with JasmineJavaScript unit testing with Jasmine
JavaScript unit testing with Jasmine
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeans
 
Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules upload
 
Building and Managing Projects with Maven
Building and Managing Projects with MavenBuilding and Managing Projects with Maven
Building and Managing Projects with Maven
 
My first powershell script
My first powershell scriptMy first powershell script
My first powershell script
 
Designing a play framework application
Designing a play framework applicationDesigning a play framework application
Designing a play framework application
 
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
 

Similaire à Java goes wild, lesson 1

Introduction to java
Introduction to java Introduction to java
Introduction to java Java Lover
 
Pj01 2-install java and write first java program
Pj01 2-install java and write first java programPj01 2-install java and write first java program
Pj01 2-install java and write first java programSasidharaRaoMarrapu
 
OOP Lecture 1-Intro to Java.pptx
OOP Lecture 1-Intro to Java.pptxOOP Lecture 1-Intro to Java.pptx
OOP Lecture 1-Intro to Java.pptxTanzila Kehkashan
 
basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operatorkamal kotecha
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introductionjyoti_lakhani
 
Fundamentals of java --- version 2
Fundamentals of java --- version 2Fundamentals of java --- version 2
Fundamentals of java --- version 2Uday Sharma
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to javaattiqrocket
 
The Evolution of Java
The Evolution of JavaThe Evolution of Java
The Evolution of JavaFu Cheng
 
How to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machineHow to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machineChun-Yu Wang
 
JavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesJavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesCharles Nutter
 
JavaFX - Sketch Board to Production
JavaFX - Sketch Board to ProductionJavaFX - Sketch Board to Production
JavaFX - Sketch Board to ProductionYoav Aharoni
 
01. Introduction to programming with java
01. Introduction to programming with java01. Introduction to programming with java
01. Introduction to programming with javaIntro C# Book
 
Java Programming and J2ME: The Basics
Java Programming and J2ME: The BasicsJava Programming and J2ME: The Basics
Java Programming and J2ME: The Basicstosine
 
Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012Anton Arhipov
 

Similaire à Java goes wild, lesson 1 (20)

Introduction to java
Introduction to java Introduction to java
Introduction to java
 
Pj01 2-install java and write first java program
Pj01 2-install java and write first java programPj01 2-install java and write first java program
Pj01 2-install java and write first java program
 
OOP Lecture 1-Intro to Java.pptx
OOP Lecture 1-Intro to Java.pptxOOP Lecture 1-Intro to Java.pptx
OOP Lecture 1-Intro to Java.pptx
 
basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operator
 
java swing
java swingjava swing
java swing
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introduction
 
1.Intro--Why Java.pptx
1.Intro--Why Java.pptx1.Intro--Why Java.pptx
1.Intro--Why Java.pptx
 
Java part 1
Java part 1Java part 1
Java part 1
 
Fundamentals of java --- version 2
Fundamentals of java --- version 2Fundamentals of java --- version 2
Fundamentals of java --- version 2
 
Lesson1 intro
Lesson1 introLesson1 intro
Lesson1 intro
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Lesson1 intro
Lesson1 introLesson1 intro
Lesson1 intro
 
The Evolution of Java
The Evolution of JavaThe Evolution of Java
The Evolution of Java
 
How to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machineHow to implement a simple dalvik virtual machine
How to implement a simple dalvik virtual machine
 
JavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesJavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for Dummies
 
JavaFX - Sketch Board to Production
JavaFX - Sketch Board to ProductionJavaFX - Sketch Board to Production
JavaFX - Sketch Board to Production
 
01. Introduction to programming with java
01. Introduction to programming with java01. Introduction to programming with java
01. Introduction to programming with java
 
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptxJAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
 
Java Programming and J2ME: The Basics
Java Programming and J2ME: The BasicsJava Programming and J2ME: The Basics
Java Programming and J2ME: The Basics
 
Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012
 

Plus de Thierry Wasylczenko

Du développement à la livraison avec JavaFX et le JDK9
Du développement à la livraison avec JavaFX et le JDK9Du développement à la livraison avec JavaFX et le JDK9
Du développement à la livraison avec JavaFX et le JDK9Thierry Wasylczenko
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleThierry Wasylczenko
 
#Polyglottisme, une autre manière de développer une application
#Polyglottisme, une autre manière de développer une application#Polyglottisme, une autre manière de développer une application
#Polyglottisme, une autre manière de développer une applicationThierry Wasylczenko
 

Plus de Thierry Wasylczenko (8)

Du développement à la livraison avec JavaFX et le JDK9
Du développement à la livraison avec JavaFX et le JDK9Du développement à la livraison avec JavaFX et le JDK9
Du développement à la livraison avec JavaFX et le JDK9
 
JavaFX et le JDK9
JavaFX et le JDK9JavaFX et le JDK9
JavaFX et le JDK9
 
#JavaFX.forReal() - ElsassJUG
#JavaFX.forReal() - ElsassJUG#JavaFX.forReal() - ElsassJUG
#JavaFX.forReal() - ElsassJUG
 
#JavaFX.forReal()
#JavaFX.forReal()#JavaFX.forReal()
#JavaFX.forReal()
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
#Polyglottisme, une autre manière de développer une application
#Polyglottisme, une autre manière de développer une application#Polyglottisme, une autre manière de développer une application
#Polyglottisme, une autre manière de développer une application
 
JavaFX, because you're worth it
JavaFX, because you're worth itJavaFX, because you're worth it
JavaFX, because you're worth it
 
Introduction to JavaFX 2
Introduction to JavaFX 2Introduction to JavaFX 2
Introduction to JavaFX 2
 

Dernier

Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
Wadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxWadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxNadaHaitham1
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadhamedmustafa094
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdfKamal Acharya
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesRAJNEESHKUMAR341697
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptNANDHAKUMARA10
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 

Dernier (20)

Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Wadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxWadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptx
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 

Java goes wild, lesson 1

  • 1. Java goes wild Lesson 1: Introduction to Java Thierry Wasylczenko
  • 2. After this course ... You will: • Know what is the JDK/JRE • Be able to set up your development environment • Know how to compile and run a Java program 2
  • 3. Agenda • Bascis • How does all of this work? • Developer’s environment 3
  • 4. Basics Success is neither magical nor mysterious. Success is the natural consequence of consistently applying the basic fundamentals. Jim Rohn “ 4
  • 5. Basics • Source code is inside files with .java extension • The source code is compiled into .class files • The class files are executed by a strange thing (covered later) 5
  • 6. A Java file public class Foo { public static void main(String[] args) { System.out.println("Hello World!"); } } 6
  • 7. How do I get class files? • By compiling all Java files $ cd /location/of/java/files $ javac Foo.java $ ls Foo.class Foo.java $ 7
  • 8. How do I run it? • With the java command $ java Foo Hello World! $ • Yes you DON’T put the .class extension when you run a class ! 8
  • 9. Java Archive • aka JAR • A collection of compiled Java classes • Package of a Java program • Can be runnable java -jar Foo.jar 9
  • 11. That’s awesome dude. But how does all of this work? You “ 11
  • 12. 12 How does all of this work? It is not the beauty of a building you should look at; it's the construction of the foundation that will stand the test of time. David Allan Coe “
  • 13. The source code • Plain text file • File extension: .java • Rules for naming each file (covered later) 13
  • 14. The bytecode 14 • Result of compilation • Something in between the source code and the machine’s language • Interpreted by the Java Virtual Machine
  • 15. The Java Virtual Machine • aka the JVM • Kind of a black box • Interprets the Java bytecode • Is available on major platforms • "Compile once, run everywhere" 15
  • 16. A little schema Source code Source code Byte code JVM Byte code JVM turns on turns on java java javac javac 16
  • 17. Well man, you’re talking about JVM, javac, bytecode and cool stuff. But how do I set them up? You “ 17
  • 18. 18 Developer's environment When people think about computer science, they imagine people with pocket protectors and thick glasses who code all night. Marissa Mayer “
  • 19. Java Development Kit • aka JDK • Provides tools • javac: java compiler • javadoc: generates the documentation • ... • Includes a Java Runtime Environment 19
  • 20. Java Runtime Environment • aka JRE • Provides tools: • java: for running Java applications • ... 20
  • 21. JAVA_HOME • An environment variable • Points to the JDK installation • Required by some tools such as: • IDEs • build tools (maven, gradle, ...) • ... • Used to update the PATH variable 21
  • 22. JAVA_HOME: example # Unix export JAVA_HOME="/path/to/jdk" export PATH=$JAVA_HOME/bin:$PATH REM Windows set JAVA_HOME="C:pathtojdk" set PATH=%JAVA_HOME%bin;%PATH% 22
  • 23. Avoid spaces in the path of your JAVA_HOME. JAVA_HOME 23
  • 24. JAVA_HOME: test the setup To test the setup you can execute the following command: 24 $ java -version java version "1.8.0_11" Java(TM) SE Runtime Environment (build 1.8.0_11-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)
  • 25. What does JRE stand for? • Java Runtime Embeded • Java Routine Exclusive • Java Runtime Environment Start Stop 25
  • 26. What is the correct command to execute a Java program? • java Foo.java • java Foo • java Foo.class Start Stop 26
  • 27. 1. Set the JAVA_HOME in your environment 2. Verify your setup Practice #1 27
  • 28. Practice #2 Given the following code: public class Foo { public static void main(String[] args) { System.out.println("Hello World!"); } } 28
  • 29. 1. Copy it in your favorite editor 2. Save the file as Foo.java 3. Compile it 4. Run it Practice #2 29
  • 30. 30
  • 32. Appendix • Java Code conventions • Not maintained since 1997, may not be accurate 32