Download presentation
Presentation is loading. Please wait.
1
Object Oriented Programming
Block1-Unit 1 Object Oriented Programming
2
Objectives of M301 Developing software systems.
Large ”Complex system”. Distributed. Interacting with existing system.
3
Objectives of first lecture
Understanding some of the basic Java constructs
4
Architecture & Styles Framework (Standard Design)
Architecture and styles are used to build SW Framework (standard design) Client-server Wrapper pattern Framework (Standard Design) A standard design that has been built before, then it changed based on requirements.
5
A Wrapper Pattern : Client-server :
An existing piece of SW is ‘encased’ within a new piece of SW, but the functionality of the whole still provided by the old SW with a new interface Client-server : Client and server runs in different machines Server provides services (functions) to the client
6
Distributed System Is one in which the separate parts of the system execute on different computers & communicate with one another to achieve their purpose (we call it concurrent). Managing concurrently executing programs raises many complex issues. These executing programs or processes will interact with other processes. This means that processes have to synchronize their actions.
7
Ex1: If one process wants to send data to another process, it must do so in such away that the 2nd process can accept the data. Ex2: If the sender outputs the data when the receiver is not in a position to read the data. The solution is to make the sending process wait (block or suspend) until the receiver is ready. Processes will make use of resources ( such as data, files, and printers..) so there should be priority.
8
Deadlock 2 processes P1,P2 and 2 resources R1, R2 P1 hold R1 and needs R2, P1 can not proceed without R2 P2 hold R2 and needs R1, P2 can not proceed without R1
9
Understanding OOP with Java
10
Object Oriented Programming (OOP)
Concepts: Encapsulation Inheritance Polymorphism An OOP is structured as a community of interacting agents ’object’. Each object play a specific role and provide a service that is used by other members of the community.
11
Encapsulation Encapsulation: methods and variables are encapsulated in a class we don’t care of how it work but of what it can do. Class ’hide a program details’.
12
Inheritance Inheritance: building a new class that can have all the features of a parent class (already built) and add its own features. Example: Graduate student Class inherits from the Student Class
13
Polymorphism Polymorphism is a way of : Example 5+4 = 9
Overload operators: An operator (+, -, =, &, #, <, ……) can behave in different manners according to its operands. Example 5+4 = 9 ‘abc’ + ‘xyz’ = ‘abcxyz’
14
Introduction to JAVA
15
What is a java source file?
text file contains JAVA program What is a project (*.jpr) file consists of? It consists of : A list of source files. A list of directories in which the source files are located. A directory name for where the project’s class files are put. A name of the main class file. How many source code files can there be in a project? There is no restriction on the number of source code files in a project.
16
public class FirstProgram public static void main (String [ ] args)
Example1 import java.lang.*; public class FirstProgram { public static void main (String [ ] args) {play My first java program! System.out.println (“My first program!”); }
17
Body (in the curly braces {})
Java program Classes Header(name of class) FirstProgram Body (in the curly braces {}) Body (has members) methods Header(name of the method) main Body (sequence of statements) Data Fields (variables) No data fields in our ex.
18
modifier: public, private, static, protected
Method Header modifer return_type method_name (arguments) { sequence-of-statements } modifier: public, private, static, protected return type: int, double, class, void: no value returned a name a list of arguments:
19
Execution of the program is started by execution of the main method.
The list of arguments: The initial method always take a single argument, which is an array of string values
20
Types integer floating Point : declared as (float or double) ex: 4.3
declared as int newVar = 42; floating Point : declared as (float or double) ex: 4.3 boolean : Use it with &&, or || void used to describe methods that don’t return any value e.g. in method main. String : String name = “Fred Smith”;
21
Types All primitive types begin with lowercase letter except String
Because int.. etc are technically not object. String is an object public static void main (String [ ] args) { The parameter value for this method is named args. It is an array of string values. [ ] means an array. No size specified for the array. The size will have been set when the array was created.
22
Example2 import java.lang.*; public class SecondProgram { public static void main (String [ ] args) if (args.length > 0) System.out.println (“Hello” + args [0]); else System.out.println (“Hello”); }
23
Access modifier modifier public private Protected
24
modifiers The use of public modifier with the class, means the entire class description is public. The public in front of method named main indicates that the method is visible outside the class. Static: the method can be used without need of generating objects If the class wants to be hidden from other classes, this could happen by using private.
25
Access modifier A protected member is inaccessible to other objects but accessible within the bounds of any subclass.
26
class BankAccount Example 3 { private int accountBalance = 0;
Here we only define the class Bankccount we didn’t create any objects yet Example 3 class BankAccount { private int accountBalance = 0; public void deposit (int amount) accountBalance = accountBalance + amount; } public void withdrawal (int amount) accountBalance = accountBalance – amount;
27
Messages In another class, you could create a BankAccount object & call methods on it BankAccount myAccount = new BankAccount(); messages can be sent now: To add 100 to the accountBalance of myAccount myAccount.deposit (100);
28
Arrays in Java Jerry Ahmed Sue Ken Barry June
First value starts from 0 e.g. array called name, elements of type String Name [0] refers to the string June To Replace Ahmed with Ali: Name[4] = “Ali” An Array has a fixed number of elements Jerry Ahmed Sue Ken Barry June 1 2 3 4 5
29
If Statement Ex If (boolean) { sequence-of-statements } else
30
Why Java? Java is Simple It eliminate the use of pointers and Go to statement Java is Object Oriented It use all the object oriented principles. Java is Network Savvy It is a client side computing language, it provide a rich set of tools for programming across the network.
31
Java is Interpreted Java used a virtual machine to interpret the java file into a bytecode ‘machine independent file’, then this bytecode file compiled and executed. Java is Robust - Exception handling. - Automatic memory management ’garbage collection’.
32
Java is Secure It used a security manager that limits the actions of file system accessing, for java language array index values are checked for validity before being referenced. Java is Architecture Neutral Because java byte code don’t correspond to any particular machine, they work with all machines.
33
Java is High-Performance
Java is High-Performance It executes rapidly, nearly the same run time performance. Java is Multithreaded It is simply a multitasking lang. from the processor point of view. Java is Dynamic Because java programs move across the Internet and execute on the user’s local computer, they permit a degree of dynamic behavior.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.