1 / 37

Programming I

Programming I. Pavel Čech Faculty of Informatics and Management University Hradec Kralove pavel.cech@uhk.cz explorer.uhk.cz /pc/www. Content. Introduction into programming Object oriented modeling Object oriented programming Programming in Java. Objectives.

kurt
Download Presentation

Programming I

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming I Pavel Čech Faculty of Informatics and Management University Hradec Kralove pavel.cech@uhk.cz explorer.uhk.cz/pc/www

  2. Content • Introduction into programming • Object oriented modeling • Object oriented programming • Programming in Java

  3. Objectives • Introduce students to OOP in Java • Apply apply knowledge acquired in ALGD • Use advanced tools for application development

  4. Resources McConnell:Rapid Development – Microsoft Press 1996 McConnell:Code Complete – Microsoft Press 1994 • Electronic publications • The Java Tutorial, Java SDK Documentation - www.javasoft.com • Thinking in Java - www.bruceeckel.com, 3. edition

  5. Tools • Java 2 SDK – basic package for programming in Java • Eclipse – IDE for programming in JAVA • ArgoUML – CASE Tool for object oriented modeling in UML These tools can be downloaded from> http://iris.uhk.cz/kozel/software(uid: student, pwd: prox) All tools a free

  6. Terminlogy • Program = sequence of commands describing some action • Process = program being executed (running) program • Processor – device capable of executing a program • Data – certain kind of objects , that are appropriately transformed by the program

  7. Terminology (cont.) • Source code – programming code written in a certain programming language • Target code – binary code, that is created by compilation of source code – is executable • Byte code(Java) – intermediate code that is create by compilation but it is run by runtime environment (JRE, JVM) • Library – group of files that contain subroutines and classes and that can be used in our program

  8. Terminology (cont.2) • Data type – determines type and the size of value in variables. Indirectly determines the set of operations that can be applied to the value. • Variable – “named” block of memory in RAM for storing values. The size of the memory block depends on the data type of the value. • Constant – the same as variable but it is not allowed to changed the value (it is read only). The constant can be assigned value only once and that can be only read.

  9. Programming language • the means of communication between computer and the programmer • the means of describing an algorithm • needs to be understandable for both sides Taxonomy • Lower level programming lang. • Higher level …

  10. Types of prog. lang. • Structured • Separation of data and operations • Older by still commonly used • In many cases faster and efficient • C, Pascal, Basic,… • Object oriented • Modern • Easily maintainable • The code can be re-used • Eiffel, Smalltalk, Java, ... • Hybrid • Not strictly object oriented i.e. can also be structured (C++, Object Pascal - Delphi, Visual Basic ...)

  11. Compiler =special kind of programs for conversion of source code into machine code Types • Interpreter • Compiler

  12. Interpreter source code inputdata Computer Interpreter output data

  13. source code developer’s computer output data compiler input data target code user’s computer Compiler

  14. The process of compilation Editor Library Debugger Compiler Source code Linker (links program) Target code OBJ code relative code

  15. Running program in Java Run-time environment Compilation environment Class Loader + Verifier of byte code Java libraries Source code (.java) Java Virtual Machine JavaInterpreter Just-In-Time compiler Java compiler Local or network transmission of byte code Runtime system Byte code (.class) OS HW

  16. What is object … Objects • real world- entities that can be found everywhere • software – program entities that follow the rules of real world ones. By combination of sw. object we create object oriented programs (systems).

  17. Real world objects • Have a name (object identity) • Have properties (state) • Do something (behavior)

  18. Where can we find objects? • Thinking about a situation  • We can write some notes with description and processes in that situation. • Noun can be objects. • Verbs can be operations (behavior) of objects • Objects that are not important when considering a given problem can be left out

  19. Object oriented programs(Alan Kay) • Everything is object. Objects stores data and we can ask for some services (performing an operation). • Program is a group of objects that comunicates (send messages = ask for services). • Each object has its own memory space and can consists of other objects. Complex objects can be divided into other objects. • Every object belongs to a class. • Every object of the same class has to understand the same messages and perform the same operations. Objects can belong into more classes through inheritance.

  20. Why use objects in programs? • It is modern … • They’re closer to reality • Readable source code • Advanced tools and languages • Reusable • Easily maintainable

  21. What objects can today? • Behave • Have properties • Inherit from ancestors • Adapt • Communicate • …

  22. Terminology revisited • Object always something particular with identity called also instance(Trabant, Audi A6, ...). • Class type of objects, a group in which a set of objects belong. Describes general features common to all objects (instances) in a class (Car).

  23. Car Color HP Go() Brake() UML .... tool ArgoUML • Unified Modeling Language • Graphical language for object modeling ClassObject MyFord:Car Car attributes (data) methods (operations)

  24. Software objects • have name (identity), state, behavior • name is determined by identifier, state is described by attributes, behaviour is realized by methods

  25. Basic OOP principles • Abstraction • Encapsulation • Inheritance • Polymorphisms • Communication (messages) • Association • Aggregation (composition)

  26. Abstraction = separation of important and unimportant aspects based on a given problem Example: Calculator from the point of view of the student Important aspects: • Range and precision of numbers • Number and types of operations • Can be kept secret during the test Unimportant: • Number of chips on a system board • Type of processor • Exact algorithm of every operation

  27. Encapsulation = data and operation forms a atomic whole that cannot be separated Data (properties, state) of object and operations are dependent and influence each other. Not all features of objects are propagated to outside (Information hidding) Data – attribures of an object Operation – methods of an object Example: An angry man (state) is more noisy (behavior) than the calm one.

  28. Information hiding Every object can have private elements (attributes, methods) than cannot be seen or influence from the outside of the object (Information hiding). These elements are hidden behind so called public interface . Example:state and properties of a man‘s intestines „Doughnut“ diagram Publicinterface Private state

  29. Communication (messaging) • Objects communicate by sending messages. • As a consequence of receiving a message some operation is performed (message passing = method invocation)

  30. Association = represents a general binary relation between two classes • Each class in association has its role • For each object with a role we can determine multiplicity (cardinality) of that relation Example: Class Student is in association with the class Faculty. The student „studies“ and the faculty is „studied by“. Multiplicity: Many students (n or *) can study only one faculty.

  31. Aggregation = special kind of association that represents the relation „part of“ Object can contain other objects. Such objects are created by aggregating other objects. If the use of part objects is exclusive in aggregation we talk about composition.Example: Composition: TV x Chip Aggregation: Student x Lab

  32. studuje Association in UML Association 1..* Student 1 Faculty Aggregation Lab Student Composition TV Chip

  33. Inheritance = ability of objects toinherit attributes and behavior from ancestors (it is so called object evolution) ie. that attributes and behavior can be further extended and modified Example: • Parent-> Children • Machine -> Vehicle -> Car

  34. Machine Vehicle Car Truck Inheritance in UML

  35. Class attributes • Attributes are common must be present for all objects of a particular class • State of object is given by values of attributes • Sometimes called data, properties Example:Color, Brand, horse power

  36. Class methods • Specify behavior • Sometimes called operation or services • It is custom to hide attributes and use so called access method to set or retrieve values • Access methods • Selectors – reading/retrieving values • Modifiers – setting/writing values

  37. Method Method Attributes Method Method Information hiding Rule: None of the attributes should be directly accessible from the outside world ->(Black Box)

More Related