java goes wild, lesson 1
DESCRIPTION
An introcution to,Java. What are JDK, JRE, JVM? Where to start? This presentation is a brief introduction to Java development and how to set a developer's environment properly.TRANSCRIPT
![Page 1: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/1.jpg)
Java goes wildLesson 1: Introduction to Java
Thierry Wasylczenko
![Page 2: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/2.jpg)
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
![Page 3: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/3.jpg)
Agenda• Bascis
• How does all of this work?
• Developer’s environment
3
![Page 4: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/4.jpg)
BasicsSuccess is neither magical nor mysterious. Success is the natural
consequence of consistently applying the basic fundamentals.
Jim Rohn“4
![Page 5: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/5.jpg)
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
![Page 6: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/6.jpg)
A Java file
public class Foo {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
6
![Page 7: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/7.jpg)
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
![Page 8: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/8.jpg)
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
![Page 9: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/9.jpg)
Java Archive• aka JAR
• A collection of compiled Java classes
• Package of a Java program
• Can be runnable
java -jar Foo.jar
9
![Page 10: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/10.jpg)
That'sfreaking
AWESOME !
![Page 11: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/11.jpg)
That’s awesome dude. But how
does all of this work?
You“11
![Page 12: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/12.jpg)
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“12
![Page 13: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/13.jpg)
The source code• Plain text file
• File extension: .java
• Rules for naming each file (covered later)
13
![Page 14: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/14.jpg)
The bytecode• Result of compilation
• Something in between the source code and the machine’s language
• Interpreted by the Java Virtual Machine
14
![Page 15: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/15.jpg)
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
![Page 16: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/16.jpg)
A little schemaSourcecode
Sourcecode
JVMByte code
JVMByte code
turns on
turns on
java
java
javac
javac
16
![Page 17: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/17.jpg)
Well man, you’re talking about
JVM, javac, bytecode and cool
stuff. But how do I set them up?
You“
17
![Page 18: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/18.jpg)
Developer's environmentWhen people think about computer science, they imagine people with
pocket protectors and thick glasses who code all night.
Marissa Mayer“18
![Page 19: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/19.jpg)
Java Development Kit• aka JDK
• Provides tools
• javac: java compiler
• javadoc: generates the documentation
• ...
• Includes a Java Runtime Environment
19
![Page 20: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/20.jpg)
Java Runtime Environment• aka JRE
• Provides tools:
• java: for running Java applications
• ...
20
![Page 21: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/21.jpg)
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
![Page 22: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/22.jpg)
JAVA_HOME: example
# Unix
export JAVA_HOME="/path/to/jdk"
export PATH=$JAVA_HOME/bin:$PATH
REM Windows
set JAVA_HOME="C:\path\to\jdk"
set PATH=%JAVA_HOME%\bin;%PATH%
22
![Page 23: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/23.jpg)
Avoid spaces in the path of your
JAVA_HOME.
JAVA_HOME
23
![Page 24: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/24.jpg)
JAVA_HOME: test the setupTo test the setup you can execute the following command:
$ 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)
24
![Page 25: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/25.jpg)
What does JRE stand for?
• Java Runtime Embeded
• Java Routine Exclusive
• Java Runtime Environment
Start Stop
25
![Page 26: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/26.jpg)
What is the correct command to
execute a Java program?
• java Foo.java
• java Foo
• java Foo.class
Start Stop
26
![Page 27: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/27.jpg)
1. Set the JAVA_HOME in your
environment
2. Verify your setup
Practice #1
27
![Page 28: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/28.jpg)
Practice #2Given the following code:
public class Foo {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
28
![Page 29: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/29.jpg)
1. Copy it in your favorite editor
2. Save the file as Foo.java
3. Compile it
4. Run it
Practice #2
29
![Page 30: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/30.jpg)
30
![Page 31: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/31.jpg)
Appendix
31
![Page 32: Java goes wild, lesson 1](https://reader033.vdocument.in/reader033/viewer/2022042715/5594549f1a28ab8b118b45bd/html5/thumbnails/32.jpg)
Appendix• Java Code conventions
• Not maintained since 1997, may not be accurate
32