Chapter 2 - An introduction to software engineering. This chapter gives a glimpse of how software development evolved from artisanship into a professional engineering discipline. At the same time, students will get familiar with Java development tools and run their first programs.
Java Methods Object-Oriented Programming and Data Structures 2nd AP edition with GridWorld Maria Litvin ● Gary Litvin Chapter An Introduction to Software Engineering Copyright © 2011 by Maria Litvin, Gary Litvin, and Skylight Publishing All rights reserved Objectives: • Understand the software development process, tools, and priorities • Understand compilers and interpreters • Learn about Java Virtual Machine, bytecode • Learn to set up and run simple console applications, GUI applications, and applets in Java • Learn basic facts about OOP 22 Software Today: 1,580,000,000 23 Software Applications • Large business systems • • • • • • Databases Internet, e-mail, etc Military Embedded systems Scientific research • Word processing and other small business and personal productivity tools • Graphics / arts / digital photography • Games AI 24 Software Development 1950-1970's: • Emphasis on efficiency fast algorithms small program size limited memory use Now: • Emphasis on • Often cryptic code • Not user-friendly programmer’s productivity team development reusability of code easier maintenance portability • Better documented • User-friendly 25 Programming Languages C C++ C# Assembl LISP Scheme y Java D Log Ada Algol languag o es 1940 1950 1960 1970 1980 1990 2000 2010 Fortra Pascal Python Fortres Machin n Basic s Cobol e Groovy Smalltalk Smalltalkcode 80 26 Software Development Tools • Editor programmer writes source code • Compiler translates the source into object code (instructions specific to a particular CPU) • Linker converts one or several object modules into an executable program • Debugger steps through the program “in slow motion” and helps find logical mistakes (“bugs”) 27 The First “Bug” “(moth) in relay” Mark II Aiken Relay Calculator (Harvard University, 1945) 28 Compiled Languages: Edit-Compile-Link-Run Edito Source r code Compil er Object code Edito Source r code Compil er Object code Edito Source r code Compil er Object code Linker Executab le program 29 Interpreted Languages: Edit-Run Edito Source Interpret r code er 210 Types of Programs • Console applications • GUI applications • Applets 218 Console Applications • Simple text dialog: prompt input, prompt input result C:\javamethods\Ch02> path=%PATH%;C:\Program Files\Java\jdk 1.5.0_07\bin C:\javamethods\Ch02> javac Greetings2.java C:\javamethods\Ch02> java Greetings2 Enter your first name: Josephine Enter your last name: Jaworski Hello, Josephine Jaworski Press any key to continue 219 Command-Line Arguments C:\javamethods\Ch02> javac Greetings.java C:\javamethods\Ch02> java Greetings Josephine Jaworski Hello, Josephine Jaworski Commandpublic class Greetings line { arguments public static void main(String[ ] args) are passed { to main String firstName = args[ ]; as an array String lastName = args[ ]; of Strings System.out.println("Hello, " + firstName +" " + lastName); } } 220 Command-Line Args (cont’d) • Can be used in GUI applications, too • IDEs provide ways to set them (or prompt for them) Josephine Jaworski 221 Greetings2.ja vaimport java.util.Scanner; public class Greetings2 { public static void main(String[ ] args) { Scanner kboard = new Scanner(System.in); System.out.print("Enter your first name: "); Promp String firstName = kboard.nextLine( ); ts System.out.print("Enter your last name: "); String lastName = kboard.nextLine( ); System.out.println("Hello, " + firstName + " " + lastName); System.out.println("Welcome to Java!"); 222 GUI Applications Menus Clickable panel Buttons Slider 223 HelloGui.java import java.awt.*; import javax.swing.*; GUI libraries public class HelloGui extends JFrame { < other code > public static void main(String[ ] args) { HelloGui window = new HelloGui( ); // Set this window's location and size: // upper-left corner at 300, 300; width 200, height 100 window.setBounds(300, 300, 200, 100); window.setDefaultCloseOperation(JFrame.EXIT_ON_CL OSE); window.setVisible(true); 224 } HelloApplet.ja va import java.awt.*; import javax.swing.*; public class HelloApplet extends JApplet { No main in applets: the public void init( ) init method is called by { JDK’s appletviewer or the browser } < other code > } 225 OOP — Object-Oriented Programming • An OOP program models a world of active objects • An object may have its own “memory,” which may contain other objects • An object has a set of methods that can process messages of certain types 226 OOP (cont’d) • A method can change the object’s state, send messages to other objects, and create new objects • An object belongs to a particular class, and the functionality of each object is determined by its class • A programmer creates an OOP application by defining classes 227 The Main OOP Concepts: • Inheritance: a subclass extends a superclass; the objects of a subclass inherit features of the superclass and can redefine them or add new features • Event-driven programs: the program simulates asynchronous handling of events; methods are called automatically in response to events 228 Inheritance • A programmer can define hierarchies of classes • More general classes are closer to the top Person Child Baby Toddler Adult Teen 229 OOP Benefits • Facilitates team development • Easier to reuse software components and write reusable software • Easier GUI (Graphical User Interface) and multimedia programming 230 Review: • What are some of the current software development concerns? • What are editor, compiler, debugger used for? • How is a compiler different from an interpreter? • Name some of the benefits of Java’s compiler+interpreter approach • Define IDE 231 Review (cont’d): • • • • What is a console application? What are command-line arguments? What is a GUI application? What is the difference between a GUI application and an applet? • What is OOP? • Define inheritance 232 ... prompt input result C:\javamethods\Ch 02> path=%PATH%;C:\Program Files \Java\ jdk 1.5.0_07\bin C:\javamethods\Ch 02> javac Greetings2 .java C:\javamethods\Ch 02> java Greetings2 Enter your first name:... any key to continue 2? ?19 Command-Line Arguments C:\javamethods\Ch 02> javac Greetings .java C:\javamethods\Ch 02> java Greetings Josephine Jaworski Hello, Josephine Jaworski Commandpublic class Greetings... GUI applications, and applets in Java • Learn basic facts about OOP 2? ?2 Software Today: 1,580,000,000 2? ?3 Software Applications • Large business systems • • • • • • Databases Internet, e-mail,