1 Java 程序设计 Java 程序设计 Java Programming Fall, 2013
2 Course Information Instructor: Name: Tang, Rong( 汤蓉 ) My Webpage: 教师主页 → 汤蓉 tm
3 Course Information 总学时: 48 学时( Lecture : 30 学时 ; Lab : 12 学时 ; Experiment : 6 学时. 先修课程包括 : 《数据结构》、《面向对象程序设 计》等
4 Course Information Textbook: Ken Arnold, James Gosling ( 著 ), 《 The Java Programming Language , 3rd Edition 》,中国电 力出版社 References: 郑莉、王行言、马素霞编著,《 Java 语言程序设 计》,清华大学出版社 Grady Booch, James Rumbaugh, & Ivar Jacobson ( 著 ) ,《 UML 用户指南》,机械工业出版社 Peter C. Dibble ( 著 ) 滕启明 ( 译 ) ,《实时 Java 平台 编程》 机械工业出版社 龚天富,侯文永编著, 《程序设计语言与编译》, 电子工业出版社
5 Course Information Lectures: Monday, Section 3-4, 1202#; Wednesday, Section 1-2, 1202# Week 9th – 16th. Lab: Lab: 6306# Time: (Week 10th -17th) 计工 1201 班: ???
bilingual adj. 双语的,两种语言的,能说两种语言的 n. 能说两种语言的人 6
7 Course Information Course Evaluation( 课程评价 ) 平时成绩 ( 考勤, 作业和实验报告 ) : 50% 期末考试 (Final Exam) : 50% 期末考试 <45 分,则:平时成绩计 0 分; 如果平时成绩较差,期末考试 >=60 分,则以期末考 试成绩为 该课程成绩。
8 Requirements Finish exercises & practice individually and independently Each assignment must be done individually and independently by each student. You are responsible for ensuring your work is not copied by someone else. The possible penalties will be applied to all students involved in copying of assignments.
9 Course Outline Chapter 1: Java 语言介绍 Chapter 2: Java 程序设计基础 Chapter 3: JVM 体系结构 Chapter 4: 类与对象 Chapter 5: Java 语言基础语法 Chapter 6: 类的继承 Chapter 7: 接口 Chapter 8: 异常处理 Chapter 9: 多线程程序设计 Chapter 10: Java 输入输出( I/O ) Chapter 11: Java 语言高级特性
10 Contents for Today 1. Introduction to Java 2. Programming Languages 3. The development process of a Java Program 4. Translation of Java to machine code 5. Java Virtual Machine (JVM) 6. Some Features of Java 7. Types of Java Programs
11 Introduction to Java History 1991James Gosling Develops Oak (renamed Java) language for programming intelligent consumer electronic devices. 1994 used for World Wide Web applications. 1995Oak was renamed “Java” and announced formally to the world by Sun. Eventually used as a general-purpose programming language because it is object-oriented. 2009 年 04 月 20 日, Oracle 以 74 亿美元收购 Sun, 取得 Java 的版权。 2011 年 7 月 28 日, Oracle 发布 Java7 的正式版。
12 Introduction to Java Three Java Platforms Java SE — Java (Software Development Kit) Standard Edition, designed for work station development, PC, etc. Java EE — Java Enterprise Edition, used for enterprise software development and deployment, server, etc. Java ME — Java Micro Edition, used to develop small electronic devices, such as cell phones, PDA, wireless communication, etc. 其它应用: Android 是第一个内置支持 Java 的操作系统, Android 自带 的应用程序使用 Java 语言编写。
13 Some Features of Java Java 编程语言是个简单、面向对象、分布式、解释性、 健壮、安全与系统无关、可移植、高性能、多线程和动 态的语言。 1. Portable/platform independent 2. The Java Virtual Machine 3. Automatic Garbage Collection 4. No pointers or pointer arithmetic 5. Multiple inheritance replaced by interfaces, eliminates complexities of multiple inheritance
14 Programming Languages Three general types : High-level Language : Java looks like everyday English and contains mathematical notations Assembler Language: A human readable version of machine language. Words, abbreviations, letters and numbers replace 0s and 1s Machine Language: A collection of binary instructions in the form of strings of 1s & 0s understood by a specific type of CPU chip.
15 Programming Languages 1. Procedure language 2. Object-oriented language
16 Programming Languages Procedure language C action-oriented Groups of actions (procedures) of a task are formed into functions, and functions are grouped to form programs. 问题 数据集合 过程集合 结果 制定 表示为 传递给 计算
17 Programming Languages Object-oriented language: Java, C++ models the real-world objects the unit of programming is the class 问题类结果实例 抽象创建计算
18 Programming Languages Compiler: C++ A program that translates from source code to object code. Source code in this case is normally a high-level language Object code could be machine code, an intermediate language, or assembly language. Interpreter: Java A program that does both program translation and execution Interpreter translates one statement at a time, and then executes the translated statement. Source code can be either a high-level language, or an intermediate language.
19 Programming Languages Compiler Source Code ( 原始程序, t.c) Object Code ( 目的程序, t.obj ) 其他的目的程序 ( Library ) 函数库 Executable Code ( 可执行程序, t.exe or t.com ) Computer Compiler ( Compiling ) Linker (Linking)
20 Programming Languages Interpreter Source Code ( 原始程序, Basic, Java ) Interpreter Computer 同时翻译与执行同时翻译与执行
21 Java 虚拟机 (JVM) A software simulation of a hypothetical computing machine that runs Java bytecodes (Java compiler output). The Java Virtual Machine allows Java code to be portable between various hardware and OS platforms. Java 虚拟机 (JVM)- Java Virtual Machine ,它是通过在 实际的计算机上用软件模拟各种计算机功能模块虚构出来 的一个计算机。 Java 虚拟机由 5 个部分组成:一组指令集、 一组寄存器、一个堆栈、一个无用垃圾内存单元收集器和 一个方法区域。
22 Java Virtual Machine (JVM)
23 JAVA 虚拟机 - JVM 为什么使用 Java 虚拟机? Java 语言最重要的特点就是可以在任何操作系统中运行 - 跨平台特性。 Java 编译器生成与平台无关的字节码,作为虚拟机的输 入, Java 解释器得到字节码后,对其进行解释,使之能 在不同的平台下运行。 不同的操作系统有不同的虚拟机。 Java 虚拟机的基本原理 Java 虚拟机屏蔽了与具体操作系统平台相关的信息,使 得 Java 语言编译程序只需生成在 Java 虚拟机上运行的 目标代码 ( 字节码 ) ,就可以在多种平台上不加修改地运 行。 Java 虚拟机在执行字节码时,实际上最终还是把字节码 解释成具体平台上的机器指令执行。
24 The development process of a Java Program 1. Write: all source code is first written in plain text files ending with the.java extension. 2. Compile: Those source files are then compiled into.class files by the javac compiler..class files-- ‘ Byte code( 字节码 ) ’ is a standard intermediate-level language. 3. Run: A.class file contains bytecodes — the machine language of the Java Virtual Machine (JVM). The Java launcher tool then runs your application with an instance of the Java Virtual Machine.
25 The development process of a Java Program Java Compiler Java Source Code (.java) Java Byte Code (.class) Java Virtual Machine A (Machine Code A) Run.class Java Virtual Machine B (Machine Code B).class Download (optional)
26 Translation of Java to machine code
27 Translation of Java to machine code A two step process Step 1: Compile( 编译 ) source code to Java ‘ byte code ’. ‘ Byte code( 字节码 ) ’ is a standard intermediate-level language. Input: Java code in one or more files ending in.java Output: Byte code in one or more files ending in.class Step 2: Interpret( 解释 ) Java byte code on a particular machine The interpreter converts each byte code statement to the specific type of machine code and then runs that machine code.
28 The Role of the Virtual Machine Local or Remote
29 可移植性 -- Portable/platform independent 程序的可移植性:指程序不经过修改而在不同的硬件 或软件平台上运行的特性。 可移植性包括二个层次:源代码级和二进制级的可移 植性。 C 、 C++ 仅有一定的源代码级的可移植性。 Java 编译器生成与平台无关的字节码,只要安 装了 Java 运行系统,其程序就可以在任意的处 理器上运行 Write Once, Run Anywhere!
30 Types of Java Programs 1. Application Standalone Java program that can run independent of any Web browser 2. Applet Java program that runs within a Java-enabled Web browser 3. Servlet Java software that is loaded into a Web server to provide additional server functionality ala CGI programs