1 / 214

Object Oriented Development

Object Oriented Development. Java. Objectives. Develop a basic understanding of: OO Concepts Networking Web servers Servlets (live reports from databases) Using an IDE to develop applications. Learn enough Java to enable you to continue learning on your own. Non-objectives.

Télécharger la présentation

Object Oriented Development

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.


Presentation Transcript

  1. Object Oriented Development Java

  2. Objectives Develop a basic understanding of: • OO Concepts • Networking • Web servers • Servlets (live reports from databases) • Using an IDE to develop applications. • Learn enough Java to enable you to continue learning on your own.

  3. Non-objectives • Language theory. • Thorough tour of the Java APIApplication Programmer Interface • Discussion of inner-workings of Java. • GUI application development (Swing/AWT) • Why the designers of Java did what they did.

  4. Prerequisites Classes assume basic knowledge of: • Algorithms • Networks • World Wide Web • Databases

  5. Class Format • Lectures. • Review Questions. • Lab work.All lab work is limited to the illustrating the subject material presented. Lab work algorithms are simple. • Ask questions.

  6. Object Oriented Development

  7. Other Methodologies • For example: • Procedural • Aspect Oriented Programming • Integration Oriented Programming • etc…

  8. Introduction • First primitive Object Oriented Programming (OOP) language, Simula, released in 1967 • Some think it simplifies coding as opposed to Procedural, or Aspect Oriented Programming. • Coded from the point of view of items in a problem rather than a set of procedures. • Office Example.

  9. Object Oriented Programming • A PIE • Abstraction • Polymorphism • Inheritance • Encapsulation

  10. Abstraction • Representing the essential parts of a real-world thing as data. • What’s needed for your solution. • Some abstractions of a Car • VIN, Color, Make, Model, Year (Manufacturer) • Transponder ID, License Plate Number, Account Number (Fast Lane)

  11. Encapsulation • Binding data together with its functionality (methods) • Department.addEmployee() • Car.drive() • Door.open() • File.open()

  12. Inheritance • Building on an existing concept by adding new properties or functionality. • Fruit • grams • calories per gram • Citrus is a Fruit • can be squeezed into juice • “Is A” implies inheritance

  13. Polymorphism • Scary name; simple concept.Literally: “Many shapes” • Overloading • Traditionally we havesquare(int), squareF(float)… • In OO we have square(int), square(float) … • Overriding • Same function as parent class being respecified in child class.

  14. Example • Sports Car inherits from car • Drive method is overriden as well as overloaded. • Car and SportsCar abstract the “concept” of a car. • Car and SportsCar encapsulate the functionality of a car. Car int speed drive() drive(int speed) SportsCar drive() overdrive()

  15. Classes and Objects • A Class is a collection of properties (also called fields or member variables) and methods that define a new data type • An Object is an instance of a class. • Example • If Person is a class • Bob, Jim, and Mary are all objects (instances of the Person Class)

  16. JAVA Object Based from the Start

  17. What is Java? • The Java Language • Java Virtual Machine • Java API

  18. The Java Language • Developed at Sun Microsystems in 1991, released to the public in 1994 • Based upon C++, but it was made to be accessible to more programmers. • Object Oriented. Everything is a class (i.e no stand-alone functions) • Delivers secure, portable, multi-threaded, networking related applications • Case-sensitive

  19. Java Virtual Machine • Referred to as the Sandbox or JVM • Java code compiles into bytecode, unlike most other languages that compile to machine code. • Since bytecode is readable to the JVM, Java is portable to any operating system that has a Java Virtual Machine built for it.

  20. Java APIApplication Programmer Interface • A collection of software libraries, called packages, that contain Java classes • As testimony to the reusability of Java code, you use the Java API to create functionality. • Use the import keyword to access a software library • Example:import java.io.*;

  21. Programming Java Applications • A Java application is a collection of classes with one class that contains a main method as an entry point. • Most classes must reside in a file with the same namee.g. A public class called Learning must reside in a file called Learning.java • Class declarations and control flow structures are contained in {} • Variable declarations, expressions, functions and library calls end with semi-colons

  22. Main Method Method name public static void main(String[] args){ } Classmethod No return value Accessible to any class An array of String objects

  23. Comments • Java uses C/C++ commenting styles. • Single line comments are denoted by //int a; // a will be used to count sheep • Block comments begin with /* and end with *//* Author: Joe Smith Date: Jan 7th, 2002 Description: First lines of code */

  24. Declaration of class Entrance point for application public class HelloWorld { public static void main( String[] args) { System.out.println(“Hello World”); } } Method of out object Static object Object contained in System

  25. Compiling and Running Java Applications • To transform files into bytecode, use the javac (abbreviated java compile) command • javac [filename] • java [classname]

  26. Review Questions • What is the purpose of the main method? • What is the difference between a Class and an Object? • Given a cookie cutter and cookies, which would best represent an object, and which best represents a class? • What two ways are comments marked in a Java program? • How do you include other libraries so that your class can use them?

  27. Lab 1 Hola.java public class Hola { public static void main( String args[]) { System.out.println(“Hello World”); } }

  28. Borland’s JBuilder • An Integrated Development Environment (IDE) • Project • A collection of source files that solve a problem.

  29. Creating a New Project

  30. Using the Project Wizard

  31. Creating a New Class

  32. Using the Class Wizard

  33. Create Your Class.

  34. To Run a ProjectWe have to tell Jbuilder which class has the main method. • Click on the • Click on • Select HelloWorld

  35. Lab 2 Hello World in Jbuilder public class HelloWorld { public Helloword() { } public static void main( String args[]) { System.out.println(“Hello World”); } }

  36. Variables and Operators • Primitive Data-types • Classes and Objects • Operators

  37. Primitive Data-types • A data-type that does not contain any other data-types • List of Primitive Data-types • boolean byte • int long • float double • char short • JVM ensures these types are identical on all platforms

  38. Defining Variables • Format: • datatype variableName; • Examples: int a;boolean done;float salary;

  39. Using Identifiers of Variables • Identifiers are the names of the variables that a programmers assigns. • Identifiers can consist of alphanumeric symbols, underscores and dollar signs, but cannot be reserved operator symbols. • Identifiers may not begin with numeric symbols. • Identifiers are case sensitive.

  40. Variable Names • Examples of Valid Identifiers $joe J3_the_robot _this4$ i • Style: stusCaremployeeJohn myRedRobot vPawns

  41. Classes and Objects • Class • A collection of properties (also called fields or member variables) and methods that define a new data type like metadata (like the def. of a db table) • Object • A particular instance of a class.like data (the rows in a database table)

  42. Class • A class is a description of what an object will look like and how it will behave. • Classes are like an idea. You cannot use them until you make an object out of the class.

  43. Reference Variables & Objects • Reference Variables point to objects datatype refVar • When they are first defined, they point nowhere. Pawn stusPawn;Pawn jeffsPawn;

  44. new • new reserves memory for an object of a specified class and returns a reference to it. ClassName myObj;myObj = new Constructor();Pawn p;p = new Pawn();

  45. Constructing Objects • Because objects are complex datatypes, (classes) they need to be “constructed”. • Format: refVar = new[constructor()] ; Pawn stusPawn;Pawn jeffsPawn;stusPawn = new Pawn();

  46. Construction Continued Pawn stusPawn; Pawn jeffsPawn; stusPawn = new Pawn(); stusPawn = new Pawn(); stusPawn = new Pawn();

  47. Garbage Collection • Garbage Collection automatically reclaims an object when its reference count is zero • Objects have a reference Count

  48. Review Questions • Is int a class or a primitive datatype? • When you declare a reference variable, what does it point to? Pawn p; • What does the Garbage Collector do?

  49. Defining a class Format: [visibility] class ClassName{ [properties] the order [constructor methods] does not [methods] matter }

More Related