Konzepte objektorientierter Programmierung



Similar documents
First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

C++ INTERVIEW QUESTIONS

Introduction to Object-Oriented Programming

Evolution of the Major Programming Languages

Objectif. Participant. Prérequis. Remarque. Programme. C# 3.0 Programming in the.net Framework. 1. Introduction to the.

AP Computer Science Java Subset

Object Oriented Software Design II

Third AP Edition. Object-Oriented Programming and Data Structures. Maria Litvin. Gary Litvin. Phillips Academy, Andover, Massachusetts

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

Install Java Development Kit (JDK) 1.8

Java CPD (I) Frans Coenen Department of Computer Science

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

History OOP languages Year Language 1967 Simula Smalltalk

C++FA 5.1 PRACTICE MID-TERM EXAM

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

Basic Programming and PC Skills: Basic Programming and PC Skills:

An Incomplete C++ Primer. University of Wyoming MA 5310

Fundamentals of Java Programming

Java Programming Language

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

: provid.ir

Hello World RESTful web service tutorial

Chapter 5 Aspect Oriented Programming

Tutorial on Writing Modular Programs in Scala

Introducing Variance into the Java Programming Language DRAFT

JAVA - INHERITANCE. extends is the keyword used to inherit the properties of a class. Below given is the syntax of extends keyword.

Programming with the Microsoft.NET Framework Using Microsoft Visual Studio 2005 (VB)

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)

Computer Programming C++ Classes and Objects 15 th Lecture

Overview of Web Services API

Getting Started with the Internet Communications Engine

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Programmation 2. Introduction à la programmation Java

Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies)

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

CS506 Web Design and Development Solved Online Quiz No. 01

Introduction to Java

OpenCL Static C++ Kernel Language Extension

CSC 551: Web Programming. Spring 2004

INTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 09/29/2011

Polymorphism. Problems with switch statement. Solution - use virtual functions (polymorphism) Polymorphism

CORBA Programming with TAOX11. The C++11 CORBA Implementation

CEC225 COURSE COMPACT

CS 111 Classes I 1. Software Organization View to this point:

J a v a Quiz (Unit 3, Test 0 Practice)

C++ for Safety-Critical Systems. DI Günter Obiltschnig Applied Informatics Software Engineering GmbH

Compiling Object Oriented Languages. What is an Object-Oriented Programming Language? Implementation: Dynamic Binding

The C Programming Language course syllabus associate level

15-214: Principles of Software Construction 8 th March 2012

Pemrograman Dasar. Basic Elements Of Java

Chapter 1 Java Program Design and Development

Programming in C# with Microsoft Visual Studio 2010

I. INTRODUCTION. International Journal of Computer Science Trends and Technology (IJCST) Volume 3 Issue 2, Mar-Apr 2015

COS 217: Introduction to Programming Systems

Department of Electrical and Computer Engineering. EEL 3160 Embedded C++ and Data Structures. Tuesday & Thursday 3:00 5:00 pm

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

Java (12 Weeks) Introduction to Java Programming Language

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

Lecture J - Exceptions

Java Application Developer Certificate Program Competencies

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction

3 Pillars of Object-oriented Programming. Industrial Programming Systems Programming & Scripting. Extending the Example.

Moving from CS 61A Scheme to CS 61B Java

Topic 11 Scanner object, conditional execution

Glossary of Object Oriented Terms

CS170 Lab 11 Abstract Data Types & Objects

CS1002: COMPUTER SCIENCE OO MODELLING & DESIGN: WEEK 5

Konzepte objektorientierter Programmierung

Capabilities of a Java Test Execution Framework by Erick Griffin

WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.

Java Programming Fundamentals

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A

Abstract. a

13 File Output and Input

MAHALAKSHMI ENGINEERING COLLEGE B TIRUCHIRAPALLI

core. Volume I - Fundamentals Seventh Edition Sun Microsystems Press A Prentice Hall Title ULB Darmstadt

EJB 3.0 and IIOP.NET. Table of contents. Stefan Jäger / stefanjaeger@bluewin.ch

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Smallest Java Package? Java.applet.* having 1 class and 3 interfaces. Applet Class and AppletContext, AppletStub, Audioclip interfaces.

Yosemite National Park, California. CSE 114 Computer Science I Inheritance

Contents. 9-1 Copyright (c) N. Afshartous

Building Java Programs

Programming Languages CIS 443

C++ Programming Language

Java Interview Questions and Answers

CSC230 Getting Starting in C. Tyler Bletsch

LAB4 Making Classes and Objects

Java Crash Course Part I

LAB 1. Familiarization of Rational Rose Environment And UML for small Java Application Development

Syllabus for CS 134 Java Programming

Implementing Rexx Handlers in NetRexx/Java/Rexx

Transcription:

Konzepte objektorientierter Programmierung Prof. Dr. Peter Müller Werner Dietl Software Component Technology Exercises 3: Some More OO Languages Wintersemester 04/05

Agenda for Today 2 Homework Finish Java Overview Quick look at C++ and C#

3 Homework Exercise 1 interface I1 { interface I2 { final class C1 implements I1 { I1 C1 I2 public class Ex1 { public static void main( String[] args ) { C1 c1 = new C1(); I2 i2 = (I2) c1; Compilation Error: inconvertible types

4 Homework Exercise 2 I1 I2 interface I1 { interface I2 { class C1 implements I1 { final class C2 extends C1 { C1 C2 public class Ex2 { public static void main( String[] args ) { C1 c1 = new C2(); I2 i2 = (I2) c1; Runtime Error: java.lang.classcastexception

5 Homework Exercise 3 class C1 { int age = 99; int getage() { return age; class C2 extends C1 { int age = 22; int getage() { return age; Output: C1.age: C1.getAge: C2.age: C2.getAge: C1=C2.age: C1=C2.getAge: 99 99 22 22 99 22

Exception Handling 6 Basic syntax: try { // dangerous code or throw new MyException(); catch( MyException me ) { // handle my own exception catch( Exception e ) { // handle other exceptions finally { // do something that definitely has to happen

7 Assertions Example Internal function for updating an attribute: private int attr; void setattr( int newattr ) { assert newattr > 0 : "New attribute value <= 0!"; attr = newattr; An invalid call at runtime results in: Exception in thread "main" java.lang.assertionerror: New attribute value <= 0! at Test9.setAttr(Test9.java:8) at Test9.main(Test9.java:23)

8 New in Java 1.5 Generics: List<String> words = new ArrayList<String>(); Enhanced for-loop: void cancelall(collection c){ for (Object o : c) ((TimerTask)o).cancel();

Generics and Overloading 9 public class Test15<T> { public void m( T t ) { public void m( String s ) { public static void main( String[] args ) { Test15<Object> to = new Test15<Object>(); to.m( (Object) "Hello World!" ); Generic m to.m( "Hello World!" ); String m Test15<String> ts = new Test15<String>(); ts.m( "Hello World!" ); Ambiguity!

New in Java 1.5 10 Autoboxing/unboxing public class Freq { public static void main(string args[]) { Map<String, Integer> m = new TreeMap<String, Integer>(); for (String word: args) m.put(word, m.get(word) + 1); System.out.println(m); Other things: typesafe enums, static import, metadata,

Java 2 Platform, Standard Edition 11

12 C++ ISO/IEC 14882 Standard from 1998 Originally developed by Bjarne Stroustrup C++ is a general purpose programming language with a bias towards systems programming that - is a better C - supports data abstraction - supports object-oriented programming - supports generic programming. Bjarne Stroustrup

13 Hello World in C++ #include <iostream> int main() { std::cout << "Hello, world!\n";

14 Some Features of C++ Everything that C has Adds OO features Operator overloading Flexible template mechanism Large Standard Template Library STL Huge library support, though not uniform

15 Inheritance and Method Binding in C++ Multiple Inheritance Change of visibility of inherited classes Static method binding by default Dynamic method binding with virtual keyword Abstract classes by using pure virtual functions Method overriding and overloading

16 Example for C++ class Super { public: virtual void m() = 0; class Sub : public Super, private Impl, public IFace { public: void m(); void Sub::m() { cout << Sub::m\n ;

C++ References 17 http://www.research.att.com/~bs/ http://www.open-std.org/jtc1/sc22/wg21/

18 C# C# (pronounced "C Sharp") is a simple, modern, object oriented, and type-safe programming language. It will immediately be familiar to C and C++ programmers. C# combines the high productivity of Rapid Application Development (RAD) languages and the raw power of C++. ECMA-334 C# Language Specification

19 Hello World in C# using System; class Hello { static void Main() { Console.WriteLine("hello, world");

20 Some Features of C# Basically everything from Java, plus: Definable value types struct and enum Four kinds of parameters: value, reference (ref keyword), and output parameters (out keyword), and parameter arrays (params keyword) Properties Indexers Operator overloading Delegates & Events Unsafe code sections

21 Array types: Rectangular or Jagged class Test { static void Main() { int[] a1; // single-dim array of int int[,] a2; // 2-dimensional array of int int[,,] a3; // 3-dimensional array of int int[][] j2; // "jagged" array: array of // (array of int) int[][][] j3; // array of (array of // (array of int))

22 Inheritance and Method Binding in C# Single implementation inheritance Multiple interface subtyping Static method binding by default Dynamic method binding with virtual keyword Abstract classes and methods by using abstract keyword Keywords override and new distinguish between method overriding or hiding

23 Example for C# using System; public abstract class Super { public abstract void m(); public class Sub : Super, IFace { public [override new] void m() { Console.WriteLine( Sub.m );

C# References 24 http://msdn.microsoft.com/library/ default.asp?url=/library/en-us/cscon/ html/vcoricstartpage.asp (base URL) + vclrfaquicksurveyof (one word) csharpfeatures_pg.asp http://genamics.com/developer/ csharp_comparative.htm http://www.go-mono.com/

25 Questions?