1 / 48

F21SF Software Engineering Foundations

1 INTRODUCTION. Dept of Computer Science. F21SF Software Engineering Foundations. Monica Farrow EM G30 email : M.Farrow@hw.ac.uk Material available on Vision. Topics. Introduction to the course Topics Resources Course organisation, including assessment Permitted collaboration

bryce
Download Presentation

F21SF Software Engineering Foundations

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.

E N D

Presentation Transcript


  1. F21SF SEF L2 1 INTRODUCTION Dept of Computer Science F21SFSoftware Engineering Foundations Monica Farrow EM G30 email : M.Farrow@hw.ac.uk Material available on Vision

  2. F21SF SEF L2 Topics • Introduction to the course • Topics • Resources • Course organisation, including assessment • Permitted collaboration • A first java program • Structure • IDE

  3. F21SF SEF L2 INTRODUCTION

  4. F21SF SEF L2 Introduction to the course • This course is for students who’d like to learn object oriented programming using java • One course can’t cover everything • By the end, you should be competent to find out more for yourself • It assumes you have done at least a little programming before • It is a pre-requisite for Advanced Software Engineering in Java (semester 2) • A course timetable is provided on Vision

  5. F21SF SEF L2 Course Topics • Object-oriented design and programming • Classes, objects, inheritance, interfaces • UML (Unified Modeling Language) diagrams • Basic programming concepts • Sequence, selection, repetition • Arrays – java basic array, and ArrayLists • Introduction to Graphical User Interfaces • Testing

  6. F21SF SEF L2 Why Java? • Platform independent • The same code can be run on any processor and any operating system • Modern object-oriented programming language • Currently the most widely accepted style for programs • There is an extensive collection of existing classes in library packages • Called the Java API (Application Programming Interface) • Can be used to produce various types of applications, such as • Desktop applications • Applets (applications embedded in web page) • Server-side application to produce dynamic web pages • Mobile phone applications

  7. F21SF SEF L2 What is (the) UML? • Unified Modeling Language • A language for specifying, visualising and constructing the descriptive diagrams and documentation of software system • A family of mainly graphical notations • “a picture is worth 1000 words” • Helps in designing and describing software systems, particularly object-oriented systems • Industry standard for object-oriented modelling • This course includes an introduction to UML

  8. F21SF SEF L2 Resources • These notes are intended to provide the essentials of the topics covered, but it is always useful to refer to other sources as well • To clarify and to deepen your understanding • As a reference for fine detail • Here are some recommended books and websites that you might find useful • Buying a book is not compulsory for this course

  9. F21SF SEF L2 Java Book • Head First Java by Kathy Sierra and Bert Bates • The book is a good fit for this course • It’s quite entertaining, with lots of activities • It is rather ‘American’ – look first to see if you like the style at • http://oreilly.com/catalog/9780596009205/

  10. F21SF SEF L2 Web resources on java • Java API (version 7) – essential reference for library classes • http://docs.oracle.com/javase/7/docs/api/index.html • Use these when you need extra information: • Java sun tutorials • http://docs.oracle.com/javase/tutorial/reallybigindex.html • Beginning java tutorials • http://www.javabeginner.com/ • Leepoint for reference • http://www.leepoint.net/notes-java/index.html • Electronic books • Intro by David Eck http://math.hws.edu/javanotes/index.html • Thinking in Java http://mindview.net/Books/TIJ4

  11. F21SF SEF L2 UML Books • There are many good books on UML, such as • UML Distilled Third Edition • A Brief Guide to the Standard Object Modeling Language by Martin Fowler • Addison Wesley ISBN 0-321-19368-7 • Mentions UML 2 • Chatty, compact, with advice from experience • Learning UML2.0 • By Russ Miles and Kim Hamilton • O’Reilly ISBN 0-596-00982-8 • Also Safari books online • http://my.safaribooksonline.com/book/software-engineering-and-development/uml/0596009828

  12. F21SF SEF L2 Web resources on UML • I recommend • Introduction to the diagrams of UML2 by Scott Ambler • http://www.agilemodeling.com/essays/umlDiagrams.htm • Contains a summary table and a page description for each diagram • The full specification is on the OMG website, but is very detailed and not very user-friendly.

  13. F21SF SEF L2 Assessment • You final mark comes from 2 components • 60% - 2 hour exam in December • 40% coursework consisting of 2 assignments using: • Several classes, arrays, ArrayLists (20%) • Additionally Inheritance & Graphical User Interface (20%) • If you fail this course, you will be reassessed with a 2 hour exam in August. Your final mark then just comes from this exam, not from the coursework.

  14. F21SF SEF L2 Lectures and labs • 3 lectures per week • 1 2-hour lab per week • Work on suggested exercises and assessed exercises, get help from lecturer or lab helpers • Leaves 5 hours spare for own study • Read over lecture notes, understand sample programs, read books/web, work on assessed exercises

  15. F21SF SEF L2 Lecture contents • The lecture slides are intended to be complete enough so that you can read through them easily. And so nothing is forgotten. • During lectures, I might cover the material on several slides whilst pointing to a particular diagram or code. • I expect you to read over the lecture afterwards, and look at the code examples, to reinforce the ideas introduced in the lectures.

  16. F21SF SEF L2 Lab sessions • Just read through the lectures before the first lab, which is just an introduction. • The other lab sessions are a time for getting help because • Either you don’t understand part of a lecture or the associated code or exercises • Or you are stuck with part of an assignment • So • Read through each lecture and study the associated code • Work on suggested exercises and on the assignments outside the lab sessions, so that you know what your problems are • Continue this work in the lab session, so you can ask if you need to

  17. F21SF SEF L2 Lectures and assignments • No “Re-inventing the wheel” • We’re not asking you to have great leaps of creative imagination in the assignments • All the techniques that you need are presented in the lectures and associated sample classes • It is your task to apply those algorithms and code fragments in the assignments

  18. F21SF SEF L2 Time management • Work outside lab sessions and come with questions • Ask questions in a lecture if you don’t understand – you WILL NOT be the only one! • Don’t get behind, and don’t leave assignments til the last minute, because. . .

  19. F21SF SEF L2 Programming • Programming is • Time-consuming • When things work, it is very rewarding • When things don’t work, it can be VERY frustrating. • DO NOT spend hours on a problem if you get stuck • Stop and do something else – work for another module, relax, etc • Your subconscious may carry on working on the problem and a solution may dawn on you in the shower, on the bus etc • If you’re really confused, an extra 3 hours puzzling over the problem isn’t going to help

  20. F21SF SEF L2 Collaboration • You are welcome to • Discuss the lectures and assignments with other people. It’s a good way of making sure you understand • Help each other with problem code. Often talking through your code with another person makes you see the mistake. Finding where others have gone wrong or need an explanation reinforces your own understanding

  21. F21SF SEF L2 Plagiarism • You should NOT take code written by others and submit this as your own work • Submitting the work of others without acknowledging it is plagiarism, which can result in serious academic penalties for yourself, and also for the other person, if they are a student. • If you have been shown a few lines of code by another person, or found a block of code on the web or in a book, please acknowledge this with a comment in your code. This is ok • If you submit a complete program, or the majority of a program, which has been written by others, without acknowledgment, this is plagiarism.

  22. F21SF SEF L2 A first java program

  23. F21SF SEF L2 Define Program Idea Compile – check for syntax errors and create Executable file Create source code using text editor Run the program (Execute the code) Edit source code Program Development This UML activity diagram shows the action sequence when writing a typical program. The conditions (in square brackets) show when a particular path is followed. Diamonds are for decisions and merges. [run time error] [compilation error] [ok] [ok]

  24. F21SF SEF L2 Java is multi-platform Java has an extra stage – producing byte code. JVM : Java Virtual Machine : a system program that runs on any platform and translates byte code into machine-language instructions for that platform Source code (.java file) Java Compiler Byte code for the JVM (.class file) Interpreted for a Mac Interpreted for Sun Interpreted for PC Executable Instructions for Sun Executable Instructions for PC Executable Instructions for a Mac

  25. F21SF SEF L2 Source code • We write source code, in Java. • The source code is divided into classes, and is saved with the extension java. All Java programs consist of classes. Most have more than one. • For instance, a class called First would be stored in a file called First.java

  26. F21SF SEF L2 Minimal program outline Class Header public class ClassName { public static void main(String[] arg) { Statements; } } main Method Header Each statement ends with ; Solution to problem Curly brackets enclose class and method

  27. F21SF SEF L2 methods • In java, code statements are organised into self-contained logical blocks called methods • In another programming language these might be called subroutines, functions or procedures • All java programs must have one method called main, which is where the program starts. • In an object-oriented design, all code of importance is placed into classes, so the main method should ONLY be used to • Kick-start a program • To test a program or class

  28. F21SF SEF L2 The main method - signature • When it runs a program, the JVM looks for a method that has this signature (i.e. heading line): • public static void main (String[] args) • public – any other class can access it • static– class method – discussed later • void – there will be no return value • main – the name of the method • String[] args – for optional run-time parameters(discussed later)

  29. F21SF SEF L2 A first minimal program public class First { public static void main (String[] args) { //print a message String name = "Monica"; System.out.println("Hello " + name); } //end main method } //end class

  30. F21SF SEF L2 Notes on the First program • Single line comments start with // • Curly brackets enclose the class and the method • First one can be placed either at the end of the method header line or at the start of the next line • More books and examples seem to place the bracket at the end of the header line • However, if it is at the start of the next line, it’s easier to visually see that the brackets match up! • Indentation of classes and methods, as shown, is important • By convention, for human readability

  31. F21SF SEF L2 Statements in the method body • The action happens in the statements contained in the method body (i.e. between the curly brackets) • The First program contains 2 statements • the first declares a variable calledname and assigns it a value • The second uses the java println method to print the details which are supplied in the rounded brackets (the parameter) to standard output • In this case, the text ‘Hello’ is combined with the value contained in the name variable • Hello Monica

  32. F21SF SEF L2 Variables and Data types • Data is stored in named variables which must be declared before use by specifying a type and a name • Type determines what kind of value can be held. • E.g. String for text, int for integers etc • Today, you can think of a variable as a named box which contains a value name "Monica"

  33. F21SF SEF L2 Class and primitive data types • In java, data types are classified like this: • Primitive data types, not derived from anything else • Integers have type int, long, short, byte • Real numbers have type double, float • Other primitive types are boolean, char • Class data types • Text is stored as a String, which is a special class • Classes that we write ourselves e.g. Car, Person, … • Other existing java classes

  34. F21SF SEF L2 Assignment • E.g. String name = "Monica"; • = is the assignment operator • An assignment is NOT an equation • In an assignment, the value of the expression on the right hand side is given to the variable on the left hand side • number = 12; • result = x * x + x / y; • An assignment is a statement

  35. F21SF SEF L2 Statements can consist of ... • Variable declarations (this variable will be used later) • double x; • Assignments (store value in the variable) • x = 16.43; • Variable declaration plus assignment • double x = 16.43; String name = "Anna"; • Method calls (do this) • System.out.print ("Hello " + name); • Method calls plus assignment of the method’s return value (get this) • Calendar today = Calendar.getInstance();

  36. F21SF SEF L2 Parameters • Actual parameters, within parentheses at the end of the method call, are the values used when the method is executed. • Parameters can be • Variables, which contain a value • E.g. println(name) • or Literals, which are values not stored in a variable • E.g. println("In the beginning.. ") • or Expressions, which need to be evaluated first before they can be used • E.g.println("Hello " + name )

  37. F21SF SEF L2 Running a java program • If you have java installed on your computer, you can run a java program using a command window • Create the .java file using a basic text editor e.g. Wordpad, or a java-aware editor (e.g. GEdit, JEdit..) • Compile using the command javacto produce a .class fileE.g. javac First.java • Run using the command java(interprets and runs)E.g. java First

  38. F21SF SEF L2 Screenshot of a run there is only a .java file to start with compile, successful if no errors shown Now there is also a .class file run Message printed to standard output

  39. F21SF SEF L2 Errors • Your program may have 2 types of error • Syntax errors, found at compilation time • Something in your program isn’t correct java. For example, missing semi-colon, missing brackets, invalid statement. The compiler can’t understand and makes a guess at a suitable error message. These messages are often useful, sometimes rather obscure. • Logic error, found at runtime • The compiler understood your program but the program doesn’t do what you wanted. For example, you misspelled part of a printed message, or got a calculation wrong. Or your program might crash if it is trying to do impossible operation – examples later.

  40. F21SF SEF L2 Error quiz • Find the errors – syntax or logic? • public class First { • public static void mainMethod (String[] args) • print a message • String name is "Monica"; • System.out.println("Hello" + name); • } //end main method • } //end class

  41. F21SF SEF L2 Integrated Development Environments • To create a program, we need at least • A text editor, a java compiler, the JVM • An integrated development environment provides at least these facilities, plus many others such as those shown on the next slide • A little more complicated for beginners, but worth the effort • In this course, we recommend using the industry standard open source IDE eclipse • Another open source IDE is netbeans

  42. F21SF SEF L2 IDE Screenshot

  43. F21SF SEF L2 Some IDE features • Menus and toolbars for common actions • Syntax highlighting • Debugger -step through your code a line at a time, checking variable values • Automatic code completion • Compilation errors shown in real time, with suggested corrections • Highlights unreachable code, unused variables • Reformats incorrect indentation • Supports code refactoring (renaming or dividing up long methods)

  44. F21SF SEF L2 src bin Separate folder for source and binary • It’s good practice to separate the source from the class files • In eclipse, this is an option when creating a new project Project / parent dir myProg .java files .class files

  45. F21SF SEF L2 Packages • You can organise your java classes into packages • Packages are not covered in this module • We will store everything in the same ‘default’ package • If you do organise your classes into packages, the first line of each class must name the package • You might see this in other code examples • It might happen automatically depending on how you use the eclipse wizards. • E.g. package myprog;

  46. F21SF SEF L2 To Do Now • Read over this lecture • If these ideas are new to you, try the quiz on the next slides • Wait until after the next lecture before trying to actually run a java program. • Next lecture – a first object oriented program

  47. F21SF SEF L2 Quiz on basic programming concepts • Here is a small java program: • public class Add2Nums { • public static void main (String[] args) { • //add 2 numbers • int num1 = 4; • int num2 = 6; • int sum = num1 + num2; • System.out.println (sum); • } • } • Questions appear on the next slide

  48. F21SF SEF L2 Quiz contd • What is the name of this class? • Which lines are statements? • Which lines are assignments? • Where is a parameter? • Name the variables used in this program • What do you think would happen if I changed: • line 4 to int num1 = 4.5; • line 7 to System.out.println (num1 + num2); • line 2 to public void main () • line 3 to add 2 numbers

More Related