Lecture Programming languages (2/e): Chapter 13c - Tucker, Noonan

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 Prelude: Abstract Data Types The Object Model Smalltalk Java Python Java released in 1995 (or Java 5) in 2004 major language changes: , 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 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 () ? 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 Prelude: Abstract Data Types The Object Model Smalltalk Java Python Java released in 1995 (or Java 5) in 2004 major language changes: , 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 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 .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
94    772    1    01-05-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.