Đang chuẩn bị liên kết để tải về tài liệu:
Lecture Programming languages (2/e): Chapter 13c - Tucker, Noonan
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Chapter 13c - Java. Java is a mixed language containing both primitive data types, such as int, and objects. Java uses copy semantics for primitive data types and reference seman~ tics for objects. All methods must exist as part of some class and are virtual by default. Java (and its cousin, C#) benefit by not trying to remain totally backward compatible with C, unlike C++. | Programming Languages 2nd edition Tucker and Noonan Chapter 13 Object-Oriented Programming I am surprised that ancient and Modern writers have not attributed greater importance to the laws of inheritance . Alexis de Tocqueville Contents 13.1 Prelude: Abstract Data Types 13.2 The Object Model 13.3 Smalltalk 13.4 Java 13.5 Python 13.4 Java 1.0 released in 1995 1.5 (or Java 5) in 2004 major language changes: 1.1, 1.5 steady growth in SE libraries mixed language primitive types: int, double, boolean objects statically typed single inheritance Direct support for: inner classes visibility modifiers abstract classes interfaces generics run time type identification reflection Example: Symbolic Differentiation Implement symbolic differentiation State rules Simplification separate Use of abstract syntax Symbolic Differentiation Rules Figure 13.19 Example d/dx (2*x+1) d/dx (2*x+1) = d/dx (2*x) + d/dx 1 = x * d/dx 2 + 2 * d/dx x + 0 = x * 0 + 2 * 1 + 0 -- simplified algebraically: 2 Abstract Syntax of Expressions Expression = Variable | Value | Binary Variable = String id Value = int value Binary = Add | Subtract | Multiply | Divide Add = Expression left, right Subtract = Expression left, right Multiply = Expression left, right Divide = Expression left, right public abstract class Expression { public abstract Expression diff(Variable x); } class Value extends Expression { private int value; public Value(int v) { value = v; } public Expression diff(Variable x) { return new Value(0); } } class Variable extends Expression { private String id; static final private Value zero = new Value(0); static final private Value one = new Value(1); public Variable(String s) { id = s; } public Expression diff(Variable x) { return id.equals(x.id) ? one : zero; } } abstract class Binary extends Expression { protected Expression left, right; protected Binary(Expression u, Expression v) { left = u; right = v; } } class Add extends Binary { public Add(Expression u, Expression v) { super(u, v); } | Programming Languages 2nd edition Tucker and Noonan Chapter 13 Object-Oriented Programming I am surprised that ancient and Modern writers have not attributed greater importance to the laws of inheritance . Alexis de Tocqueville Contents 13.1 Prelude: Abstract Data Types 13.2 The Object Model 13.3 Smalltalk 13.4 Java 13.5 Python 13.4 Java 1.0 released in 1995 1.5 (or Java 5) in 2004 major language changes: 1.1, 1.5 steady growth in SE libraries mixed language primitive types: int, double, boolean objects statically typed single inheritance Direct support for: inner classes visibility modifiers abstract classes interfaces generics run time type identification reflection Example: Symbolic Differentiation Implement symbolic differentiation State rules Simplification separate Use of abstract syntax Symbolic Differentiation Rules Figure 13.19 Example d/dx (2*x+1) d/dx (2*x+1) = d/dx (2*x) + d/dx 1 = x * d/dx 2 + 2 * d/dx x + 0 = x * 0 + 2 * 1 + 0 -- simplified algebraically: 2 Abstract .