Block 1 Unit 1 Introduction and the IDE

Block 1 -Unit 1 Introduction and the IDE Atiya Masood

Objectives of M 301 is about the developing of software systems l this module is about development software systems (SW) which are large and distributed in autonomous computers. l l SW: is a collection of independent applications tied together with bridging software. § Bridging SW § § Is a collection of independent applications tied together. . That is, SW specifically written so that 2 or more separate applications can work together So many systems consist of a number of applications, interact with each other via complex bridging SW

Software in business l Software is a critical issue which most businesses depend on. l If an existing software needs to be enhanced by adding a new function, the existing software will be called a legacy system ‘existing software that must be kept running

Maintainable software Software is often a collection of independent applications tied together with bridging software ‘software that is written so that two or more separate applications can work together’. Maintainability of software means: 1. Correcting faults. 2. Extend functionality l

SW development has a sequence of phases Building a SW needs 3 parties: Customer, Developer, Users l Customer: The company or institute that needs the SW. l Developer: Programmer team. l Users: people who will use the system. l

SW development has a sequence of phases l Traditionally software development (water fall model) has been divided into the following activities 1. requirements analysis. : the process of producing a d complete of the requirements of the system. ﻫﻲ : ﺗﺤﻠﻴﻞ ﺍﻟﻤﺘﻄﻠﺒﺎﺕ ﻋﻤﻠﻴﺔ ﺍﻧﺘﺎﺝ ﻣﻮﺍﺻﻔﺎﺕ ﻛﺎﻣﻠﺔ ﻭﻣﻔﺼﻠﺔ ﻟﻤﺘﻄﻠﺒﺎﺕ ﺍﻟﻨﻈﺎﻡ l Identifying what the user wants from the SW. l clear identification of the needs of the users, a process often referred to as requirements analysis. The process that produces the negotiated statement of requirements from the statement of requirements. It involves both customer and developer l l Analysis: analysing the specification of requirements to develop a detailed understanding in computing terms of what the system has to do. ﻫﻮ ﺗﺤﻠﻴﻞ : ﺍﻟﺘﺤﻠﻴﻞ ﻣﻮﺍﺻﻔﺎﺕ ﺍﻟﻤﺘﻄﻠﺒﺎﺕ ﻟﺘﻄﺭ ﻓﻬﻢ ﻣﻔﻝ ﻓﻲ ﺣﺴﺎﺏ ﺍﻟﺸﺮﻭﻁ ﻛﻴﻒ ﻳﻌﻤﻞ ﺍﻟﻨﻈﺎﻡ

l Analysis: the process of generating the Requirements Specification, which is the process of finding out what the SW should do and the environment in which it work. The analysis phase could be broken into: l Elicitation of requirements: Finding out what is required. l Specification of requirements: The production of the requirements specification document. l § § Requirements could be changed throughout the SW development process Analysis does not depend on using a computer. This stage precedes consideration of possible solutions and detailed choices of designs and computer languages.

SW development has a sequence of phases Design: deciding how the system will meet the specified requirements. >ﺗﻘﺮﻳﺮ ﻛﻴﻒ ﺍﻟﻨﻈﺎﻡ ﺳﻴﻠﻱ ﺍﻟﻤﺘﻄﻠﺒﺎﺕ ﺍﻟﻤﺤﺩﺓ l deciding how to achieve the requirements technically. l Design, in contrast to analysis, involves much less discussion with the customer about the detailed meaning of the system. Design is about deciding on structures which can be justified as being necessary in terms of efficiency, flexibility, re-use, and other factors, that is, in design, there is a significant choice in the structures we produce. l

SW development has a sequence of phases l Implementation: translating the completed design into l program code in some suitable programming language. ﺗﺮﺟﻤﺔ ﺍﻟﺘﺼﻤﻴﻢ ﺍﻟﻤﻜﻝ ﺍﻟﻰ ﺭﻣﺰ ﺑﺮﻧﺎﻣﺞ ﻟﻠﻐﺔ ﺑﺮﻣﺠﺔ ﻣﻨﺎﺳﺒﺔ : ﺍﻟﺘﻄﺒﻴﻖ ● Testing l l l Ensure that the SW works technically. Ensure that the SW meets the objectives and specification. After testing the design, implementation, and testing phases may need re applying, this process called life cycle of developing a SW.

Architecture & Styles SW is so complex & large § It needs thinking and describing § Which we will call it SW Architecture § SW Architecture Is the idea of taking an overview ’the developing for the SW’. § Different architecture and styles are used to build a SW: § Framework (Standard Design) client-server § Wrapper pattern: §

Architecture & Styles l Framework l (Standard Design ) The chosen architecture should be similar to a SW system that has been built before, which is called a Standard Design or Framework (and then change it according to what is required. ) l A web application framework is a software framework that is designed to support the development of dynamic websites If a needed part is unavailable, an existing part should be built, which we call it Component § A new architecture should be constructed parts will have to be arranged in a particular kind of design and again tied and tested, which we call it Patterns. l

Architecture & Styles l Using client-server architecture, where you expect to find a client and a server running in different machines. l Wrapper pattern: where an existing piece of SW (already developed) is encased (wrapped) within a new piece of SW, which adds a new interface to the old SW. But the functionality of the whole is still provided by the old SW. § Abstraction § The process of describing the essential features of something & ignoring other details

Project Management § § § SW can be complex & large, and have to be developed by teams over several years The customer wants a system development process that is predictable The facilities that the SW systems offers must solve the customer’s problems The SW must be delivered within a defined timescale & to an agree budget The work required is broken down into smaller stages (phases)

Project Management § § § Then broken down into small tasks, each for 1 person in a week or month. The work has to be planned. These plans will be created at the start of the project. At the start, much of the project details are uncertain. The plan is accurate by 25%. The plan need to be updated as the development process progress.

Project Management l Validation: Checking with the customers that the SW does what customers want. l Verification: Checking the functional correctness. Check the design according to specification, check if the programming is correctly coded. § Quality Assurance § Process for checking the system’s quality

Distributed system l l The most common kind of SW is: Distributed system: in which the separate parts of the system execute on different computers and communicate with one another to achieve their purpose. l Distributes systems could be called Concurrent Systems where number of programs (parts) are executing simultaneously on different machines and exchanging data between each other. § These executing programs or processes will interact with other processes. § This means that processes have to synchronize their actions

Distributed system Exp 1: If one process wants to send data to another process, it must do so in such away that the 2 nd process can accept the data. Exp 2: 1. 2. 3. 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.

Distributed system l where two or more processes are making use of the same resource which is required by the other, (for example using the same printer or data), neither can be proceed. This deadlock. situation know as

Distributed system Since Data are exchanged within distributed systems, security must be guaranteed. For example the transmission of data must be received unchanged. l The network design, the kinds of data permitted to be transmitted, and encryption techniques all play a part in ensuring security. l § Human Computer Interaction (HCI) § The usability of a SW system means the ease with which a human can interact with the SW

Ch 1 : Ch 4 Understanding OOP with Java Budd The Software tool that will be used in this module is JAVA. An IDE normally consists of a source code editor, a compiler and/or interpreter, build automation tools, and (usually) a debugger.

Objectives: Set up a directory suitable for your practical work in Java; l create a new project using the IDE; l create a Java source file containing a small class; l compile and execute a Java application; l use the help facility in the IDE. l

Object Oriented Programming An OOP is structured as a community of interacting agents ’object’. Each play a specific role and provide a service that is used by other members of the community. l Object communicate with an object by sending it a message l All message ask an object to perform some action, l In order to make an object do something, you need to send a message to it - in such a situation, we call the object the receiver l

Object Oriented Programming l Objects are organized into classes. Objects belonging to the same class (instances of the class) have the same attributes and respond to the same set of messages, responding to each message in an identical manner. Any initialization of each instance is identical l Objects are all instances of classes

3 main concepts Encapsulation’ ’ﻛﺒﺴﻠﺔ. 2. Inheritance’ ’ﺍﻟﻮﺭﺍﺛﺔ. 3. Polymorphism’ ﺍﻟﺘﻮﺍﺟﺪ ﺑﺄﻜﺜﺮ ﻣﻦ ﺷﻜﻞ Encapsulation 1. Class ’hide a program details • Encapsulates data (attributes) and functions (behavior) into packages called classes • We gather a related methods and the variables that methods affect on one closed capsules called a class, we don’t care of how it work but of what it can do

Inheritance We use this class through one of two ways: 1. Create an instance ’physical implementation for a class details’ which have a memory size and location. 2. Inherited it from another class ‘normal or abstract’ It means building a new class that can have all the features of his parent class and add his own ‘like in real life’. Living things All Humans are Animals Mammals and all Mammals are Animals Mammal And all Animals are Human Living things.

Inheritance l Classes divided in to sub class Vehicles Cars Buses Trucks Abstract class Is the class with no direct instances but use only for creating subclasses

Polymorphism l This is the ability to send the same message to different instances which may appear to perform the same function Polymorphism is a way of : 1. Overload operators. That an operator (+, -, =, &, #, <, ……) can behave in different manners according to its operands. 2. Override methods. That to rewrite the method I used before by another way ‘it can cause binding message’. ﺗﻌﺪﺩ ﺃﺸﻜﺎﻝ ﺍﻟﻜﺎﺋﻦ ﻳﻜﻮﻥ ﺇﻣﺎ ﺑﺘﻐﻴﻴﺮ ﻃﺮﻳﻘﺔ ﻋﻤﻞ ﺍﻟﻤﻌﺎﻣﻞ ﺃﻮ ﺍﻟﺪﺍﻟﺔ ﻣﺜﻞ ﺩﺍﻟﺔ ﺍﻟﺤﺮﻛﺔ ﻓﻔﻲ ﻛﺒﺴﻮﻟﺔ ﺍﻝ Living things ﺫﻛﺮﻧﺎ ﺩﺍﻟﺔ ﺍﻟﺤﺮﻛﺔ ﻟﻜﻦ ﻋﻨﺪ ﺗﺼﻨﻴﻒ ﺍﻟﺤﻴﻮﺍﻧﺎﺕ Animals. ﻧﺠﺪ ﺃﻦ ﺍﻟﺴﻤﻜﺔ ﺗﺘﺤﺮﻙ ﻏﻴﺮ ﺍﻟﺜﻌﺒﺎﻥ ﻏﻴﺮ ﺍﻟﻄﺎﺋﺮ ﻭﻫﻜﺬﺍ

JBuilder will Build the class as shown

Why Java l l l 1. Java is an object oriented language, which consists of a sequence of classes. Jave is case sensitive language, which means there is a differ Java program is either Applet Or Application Java is Simple It eliminate the use of pointers, Go to statement, There is no preprocessor’# define for ex. ’ 2. Java is Object Oriented It use all the object oriented 3. Java is Network Savvy principles It is a client side computing lang, it provide a rich set of tools for programming across the network.

Why Java l Java is Interpreted Java used a virtual machine to interpret the java file into a bytecode ‘machine independent file’, then this bytecode file compiled through a Just In Time compilation process ‘machine dependent’

Why Java l Java is Portable The exact same program can be compiled on one system, then executed on many different types of systems • l l Java is Robust Because of the : - Exception handling. (catch, try) - Automatic memory management ’garbage collection’. The process of destroying objects when there are no references to them in the software system. In certain programming languages, such as Java, this process is automated.

Why Java • Java is Secure It used a security manager that limits the actions of file system accessing, for java lang. array index values are checked for validity before being referenced. • Java is Architecture Neutral Because java bytecode don’t correspond to any particular machine, they work with all machines • Java is High-Performance It executed rapidly, nearly the same run time performance. (JIT)

Why Java • 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

READ THIS QUESTION What is a java source file? It is the java code text file. 2. What is a project (*. jpr) file consists of? It consists of : 1. 2. 3. 4. 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. 3.

Program Structure A class is a programming structure containing a collection of data fields and methods. l Each class has a class header and a class body. l l Class format l Modifier classname // class header { // begin Data fields; Mathods; }// end of the class l l

Program Structure l l l l From above format There are two kinds of modifiers: • Accessing modifiers and Lifetime modifiers. 1. Accessing modifiers are related to whom could access this class, (or data field, method). There are 3 accessing modifiers: • public: It can be accessed form all other classes and instances • private: It can be accessed inside the class itself only. • protected: it can be accessed inside the class and from subclasses instance of inheritance.

Program Structure 2. Lifetime modifiers are related to the duration life of this class, (method or data field). One modifier is used: l • Static: Are created at the beginning of execution and before any objects have been created l static meaning that all instances of this class share this one method. l Note: usually the class name starts with capital letter (e. x: class Student), and the file name must be the same name as the upper class. l The class name and the file which stores it should have the same name

Program Structure Example Public class First. Program { } l A member § Either data field § Or method l Data Fields: these are the instances, variables, or objects l Data fields format: l Modifier type datafeldname declarations ;

Program Structure l Modifier of the data fields is usually private. l Type: there are two kinds, wither primitive data type or a structure one; Primitive data types(starts with small letter) int (for integer) float (for real numbers) double (double precision real) boolean (either true or false) char (short for character) l l l

Program Structure l Structure type: in this case for example the type is a class. Datafiledname: usually reflects what this field represents. (For example grade, average, …) l private int account. Balance = 0; l Methods: are functions or procedures which access the private data fields and do the task it assumed to do.

Program Structure l Method l l l § format: Modifier return_type method_name(arguments) { // begin statements; . . } // end of method A method consists of § Header § Body

Program Structure l l l Modifier of the method is usually public Return type: if the method will not return anything, use void Else write the data or structure type which will be returned such as int, float, … arguments: are parameters holding values and are sent from another method, e. x: (int grade; String name) two arguments are used called grade and name of different type. sometimes the method has not any argument, in this case you insert empty parentheses ( ).

Program Structure Statements: could be for example: Input statement: Output statement: System. out. println("hello") ) Data fields declarations: int x; Assignment statement: x = 5; Mathematical expression: x = x * 2 + 10; Control statement: change the execution sequence of execution: l If statement: if (x > 10)… l Repetition: while (x<=5). . l l l l

Program Structure l l l l l Example of a simple Java program to display: Hello to Java. import java. lang. *; // this is java library used to recognize the output statement public class Hello. World { public static void main(String [] args) // main method header { System. out. println("Hello to Java"); }//main } // class

2. The Connection of The Java World § Import java. lang. *; This statement makes a portion of the java library (API Application Programmers Interface), which is visible to the class description that follows it § The java API is only available when the user explicitly requests them § The class (System) is defined in the package (java. lang) § System. out. println("Hello World!"); l Print a single line of output on a standard output (output console). In the above statement, System is a class, out is a data field and println is a method. l

2. The Connection of The Java World One of data members held by (System) is out, which holds various features associated with output § Println, is a behaviour provided by (out) § Println, takes as argument a text string, & uses the argument to print a single line of output on a standard output area (often called the output console) § Syste. out. println (“My first java program!”); §

Main method l l l when the execution of the program starts, the loader will search for a method called main to start the execution from that point. The main method header must exactly the same as the one shown in the example. public static void main(String [] args) // main method header { System. out. println("Hello to Java"); }//main

Main method § § § The static members are shared by all instances of a class. The static member exist no matter how many instances are created. A static member exist even if no instances created yet. Main method should be static. Main method must exist before any instances of the class.

Arrays in Java First value starts from 0 e. g. array called name, elements of type String l l June 0 l l Barry 1 Ken Sue 2 3 Ahmed Jerry 4 Name [0] refers to the string June Name[4] = “Ali” Replace Ahmed with Ali An Array has a fixed number of elements l l l Examples: int primes[]={2, 3, 5, 7, 11, 13, 17, 19}; Primes[3]=primes[2]+2; 5
![Arrays in Java e. g. Public static void main (string [ ] args) { Arrays in Java e. g. Public static void main (string [ ] args) {](http://slidetodoc.com/presentation_image_h2/5979606f5191b015dc1b39a1a6946295/image-50.jpg)
Arrays in Java e. g. 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 l We pass any command line arguments to the method in an array of Strings called args. §

If Statement l l l if (boolean expression ) { Sequence-of-statements } else { sequence-of-statements }

Exp 2 import java. lang. *; public class Second. Program { public static void main (String [ ] args) { if (args. length > 0) System. out. println (“Hello” + args [0]); else System. out. println (“Hello everybody!”); }} l Here, the data member length is being used to determine the number of values held by the array named args. l If the user entered a command line argument, such as the string “Arab", the output will be "Hello Arab".

Exp 2 The index values for an array in Java begin with zero and extend to the value one smaller than the number of elements in the array. l The operator + is used for string concatenation when at least one argument is a String. l When at least one argument to the ‘+’ operator is String then other argument is automatically string l

Small Java Code Data Field class Bank. Account { private int account. Balance = 0; Method public void deposit (int amount){ account. Balance = account. Balance + amount; } Public void withdrawal (int amount){ account. Balance = account. Balance – amount; } A data field named account. Balance which is initialized to zero. l • Two methods named deposit and withdrawal. l

Creating an instance of the Class Creating an Object <object name>= new <class name> (argument) l In another class you could create a Bank. Account object and call/invoke methods on it, for example: l Bank. Account my. Account = new Bank. Account(); l Note: In Java = acts in the same way as : = in Smalltalk. l l The result of the above Java statement is shown below.

How to send a message to an object (invoke/call a method on that object) l Since every instance of the class Bank. Account will have such a data field, it is known as an instance variable.

How to send a message to an object (invoke/call a method on that object) The full stop between the variable identifier and the method name is known as the dot notation which is used to denote sending a message to an object. When a message is sent to an object, the corresponding method is executed (or called). l Note: In Java, we usually say a method is called rather that a message is sent to an object. l my. Account. deposit (100); my. Account. withdrawal (30); my. Account. withdrawal (26); n. What is the values of Balance?

Assignment statement with variables referencing objects This implies that the object would be updated in exactly the same way by either my. Account. deposit(50); or your. Account. deposit(50); Having two (or more) variables reference the same object is known as aliasing and must be used with care.

GIVE OUT PUT Bank. Account my. Acc 1 = new Bank. Account(); Bank. Account my. Acc 2 = new Bank. Account(); my. Acc 1. deposit(100); my. Acc 2 = my. Acc 1; my. Acc 1. deposit(50); my. Acc 2. deposit(50); l (account. Balance=44)

Primitive data types VS Classes in Java l In the case of objects, variables are used to refer to objects as illustrated in the previous figure. Java does not use the reference mechanism for variables of primitive data type. Instead, the values are stored in the variable itself. Now to demonstrate the difference further, suppose i = 1 and j = 4, then the assignment statement i = j; Results in i = j = 4. However, both variable (i and j) are independent. So, if we apply the following statement i = 2; Then j will remain 4.

Primitive data types VS Classes in Java l In the case of objects, variables are used to refer to objects as illustrated in the previous figure. Java does not use the reference mechanism for variables of primitive data type. Instead, the values are stored in the variable itself. Now to demonstrate the difference further, suppose i = 1 and j = 4, then the assignment statement i = j; Results in i = j = 4. However, both variable (i and j) are independent. So, if we apply the following statement i = 2; Then j will remain 4.

Variables and declarations l Each variable should be declared as having a particular type (either a class or a primitive data type) this is why Java is called a strongly typed langauge. Examples: private int account. Balance = 0; Bank. Account my. Account = new Bank. Account () ; String [ ] args; int amount;

Conceptual vs. implementation view of a solution Thinking about how to solve a problem that involves understanding the problem (or application) domain which has nothing to do with programming languages, a process that leads to what we describe as the conceptual view of the solution. l Implementing the solution to a problem in a particular programming language that requires a knowledge of the syntax and semantics of that language, a process that leads to what we describe as the implementation view of the solution. l

Types, abstract data types and classes l l l l Type is a word given to a named set of items having some property in common. Behaviour stands for collection of operations in which the elements of a set can participate. An abstract data type (ADT) is a set of items defined by the collection of operations that can be carried out on them. The elements of such a set are usually referred to as values. Example of an ADT is a set of bank accounts. All the instances of this set will respond to the same operations (e. g. get. Balance, set. Balance, withdraw. Amount, transfer. Amount). The word ‘class’ has several meanings and there are three we are interested in: a class is an implementation of an abstract data type; a class is a programming structure containing a collection of data fields and methods; a class is a set of objects

Actual argument Formal argument my. Account. deposit(100); In the message deposit(100), the value 100 is known as an actual argument which, when the method deposit is invoked, is assigned to the formal argument , amount, appearing in the method heading. During the execution of the body of deposit, the formal argument amount acts as a local variable. l A method Signature defines everything you need to know about a method to call it, i. e. its modifiers, return type, name, and parameters. l l
- Slides: 65