Test

Views:
 
Category: Education
     
 

Presentation Description

test

Comments

Presentation Transcript

M301: Software Systems & their DevelopmentThe Material is Prepared by: Dr. Mohamed OmranEdited, Designed, and Converted to PPT by: Yaser Al-Mtawa : 

M301: Software Systems & their DevelopmentThe Material is Prepared by: Dr. Mohamed OmranEdited, Designed, and Converted to PPT by: Yaser Al-Mtawa

M301: Software Systems & their Development Block 1: Introduction to Java Unit 1: Introduction and the IDE Section 1: Introduction to the course Aims of the course: · Enable you to read programs written in Java and to amend or extend existing software systems in response to new requirements, particularly in the area of networked systems; · Describe the major features of modern concurrent (distributed) systems; · Illustrate the use of the Unified Modelling Language (UML) in the analysis of new requirements in relation to existing solutions; · Analyze existing systems to identify their major architectural principles and software mechanisms, and to describe how they work both in isolation and together; · Introduce the development of software systems using an object-oriented approach with associated management practices. : 

M301: Software Systems & their Development Block 1: Introduction to Java Unit 1: Introduction and the IDE Section 1: Introduction to the course Aims of the course: · Enable you to read programs written in Java and to amend or extend existing software systems in response to new requirements, particularly in the area of networked systems; · Describe the major features of modern concurrent (distributed) systems; · Illustrate the use of the Unified Modelling Language (UML) in the analysis of new requirements in relation to existing solutions; · Analyze existing systems to identify their major architectural principles and software mechanisms, and to describe how they work both in isolation and together; · Introduce the development of software systems using an object-oriented approach with associated management practices.

Course structure: Block 1 of the course concentrates on building software components. It shows you the fundamentals of creating objects and building systems from them. We shall introduce you to the basics of Java as a means of illustrating the concepts involved. The existence of communicating distributed software implies that there are separate sequential programs executing simultaneously (we use the term concurrent processes to describe such a situation). In Blocks 2 and 3 you will study the ramifications of concurrency in software systems. You can think of these blocks as providing the theoretical basis of distributed software. Blocks 4 and 5 turn to the issues that arise in the process of developing software. These two blocks may be considered as providing the practice of software development. Block 6 brings together the theory and practice, and provides you with the opportunity of putting what you have learned into practice via a small project based on a case study that you will have followed throughout the course Read: Section 1.1 from Block 1 : 

Course structure: Block 1 of the course concentrates on building software components. It shows you the fundamentals of creating objects and building systems from them. We shall introduce you to the basics of Java as a means of illustrating the concepts involved. The existence of communicating distributed software implies that there are separate sequential programs executing simultaneously (we use the term concurrent processes to describe such a situation). In Blocks 2 and 3 you will study the ramifications of concurrency in software systems. You can think of these blocks as providing the theoretical basis of distributed software. Blocks 4 and 5 turn to the issues that arise in the process of developing software. These two blocks may be considered as providing the practice of software development. Block 6 brings together the theory and practice, and provides you with the opportunity of putting what you have learned into practice via a small project based on a case study that you will have followed throughout the course Read: Section 1.1 from Block 1

Block 1: Introduction to Java Unit 1: Introduction and the IDE Section 2: Introduction to the Integrated Development Environment (IDE) Objectives: · Set up a directory suitable for your practical work in Java; · create a new project using the IDE; · create a Java source file containing a small class; · compile and execute a Java application; · use the help facility in the IDE. IMPORTANT: Read Section 1.2 from Block 1 and do the practical activities : 

Block 1: Introduction to Java Unit 1: Introduction and the IDE Section 2: Introduction to the Integrated Development Environment (IDE) Objectives: · Set up a directory suitable for your practical work in Java; · create a new project using the IDE; · create a Java source file containing a small class; · compile and execute a Java application; · use the help facility in the IDE. IMPORTANT: Read Section 1.2 from Block 1 and do the practical activities

Block 1: Introduction to Java Unit 1: Introduction and the IDE Section 3: First Program in Java Objectives: · understand some of the basic Java constructs needed to create a simple executable Java program, which includes the structure of a program, a class, a method, a data field, and the use of modifiers; · describe the role of the mainmethod when a Java program is executed; · describe the model of execution of a Java program including the roles of variables and method invocation (or message passing); · understand the need for, and how to write, declarations; · understand the difference between types, abstract data types and classes. Book reference: Chapter 4 of Understanding Object-Oriented with JAVA by Budd. : 

Block 1: Introduction to Java Unit 1: Introduction and the IDE Section 3: First Program in Java Objectives: · understand some of the basic Java constructs needed to create a simple executable Java program, which includes the structure of a program, a class, a method, a data field, and the use of modifiers; · describe the role of the mainmethod when a Java program is executed; · describe the model of execution of a Java program including the roles of variables and method invocation (or message passing); · understand the need for, and how to write, declarations; · understand the difference between types, abstract data types and classes. Book reference: Chapter 4 of Understanding Object-Oriented with JAVA by Budd.

Slide 6: 

A java application is a computer program that executes when you use the JAVA command to launch the Java Virtual Machine (JVM) public class Welcome1 { public static void main( String args[ ] ) { System.out.println( “Welcome to JAVA Programming !” ); } } To compile: javac Welcome1.java This will create a file called Welcome1.class - (the class file) contains the byte codes representing the application executing by JVM To execute: java Welcome1 will launch the JVM which loads the ( . class ) files C:\JavaExample\cho2\UNIT1 > java Welcome1 Welcome to JAVA Programming ! Do Not Type

Objects, classes and calling methods in Java Consider the following simple example of a Java class named BankAccount: Class BankAccount { private int accountBalance = 0; public void deposit (int amount) { accountBalance = accountBalance + amount; } public void withdrawal (int amount) { accountBalance = accountBalance - amount; } } This class contains three members: · A data field named accountBalance which is initialized to zero. · Two methods named deposit and withdrawal : 

Objects, classes and calling methods in Java Consider the following simple example of a Java class named BankAccount: Class BankAccount { private int accountBalance = 0; public void deposit (int amount) { accountBalance = accountBalance + amount; } public void withdrawal (int amount) { accountBalance = accountBalance - amount; } } This class contains three members: · A data field named accountBalance which is initialized to zero. · Two methods named deposit and withdrawal

Sending messages to the object In another class you could create a BankAccount object and call/invoke methods on it, for example: BankAccount myAccount = new BankAccount(); Note: In Java = acts in the same way as := in Smalltalk. The result of the above Java statement is shown below. Since every instance of the class BankAccountwill have such a data field, it is known as an instance variable. Once the object referenced by myAccount has been created, messages can be sent to it. For example, to add 100 to the accountBalance of the object referred to by myAccount, you would write: myAccount.deposit(100); Also, to withdrawal 30 from the accountBalance of the object referred to by myAccount, you would write: myAccount.withdraw(30); : 

Sending messages to the object In another class you could create a BankAccount object and call/invoke methods on it, for example: BankAccount myAccount = new BankAccount(); Note: In Java = acts in the same way as := in Smalltalk. The result of the above Java statement is shown below. Since every instance of the class BankAccountwill have such a data field, it is known as an instance variable. Once the object referenced by myAccount has been created, messages can be sent to it. For example, to add 100 to the accountBalance of the object referred to by myAccount, you would write: myAccount.deposit(100); Also, to withdrawal 30 from the accountBalance of the object referred to by myAccount, you would write: myAccount.withdraw(30);

Aliasing Let the following statements. BankAccount yourAccount ; (Declaration Statement) yourAccount = myAccount; (Assignment Statement) This implies that the object would be updated in exactly the same way by either myAccount.deposit(44); or yourAccount.deposit(44);Having two (or more) variables reference the same object is known as aliasing and must be used with care. : 

Aliasing Let the following statements. BankAccount yourAccount ; (Declaration Statement) yourAccount = myAccount; (Assignment Statement) This implies that the object would be updated in exactly the same way by either myAccount.deposit(44); or yourAccount.deposit(44);Having two (or more) variables reference the same object is known as aliasing and must be used with care.

Primitive data types and classes in Java * Primitive data types are: - int (for integer) - float (for real numbers) - double (double precision real) - boolean (either true or false)- char (short for character) * Classes are program constructs containing methods and data fields whose definitions can be inspected by the programmer. Primitive data types vs. Classes 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. This is illustrated in the following figure. : 

Primitive data types and classes in Java * Primitive data types are: - int (for integer) - float (for real numbers) - double (double precision real) - boolean (either true or false)- char (short for character) * Classes are program constructs containing methods and data fields whose definitions can be inspected by the programmer. Primitive data types vs. Classes 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. This is illustrated in the following figure.

Now to demonstrate the difference further, suppose i = 1 and j = 4, then the assignment statement i = j; Results 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 Java is a strongly typed language in the sense that every variable must be declared as having a particular type. That is, every variable must appear in a declaration in which the class of the objects to which it may refer or the primitive data type of the values it contains must be stated explicitly. In a strongly typed language, a given variable is allowed only to refer to an object or value of its declared type. Examples of Java declarations are:private int accountBalance = 0;int amount;BankAccount myAccount = new BankAccount();String [] arges;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.* 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. : 

Variables and Declarations Java is a strongly typed language in the sense that every variable must be declared as having a particular type. That is, every variable must appear in a declaration in which the class of the objects to which it may refer or the primitive data type of the values it contains must be stated explicitly. In a strongly typed language, a given variable is allowed only to refer to an object or value of its declared type. Examples of Java declarations are:private int accountBalance = 0;int amount;BankAccount myAccount = new BankAccount();String [] arges;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.* 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.

DefinitionsType is a word given to a named set of items having some property in common.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 willrespond to the same operations (e.g. getBalance, setBalance, withdrawAmount, transferAmount).A class is a collection of objects and the objects are defined by a set of methods that correspond to the operations of the ADT.A method is a small part of a program that is supplied with some objects (or values of primitive data type) called arguments, and whose purpose is to perform a computation, possibly producing an object (or a value of a primitive data type) as its result. : 

DefinitionsType is a word given to a named set of items having some property in common.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 willrespond to the same operations (e.g. getBalance, setBalance, withdrawAmount, transferAmount).A class is a collection of objects and the objects are defined by a set of methods that correspond to the operations of the ADT.A method is a small part of a program that is supplied with some objects (or values of primitive data type) called arguments, and whose purpose is to perform a computation, possibly producing an object (or a value of a primitive data type) as its result.

Summary of Chapter 4Consider the following Java programimport java.lang.*;public class FirstProgram { public static void main (String [] args) { System.out.println("Hello World!"); }}modifiers return-type method-name (arguments) {sequence-of-statements}Access ModifiersThe three access modifier keywords and their purposes are:public: the data field, method or class to which it is applied is visible to, i.e. available to be used by, all objects of all other classes in addition to the class in which it is defined;private: the data field, or method to which it is applied is not visible to objects of classes outside the class in which it is defined, including subclasses;protected: the data field, or method to which it is applied, is not visible to other objects outside the class in which it is defined, but it is visible to any subclass (derived class) of that class. : 

Summary of Chapter 4Consider the following Java programimport java.lang.*;public class FirstProgram { public static void main (String [] args) { System.out.println("Hello World!"); }}modifiers return-type method-name (arguments) {sequence-of-statements}Access ModifiersThe three access modifier keywords and their purposes are:public: the data field, method or class to which it is applied is visible to, i.e. available to be used by, all objects of all other classes in addition to the class in which it is defined;private: the data field, or method to which it is applied is not visible to objects of classes outside the class in which it is defined, including subclasses;protected: the data field, or method to which it is applied, is not visible to other objects outside the class in which it is defined, but it is visible to any subclass (derived class) of that class.

Lifetime Modifiersstatic data field signifies that the data field is shared by all the objects of the class. A static variable is also known as a class variable to distinguish itfrom a non-static variable known as an instance variable because each object has itsown copy of the instance variable.Note that a static member, be a method or a data field, exists even if no objects of itsclass have been created. Consequently, like the method main, which is alwaysdeclared static, all static members are available for use when a program startsexecuting, and before any objects have been created.Exercise:Why do you think that the main method should always be public and static? (read Budd, pp. 62). : 

Lifetime Modifiersstatic data field signifies that the data field is shared by all the objects of the class. A static variable is also known as a class variable to distinguish itfrom a non-static variable known as an instance variable because each object has itsown copy of the instance variable.Note that a static member, be a method or a data field, exists even if no objects of itsclass have been created. Consequently, like the method main, which is alwaysdeclared static, all static members are available for use when a program startsexecuting, and before any objects have been created.Exercise:Why do you think that the main method should always be public and static? (read Budd, pp. 62).

authorStream Live Help