First Program

Download Report

Transcript First Program

Programming
Our First Java Program
Yingcai Xiao
What to Do
Review
Set up for Java Programming
Write our first Java Program with IDE
Write our first Java Program without IDE
Programming a Computer
Computer
Computer: a device for data processing.
von Neumann architecture is used by all digital computers.
•
It runs stored programs.
•
It has the following basic components: Memory,
IO, CPU, Secondary Storage.
Computer Programs are stored instructions for data
processing. They are composed of
Programming is to define Data Structures to store data
and Algorithms to process data.
Types of Programming Languages
Machine Languages: binary opcodes, hardware dependent. Hard to
program and not portable. Programs are called binary code and
are understandable by the targeted hardware.
Assembly Languages: English-like instructions, platform/OS
dependent. Easier to program but not portable. Programs are
called assembly code and need to be translated into binary code.
High-level Languages: English-like instructions, platform/OS
independent. Easy to program and portable. Programs are called
source code and need to be translated into binary code.
Special Programs
• Operating System: a program that manages a
computer (its memory, CUP, SS, IO (networking)).
• Compiler: a program that translates source code
written in a high-level programming language into
binary code.
• Linker: a program that links all related binary codes
(libraries) together to make an executable.
• Loader: a program load an executable into memory for
execution.
• Editor: a program that can be used to write source code.
IDE (Integrated Development Environment)
• A complete environment for developing software.
• Contains an editor, a compiler, a linker/loader, a
debugger, sometimes, a profiler, a source code version
controller, and other tools.
• Always provides library programs for performing
common tasks.
Setting Up Your Computer for Java Program Development
• The lab computers are set for Java program
development.
• Follow the instructions in “Before You Begin” in the
textbook to set up your own computer.
• You can also follow the instructions at
Creation of a C++ program
Source File (.cpp)
Edit
Preprocess
Intermediate File (.I)
Compile
Object File (.obj)
Link
Binary File (.exe)
Load
Creation of a Java program
Source File (.java)
Edit
Preprocess/Compile
Binary Byte File (.class)
JRE/JVM:
load/valid/translate/execute
Native Binary Code
Creation of a Java program
Creation of a Java program
Creation of a Java Program
•
Creation Source code : use a text editor (Notepad) to write the
source code. Java source code (.java) is portable to all platforms
as long as there is a java compiler.
notepad ics.java
•
Compile the source code: Java source code are converted into
Java bytecode (.class) by the Java compiler (javac.exe). Java
byte code are portable to all platforms as long as there is a Java
runtime environment.
javac ics.java
•
Run the bytecode: Java bytecode (.class) are executed by the
Java virtual machine.
java ics
Common Binary Code?
(Binary Code Reuse Cross OS)
Traditional Compilation
Source Code for Language 1
Source Code for Language 1
Language 1 Compiler on OS1
Language 1 Compiler on OS2
Binary Code for OS1
Binary Code for OS2
OS1
OS2
OS-Independent Code:
Intermediate Languages
The trend to support machine-independent
binary code is to compile the source code into the
binary format of an intermediate language.
And to provide an interpreter for the
intermediate language on each OS to translate the
binary code of the intermediate language into the
native binary code of the OS.
OS-Independent Compilation: Intermediate Language
Source Code for Language 1
Language 1 Compiler on OS1
Language 1 Compiler on OS2
Intermediate Binary Code for Language1
Intermediate Code Interpreter OS1
Intermediate Code Interpreter OS2
Binary Code for OS1
Binary Code for OS2
OS1
OS2
Java Intermediate Language: Java Bytecode
Java Source Code (.java)
Java Compiler (javac) on OS1
Java Compiler (javac) on OS2
Java Bytecode (.class)
Java Interpreter on OS1 (java)
Java Interpreter on OS2 (java)
Binary Code for OS1
Binary Code for OS2
OS1
OS2
Program statements are interpreted one at a time during the run-time.
JIT Compiler
An interpreter interprets intermediate code one
line at a time. Slow execution.
A JIT (Just-In-Time) compiler compiles the
complete code all at once just into native binary
code before execution. Faster execution.
JIT Complier: Java Bite Code Compiler
Java Source Code (.java)
Java Compiler (javac) on OS1
Java Compiler (javac) on OS2
Java Bytecode (.class)
Java JIT Compiler on OS1
Java JIT Compiler on OS2
Binary Code for OS1
Binary Code for OS2
OS1
OS2
All programming statements are compiled at compile time.
MSIL: Microsoft Intermediate Language (Used by .NET)
Source Code for Language 1
Language 1 Compiler on OS1
Language 1 Compiler on OS2
MSIL Code
MSIL JIT Compiler on OS1
MSIL JIT Compiler on OS2
Binary Code for OS1
Binary Code for OS2
OS1
OS2
.NET OS-Platform-Independence
JIT Compilation in .NET
All MSIL code are JIT-compiled to native binary
code before execution. No run-time interpretation,
faster execution.
A Common Language?
(Source Code Reuse Cross Languages)
.NET CTS/CLR
.NET Common Language Runtime
To make .NET language independent, CLR (Common
Language Runtime) is defined as the runtime
environment.
CLR defines CTS (Common Type System) which
should be followed by all languages to be used in the
.NET framework.
The code that follows CTS standard and runs through
CLR is called managed code.
CLR: Common Language Runtime
Source Code for Language 1
Source Code for Language 2
Language 1 Compiler on OS1
Language 2 Compiler on OS2
MSIL Code Confirming CTS (Managed Code)
CLR on OS1
CLR on OS2
Binary Code for OS1
Binary Code for OS2
OS1
OS2
.NET Language-Independence
.NET Architecture for Language and Platform Independence
(fan-in and fan-out on MSIL)
Source Code for Language 1
Source Code for Language 2
Language 1 Compiler on OS1
Language 2 Compiler on OS2
MSIL Code Confirming CTS (Managed Code)
CLR for OS1
CLR for OS2
Binary Code for OS1
Binary Code for OS2
OS1
OS2
CLI (Common Language Infrastructure)
CLR/CTS for Everyone?
CLI : Common Language Infrastructure
A specification defines an environment for multiple
high-level languages to be used on different computer
platforms.
Created by Microsoft based on .NET, standardized by
MS, Intel, HP and others, ratified by ECMA and ISO.
.NET is an implementation of CLI for desktop systems.
.NET Compact Framework is an implementation of CLI
for portable devices.
Open Source implementations: Mono development
platform (Novell), Portable .NET (dotGNU)
CLI (Common Language Infrastructure) Specification
Open Architecture for Language and Platform Independent Programming
Source Code for Language 1
Source Code for Language 2
Language 1 Compiler on OS1
Language 2 Compiler on OS2
CIL (Common Intermediate Language) Code
Confirming CTS (Common Type System)
CLR for OS1
CLR for OS2
Binary Code for OS1
Binary Code for OS2
OS1
OS2
A Common Language for the Internet?
A Common Language for the Internet
ASCII text (ISO/IEC 8859-1) is platform-independent.
Tim Berners-Lee
=> HTTP (Hyper Text Transport Protocol)
=> HTML (Hyper Text Markup Language)
=> Everything is presented as text including data and programs.
=> Recognizable by all types of computers. (World Wide Web)
A Common Language for the Internet
XML (eXtensible Markup Language), can be used to
define data and programs over the Internet.
=> WSDL (Web Service Description Language), XML-based
=> SOAP (Simple Object Access Protocol), XML-based
Web Services
Libraries shared over the Internet at run-time.
Service interfaces specify what the services can
do (contracts).
Service interfaces are defined in WSDL (Web
Service Description Language)
UDDI Registry: Universal Description,
Discovery, and Integration. (yellow page)
Access Standard:
SOAP: Simple Object Access Protocol
What did you learn?
Computer, programming, data structure, algorithm,
programming languages, …