1 / 58

S E 3 60 Advances in Software Development

S E 3 60 Advances in Software Development. Asst . Prof.Dr . Senem Kumova Metin. Introduction. Instructor : Dr. Senem Kumova Metin Email: senem. kumova @ ieu.edu.tr Room: 3 12 Course website: http://homes.ieu.edu.tr/ skumova You have to c heck website regularly for

Download Presentation

S E 3 60 Advances in Software Development

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. SE 360Advances in SoftwareDevelopment Asst.Prof.Dr. Senem Kumova Metin

  2. Introduction Instructor : Dr. Senem Kumova Metin Email: senem.kumova@ieu.edu.tr Room: 312 Course website:http://homes.ieu.edu.tr/skumova Youhaveto check website regularly for announcements,homeworks, course slides and projects

  3. Assignments Labs and Project • Starting next lecture, there will be 1 hour labtime. Bring your laptops!!! • In the second part you will do a courseproject, in Java. • Start thinking about your project now!!! • I leave the topic up to you. • Up to 2 people per group.

  4. Syllabus

  5. Classification of HighlevelProgramminglanguages • Programming paradigm : Alternative approaches to the programming process • Imperative (Procedural) (Fortran, Algol, Pascal, Basic, C) • Functional (Lisp, ML) • Declarative(Logic) (Prolog,GPSS) • Object-Oriented (C++, Java, Scala, Smalltalk)

  6. Programming Languages 1/2 • Imperative: The language provides statements, such as assignment statements , which explicitly change the state of the memory of the computer. X:=X+1 • Functional: In this paradigm we express computations as the evaluation of mathematical functions. (defun factorial (n) (if (<= n 1) 1 (* n (factorial (- n 1))))) The program can then be called as (factorial 10)

  7. Programming Languages 2/2 • Logic (Declarative): In this paradigm we express computation in exclusively in terms of mathematical logic brother(X,Y) /* X is the brother of Y */ :- /* if there are two people F and M for which*/ father(F,X), /* F is the father of X */ father(F,Y), /* and F is the father of Y */ mother(M,X), /* and M is the mother of X */ mother(M,Y), /* and M is the mother of Y */ male(X). /* and X is male */ uncle (X,Y) :- father(F,Y), brother(X,F). • Object-Oriented: In this paradigm we associate behavior with data-structures called " objects " which belong to classes which are usually structured into a hierarchy

  8. What exactly is an object? • An OBJECT is an identity which includes both Attributes and Behaviors EXAMPLE -- > PERSON OBJECT Attributes : Eye Color, Age, Height … Behaviors : Walking, Talking, Breathing …

  9. TheObject Model • A OO-software system is a set of cooperating objects • Objects have state and processing ability • Objects exchange messages

  10. Class and Object • A class is a collection of objects that have common properties, operations and behaviors. • A class is a data type, objects are instances of that data type.

  11. Object Oriented Programming • A programming paradigm that uses abstraction (in the form of classes and objects) to create models based on the real world environment. • An object-oriented application uses a collection of objects, which communicate by passing messages to request services. • Objects are capable of passing messages, receiving messages, and processing data. • The aim of object-oriented programming is to try to increase the flexibility and maintainability of programs. Because programs created using an OO language are modular, they can be easier to develop, and simpler to understand after development.

  12. Java • Main topic of the course is Object OrientedConcepts • The implementation will be done in Java • You will learn Java, and use it in the project • I will use Eclipse as the Java IDE • Free IDE, highly popular • Easy to use • The resource links are given in course web page

  13. What is Java • Java is a high level programming language • Uses a virtual machine • Means your code is compiled for the VM and works in any architecture or OS (byte code • Performance penalty due to VM instead of native applications • You can write applications or applets usingJava Applet is a Java program thatworks on web pages.

  14. Click on link to Applet Byte code is downloaded Java: Write Once, Run Anywhere • Consequence of Java’s history: platform-independence Mac user running Safari Web page stored on Unix server Virtual machine translates byte code to native Mac code and the Applet is run Windows user running Internet Explorer Byte code (part of web page) From slides of James Tam

  15. Click on link to Applet Byte code is downloaded Java: Write Once, Run Anywhere • Consequence of Java’s history: platform-independent Mac user running Safari Web page stored on Unix server Windows user running Internet Explorer Virtual machine translates byte code to native Windows code and the Applet is run From slides of James Tam

  16. What is Java • If you are a C/C++ programmer, Java iseasier to code • No pointers • Has a garbage collection mechanism • Built in security • Java is object oriented

  17. A short history for Java The invention of the microprocessor revolutionized computers (fromhugecomputerstosmallerones ) Thenextlogical step for microprocessors was to have them run in intelligent consumer deviceslikecable TV switchboxes.. Sun Microsystems funded an internal research project “Green” to investigate this opportunity (~1991) • Result: A programming language called “Oak” JAVA

  18. Java versus Java Script Java (this is what you need to know for this course) • A complete programming language developed by Sun • Can be used to develop either web based or stand-alone software • Many pre-created code libraries available • For more complex and powerful programs Java Script (not covered in this course) • A small language that’s mostly used for web-based applications (run through a web browser like Internet Explorer, Firefox, Safari, Chrome) • Good for programming simple special effects for your web page e.g., roll-overs • e.g.,

  19. Filename.java Filename.class Java compiler (javac) Java program Java bytecode (generic binary) A High Level View Of Translating/Executing Java Programs Stage 1: Compilation From slides of James Tam

  20. Machine language instruction (UNIX) Filename.class Java interpreter (java) Machine language instruction (Windows) Java bytecode (generic binary) Machine language instruction (Apple) A High Level View Of Translating/Executing Java Programs Stage 2: Interpreting and executing the byte code From slides of James Tam

  21. Java Instructions • Each Java instruction must be followed by a semi-colon! int num = 123; System.out.println(“Hello!");

  22. Java Output System.out.print(<string or variable name one> + <string or variable name two>..); OR System.out.println(<string or variable name one> + <string or variable name two>..); public class OutputExample1 { public static void main (String [] args) { int num = 123; // More on this shortly System.out.println(“Hello!"); // printstonewline System.out.print(num); // printstocurrentline System.out.println("num="+num); } }

  23. Output : Some Escape Sequences For Formatting

  24. Variables • Variables must be declared before they can be used. • Variable declaration: • Creates a variable in memory. • Specify the name of the variable as well as the type of information that it will store. • E.g. int num; • Using variables • Only after a variable has been declared can it be used.

  25. Declaring Variables: Syntax • Format: <type of information> <name of variable>; • Example: char myFirstInitial; • Variables can be initialized (set to a starting value) as they’re declared: char myFirstInitial = ‘j’; int age = 30;

  26. Some Built-In Types Of Variables In Java

  27. Location Of Variable Declarations public class <name of class> { public static void main (String[] args) { // Local variable declarations occur here << Program statements >> : : } }

  28. Java Constants Reminder: constants are like variables in that they have a name and store a certain type of information but unlike variables they CANNOT change. Format: final <constant type> <CONSTANT NAME> = <value>; Example: final int SIZE = 100;

  29. Location Of Constant Declarations public class <name of class> { public static void main (String[] args) { // Local constant declarations occur here (more later) // Local variable declarations < Program statements >> : : } }

  30. Java Keywords

  31. Common Java Operators / Operator Precedence

  32. Common Java Operators / Operator Precedence

  33. Common Java Operators / Operator Precedence

  34. Common Java Operators / Operator Precedence

  35. Common Java Operators / Operator Precedence

  36. Post/Pre Operators public class Order1 { public static void main (String [] args) { int num = 5; System.out.println(num); // 5 num++; System.out.println(num); // 6 ++num; System.out.println(num); //7 System.out.println(++num); //8 System.out.println(num++); //8 } }

  37. Accessing Pre-Created Java Libraries • It’s accomplished by placing an ‘import’ of the appropriate library at the top of your program. • Syntax: import <Full library name>; • Example: import java.util.Scanner;

  38. Creating a scanner object (something that can scan user input) Using the capability of the scanner object (actually getting user input) Getting Text Input • You can use the pre-written methods (functions) in the Scanner class. • General structure: import java.util.Scanner; main (String [] args) { Scanner <name of scanner> = new Scanner (System.in); <variable> = <name of scanner> .<method> (); }

  39. Getting Text Input (2) import java.util.Scanner; public class MyInput { public static void main (String [] args) { String str1; int num1; Scanner in = new Scanner (System.in); System.out.print ("Type in an integer: "); num1 = in.nextInt (); System.out.print ("Type in a line: "); in.nextLine (); str1 = in.nextLine (); System.out.println ("num1:" +num1 +"\t str1:" + str1); } }

  40. Useful Methods Of Class Scanner • nextInt () • nextLong () • nextFloat () • nextDouble () • nextLine () • next()

  41. Decision Making In Java • Java decision making constructs • if • if, else • if, else-if • switch

  42. Decision Making: Logical Operators

  43. Indenting the body of the branch is an important stylistic requirement of Java • What distinguishes the body is either: • A semi colon (single statement branch) • Braces (a body that consists of multiple statements) Decision Making: If Format: if (Boolean Expression) Body Example: if (x != y) System.out.println("X and Y are not equal"); if ((x > 0) && (y > 0)) { System.out.println("X and Y are positive"); }

  44. Decision Making: If, Else Format: if (Boolean expression) Body of if else Body of else Example: if (x < 0) System.out.println("X is negative"); else System.out.println("X is non-negative");

  45. Example Program: If-Else import java.util.Scanner; public class BranchingExample1 { public static void main (String [] args) { Scanner in = new Scanner(System.in); final int WINNING_NUMBER = 131313; int playerNumber = -1; System.out.print("Enter ticket number: "); playerNumber = in.nextInt(); if (playerNumber == WINNING_NUMBER) System.out.println("You're a winner!"); else System.out.println("Try again."); } }

  46. If, Else-If Format: if (Boolean expression) Body of if else if (Boolean expression) Body of first else-if : : : else if (Boolean expression) Body of last else-if else Body of else

  47. If, Else-If (2) import java.util.Scanner; public class BranchingExample2 { public static void main (String [] args) { Scanner in = new Scanner(System.in); int gpa = -1; System.out.print("Enter letter grade: "); gpa = in.nextInt();

  48. If, Else-If (3) if (gpa == 4) System.out.println("A"); else if (gpa == 3) System.out.println("B"); else if (gpa == 2) System.out.println("C"); else if (gpa == 1) System.out.println("D"); else if (gpa == 0) System.out.println("F"); else System.out.println("Invalid letter grade"); } }

  49. Alternative To Multiple Else-If’s: Switch Format (character-based switch): switch (character variable name) { case '<character value>': Body break; case '<character value>': Body break; : default: Body } 1 The type of variable in the brackets can be a byte, char, short, int or long

  50. Alternative To Multiple Else-If’s: Switch (2) Format (integer based switch): switch (integer variable name) { case <integer value>: Body break; case <integer value>: Body break; : default: Body } 1 The type of variable in the brackets can be a byte, char, short, int or long

More Related