Download presentation
Presentation is loading. Please wait.
Published byAmice Sparks Modified over 9 years ago
1
Introduction To OOP 1.0 Fundamentals Of Java Programming Language 2.0 Exception Handling 3.0 Classes, Inheritance And Polymorphism 4.0 1
2
2
3
Define modeling concepts: abstraction, encapsulation, and packages. 1 Analyze a problem using object-oriented analysis (OOA). 2 Create classes from objects using UML Class Diagram 3 Identify components of a class 4 Construct main method () using appropriate syntax 5 Apply escape sequence for special character 6 3
4
4 Abstraction Abstraction is the process of exposing only the relevant details and ignoring (hiding) the irrelevant details (Don't get confused with "datahiding" of the "Encapsulation"). Abstraction simplifies the understanding and using of any complex system.
5
5 Encapsulation Through encapsulation, you can control what parts of a program can access the members of a class. How a member of a class can be accessed is determined by the access modifier that modifies its declaration. Java’s access modifiers are: –public –private –protected
6
6 Packages Is a collection of classes that can be shared by Java programs. Are classified into in-built packages – system packages user-defined packages - Created by the users for their requirements.
7
7 The classes are grouped together based on their functionality. Some of the important packages of Java are: lang util io awt net applet
8
8 Analysis: Precise abstraction of what the desired system must do, not how it will be done. Object-Oriented Analysis is method which examines requirements from the perspective of the classes and objects. OOA Process: Use Case Modeling – shows functions Class-based Modeling – Class diagram, CRC Behavioral Model – State Diagram, Sequence Diagram
9
9 Example : Illustrate and explain object oriented and analysis by develop an information system to support all customer-related business in car rental company. The system should support management of customer data, reservations, vehicle rental and customer billing. 1)Identify problem domain : ………….. 2)Objects: …….. 3)Attributes: ……. 4)Operation: ……….
10
10 Draw a class diagram based on scenario below:- A customer makes order from retail catalog. Use Order as a central class. Associated with the order are the Customer making the purchase and the Payment. A Payment is one of three kinds; Cash, Cheque or Credit. The order contains OrderDetails, each with its associated Item.
11
11 Possible Objects, attributes and behavior :-
12
12 Example: Class : Bicycle Attributes/Behaviour brand, colour, wheels, no of gear Method/Operations speed, speed, stop, changeGear Notes: Public + Private - Class Attributes / behaviour Method / Operations
13
13 The class declaration Attribute variable declarations and initialization (optional) Methods (optional) Comments (optional) Structuring Classes
14
14 Syntax: [modifiers] class class_identifier Example: public class Shirt Class Declaration
15
15 public int shirtID = 0; public String description = “-description required-”; public char colorCode = ‘U’; public double price = 0.0; public int quantityInStock = 0; Variable Declaration and Assignment
16
16 A comment is text that is not part of your code but serves as guide when trying to figure out what the lines of code of your program are. To comment the contents of one line, you start it with double forward slashes like this // Example : //Here is where you put the comments You can include many lines of comments in your program. To do that, comment each line with the double slashes. An alternative is to start the beginning of the commented line or paragraph with /* and end the commented section with */ Example : /* Here is a simple sentence that I want to display when the program starts. It doesn't do much. I am planning to do more stuff in the future. */ Comments:
17
17 Syntax: [modifiers] return_type method_identifier ([arguments]){ method_code_block } Example: public void displayInformation() { System.out.println("Shirt ID: " + shirtID); System.out.println("Shirt description:" + description); System.out.println("Color Code: " + colorCode); System.out.println("Shirt price: " + price); System.out.println("Quantity in stock: " + quantityInStock); } // end of display method Methods
18
18 1 public class Shirt { 2 3 public int shirtID = 0; // Default ID for the shirt 4 public String description = "-description required-"; // default 5 // The color codes are R=Red, B=Blue, G=Green, U=Unset 6 public char colorCode = ’U’; 7 public double price = 0.0; // Default price for all shirts 8 public int quantityInStock = 0; // Default quantity for all shirts 9 10 // This method displays the values for an item 11 public void displayInformation() { 12 System.out.println("Shirt ID: " + shirtID); 13 System.out.println("Shirt description:" + description); 14 System.out.println("Color Code: " + colorCode); 15 System.out.println("Shirt price: " + price); 16 System.out.println("Quantity in stock: " + quantityInStock); 17 18 } // end of display method 19 } // end of class) Class declaration Variable declaration and assignment Method displayInformation()
19
19 is a special method that the JVM recognizes as the starting point for every Java technology program that runs from a command line Syntax: public static void main (String [] args)
20
20 SequenceMeaning \bBackspace \tHorizontal tab \nLine feed \fForm feed \rCarriage return \”Double quote \’Single quote \\Back slash
21
21 123456789 123456789 // Program Welcome.java public class Welcome { public static void main (String args[]) { System.out.println(“Welcome\nto\nJava!"); } Welcome to Java! Welcome to Java! Output :-
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.