Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Programming with Java “Object Oriented” Programming Compiling & Running Java Programs.

Similar presentations


Presentation on theme: "Introduction to Programming with Java “Object Oriented” Programming Compiling & Running Java Programs."— Presentation transcript:

1 Introduction to Programming with Java “Object Oriented” Programming Compiling & Running Java Programs

2 1 Computing in the world We live in a complicated world. Computing is how we deal with it Search billions of Web pages Manage air traffic Automate investment trading Computer animation and games Create accurate body images for surgery Share media data Stay in touch with our friends

3 2 Coping in a computing world Modularity Break big problems into simpler sub-problems Solve big problems by composing the solutions of the sub-problems Abstraction Find common features and express solutions in terms of those features

4 3 Software Design Considerations How can I break this complicated system/simulation/game in to manageable pieces? How can I make the code reliable (according to spec) How can I make the code easy to Test and debug Add more (potentially unforseen) pieces (ideally by reusing some of the code we’ve already written) Accomplish inevitable design changes by rewriting as few of those pieces as possible Use existing code that’s already been debugged

5 4 Object Oriented Programming A program (written in an OOP language) is a collection of cooperating objects An object has: 1. state: data stored in fields (instance variables) 2. methods: named blocks of code that determine how an object behaves (also known as procedures/functions) A class is a template for creating objects An object is an instance of a class

6 5 Example: Ghost name x y … getX() getY() move() … data behavior

7 6 One Ghost Class Multiple Ghost Objects name x y getX() … “Inky” 10 50 getX() … “Blinky” 40 6 getX() … “Pinky” 9 68 getX() … “Clyde” 76 20 getX() …

8 7 Methods: Questions, Commands Query Methods: ask an object about its state // ask a Ghost for its x position ghost1.getX() ghost2.getX() Command Methods: change an object’s state // move a Ghost forward ghost1.move()

9 8 Program: Cooperating Objects 3D Scene One Light class, multiple Light objects One Camera class, multiple Camera objects, … Lord of the Rings Simulation One 3D Scene class, one 3D Scene object One Elf class, many Elf objects One Orc class, many Orc objects Financial Software One Trade class, multiple Trade objects (buy/sell/etc) One Trader class, multiple Trader objects (human/auto)

10 9 OOP Concepts Encapsulation Data, and the methods that operate on it, are grouped in an object. An object’s data (“state”) can/should be protected by making it read/writeable only via its methods (“information hiding”) Inheritance Write code once in class A and reuse it many times in subclasses B, C, and D. We call A a superclass/supertype and B, C, D subclasses/subtypes. Polymorphism Code can take on “many forms”. This is accomplished via supertype-subtype relationships established via inheritance and interfaces. (Also with generics in Java 1.5+.) Abstraction We can write code that “ignores the details”.

11 10 Programming Languages Unlike human languages: Designed for instructing computers to solve problems The listener (the compiler) is exacting & unforgiving (grr!) Like human languages they have a grammar that has evolved A Sketch of Java’s Evolution: Machine language: (code of 1’s and 0’s) Assembly language: (e.g. add, sub, jmp) C (more English-like, procedural, pointers) C++ (loosely object oriented with multiple inheritance) Java / C# (purely object oriented with single inheritance, strongly typed, garbage collection, no pointers) Evolutionary trend: more modularity and abstraction

12 11 Java Compiler and Virtual Machine The Java Compiler Checks syntax / grammar Creates a.class file which contains byte code (virtual machine code) Java Byte Code Is portable The JVM Translates byte code in to instructions for a particular processor, which “runs the program”


Download ppt "Introduction to Programming with Java “Object Oriented” Programming Compiling & Running Java Programs."

Similar presentations


Ads by Google