Lesson_02
Lesson_02
What Is a Java
Program?
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 2-2
Topics
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 2-3
Purpose of a Computer Program
A computer program is a set of instructions that run on a computer or other digital device.
• At the machine level, the program consists of binary instructions (1s and 0s).
– Machine code
• Most programs are written in high-level code (readable).
– Must be translated to machine code
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 2-4
Translating High-Level Code to Machine Code
Solaris OS
C Compiler
Solaris OS Binary
Linux
C Compiler
Linux Binary
C Code
Microsoft Windows
C Compiler
Microsoft Windows
Binary
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 2-5
Linked to Platform-Specific Libraries
Project
Libraries
Solaris OS
C Compiler
Project
Libraries
Linux
C Compiler
Linux Binary Linux Executable
Project
Libraries
Microsoft Windows
Microsoft Windows C Compiler Microsoft Windows
Binary Executable
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 2-6
Platform-Dependent Programs
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 2-7
Topics
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 2-8
Key Features of the Java Language
Some of the features that set Java apart from most other languages are that:
• It is platform-independent
• It is object-oriented
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 2-9
Java Is Platform-Independent
Java Code
Solaris OS
Java
Workstation
Bytecode
(.class file)
JRE
Linux
JRE Workstation
Java Virtual
Machine
(JVM)
Microsoft Windows
Workstation
1 Step 1
• Many early programming languages followed a
paradigm called Procedural Programming.
• These languages use a sequential pattern of program 2 Step 2
execution.
• Drawbacks to procedural programming: 3 Step 3
– Difficult to translate real-world use cases
to a sequential pattern
– Difficult to maintain programs 4 Step 4
5 Step 5
• Interaction of objects
• No prescribed sequence
• Benefits:
– Modularity
– Information hiding
– Code reuse
– Maintainability
1. Download and install the Java Development Kit (JDK) from oracle.com/java.
2. Examine the environment.
3. Compile and run a Java application by using the command line.
PATH
points
here
Runtime
Compiler
is is
de e c. i s is
o
c in d
o v a l t le le y
c fi
r
e
c ed le . e y ja e su s fi ). ss db
u in fi c
r b r s e l a te v a
o a a u e a o d c u ja e.
e
s nt v so iled Th .c tec
l e c
o
Th c .j
a
h e p a by Th exe he tim
a T m ( t n
co ru
• Syntax:
• Example:
javac SayHello.java
• Syntax:
java <classname>
java SayHello
• Output:
Hello World!
A Java program can output data in many ways. Here are some examples:
• To a file or database
• To the console
• To a webpage or other user interface
• From a Terminal window, enter java –version to see the system’s Java version.
• Look for SayHello.java in:
/labs/02-GettingStarted/Exercises/Exercise1
• Compile it: javac SayHello.java
• Run the resulting class file: java SayHello
—
Did you see the output?
• In a terminal window:
• Look for Circle.java in:
/labs/02-GettingStarted/Exercises/Exercise2
• Run the file: java Circle.java
• Did you see the output?
• Do you see any bytecode file produced?