Top Banner
Programming Our First Java Program Yingcai Xiao
34

Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

Dec 20, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

ProgrammingOur First Java Program

Yingcai Xiao

Page 2: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

What to Do

Set up for Java Programming

Write our first Java Program with IDE

Write our first Java Program without IDE

Review

Page 3: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

Programming a Computer

Page 4: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

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.

Page 5: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

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.

Page 6: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

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.

• Loader: a program load an executable into memory for execution.

• Linker: a program that links all related binary codes (libraries) together to make an executable.

• Editor: a program that can be used to write source code.

Page 7: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

IDE (Integrated Development Environment)

• Contains an editor, a compiler, a linker/loader, a debugger, sometimes, a profiler, a source code version controller, and other tools.

• A complete environment for developing software.

• Always provides library programs for performing common tasks.

Page 8: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

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

Page 9: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

Creation of a C++ program

Source File (.cpp)

Intermediate File (.I)

Object File (.obj)

Binary File (.exe)

Preprocess

Compile

Link

Edit

Load

Page 10: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

Creation of a Java program

Source File (.java)

Binary Byte File (.class)

Native Binary Code

Preprocess/Compile

JRE/JVM: load/valid/translate/execute

Edit

Page 11: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

Creation of a Java program

Page 12: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

Creation of a Java program

Page 13: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first 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

Page 14: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

Common Binary Code?(Binary Code Reuse Cross OS)

Page 15: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

Traditional Compilation

Source Code for Language 1

Language 1 Compiler on OS1

Binary Code for OS1

OS1

Source Code for Language 1

Language 1 Compiler on OS2

Binary Code for OS2

OS2

Page 16: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

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.

Page 17: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

OS-Independent Compilation: Intermediate Language

Source Code for Language 1

Language 1 Compiler on OS1

Intermediate Binary Code for Language1

OS1

Intermediate Code Interpreter OS1

OS2

Language 1 Compiler on OS2

Binary Code for OS2Binary Code for OS1

Intermediate Code Interpreter OS2

Page 18: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

Java Intermediate Language: Java Bytecode

Java Source Code (.java)

Java Compiler (javac) on OS1

Java Bytecode (.class)

OS1

Java Interpreter on OS1 (java)

OS2

Java Compiler (javac) on OS2

Binary Code for OS2Binary Code for OS1

Java Interpreter on OS2 (java)

Program statements are interpreted one at a time during the run-time.

Page 19: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

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.

Page 20: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

JIT Complier: Java Bite Code Compiler

Java Source Code (.java)

Java Compiler (javac) on OS1

Java Bytecode (.class)

OS1

Java JIT Compiler on OS1

OS2

Java Compiler (javac) on OS2

Binary Code for OS2Binary Code for OS1

Java JIT Compiler on OS2

All programming statements are compiled at compile time.

Page 21: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

.NET OS-Platform-Independence

MSIL: Microsoft Intermediate Language (Used by .NET)

Source Code for Language 1

Language 1 Compiler on OS1

MSIL Code

OS1

MSIL JIT Compiler on OS1

OS2

Language 1 Compiler on OS2

Binary Code for OS2Binary Code for OS1

MSIL JIT Compiler on OS2

Page 22: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

JIT Compilation in .NET

All MSIL code are JIT-compiled to native binary code before execution. No run-time interpretation, faster execution.

Page 23: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

A Common Language?(Source Code Reuse Cross Languages)

.NET CTS/CLR

Page 24: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

.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.

Page 25: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

.NET Language-Independence

CLR: Common Language Runtime

Source Code for Language 1

Language 1 Compiler on OS1

MSIL Code Confirming CTS (Managed Code)

OS1

CLR on OS1

OS2

Language 2 Compiler on OS2

Binary Code for OS2Binary Code for OS1

CLR on OS2

Source Code for Language 2

Page 26: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

.NET Architecture for Language and Platform Independence(fan-in and fan-out on MSIL)

Source Code for Language 1

Language 1 Compiler on OS1

OS1

CLR for OS1

OS2

Language 2 Compiler on OS2

Binary Code for OS2Binary Code for OS1

CLR for OS2

Source Code for Language 2

MSIL Code Confirming CTS (Managed Code)

Page 27: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

CLI (Common Language Infrastructure)

CLR/CTS for Everyone?

Page 28: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

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)

Page 29: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

CLI (Common Language Infrastructure) SpecificationOpen Architecture for Language and Platform Independent Programming

Source Code for Language 1

Language 1 Compiler on OS1

OS1

CLR for OS1

OS2

Language 2 Compiler on OS2

Binary Code for OS2Binary Code for OS1

CLR for OS2

Source Code for Language 2

CIL (Common Intermediate Language) Code

Confirming CTS (Common Type System)

Page 30: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

A Common Language for the Internet?

Page 31: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

A Common Language for the Internet

ASCII text (ISO/IEC 8859-1) is platform-independent.

=> HTTP (Hyper Text Transport Protocol)

=> Recognizable by all types of computers. (World Wide Web)

=> Everything is presented as text including data and programs.

Tim Berners-Lee

=> HTML (Hyper Text Markup Language)

Page 32: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

A Common Language for the Internet

XML (eXtensible Markup Language), can be used to define data and programs over the Internet.

=> SOAP (Simple Object Access Protocol), XML-based

=> WSDL (Web Service Description Language), XML-based

Page 33: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

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

Page 34: Programming Our First Java Program Yingcai Xiao. What to Do Set up for Java Programming Write our first Java Program with IDE Write our first Java Program.

What did you learn?

Computer, programming, data structure, algorithm, programming languages, …