Presentation is loading. Please wait.

Presentation is loading. Please wait.

An Introduction to Software Development JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,

Similar presentations


Presentation on theme: "An Introduction to Software Development JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,"— Presentation transcript:

1 An Introduction to Software Development JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. TM ch  3

2 3-2 Objectives: l Understand the software development process, tools, and priorities l Learn about algorithms and see examples l Learn basic facts about OOP l Understand compilers and interpreters l Learn about Java Virtual Machine, bytecodes l Learn to set up simple console applications, GUI applications, and applets in Java

3 3-3 Software Today: 84,700,000

4 3-4 Software Applications l Large business systems l Databases l Military l Embedded systems l Scientific research l AI l Word processing and other small business and personal productivity tools l Internet, e-mail, etc. l Graphics / arts / digital photography l Games

5 3-5 Software Development Early era (1950s): l Emphasis on efficiency –fast algorithms –small program size –limited memory use l Often cryptic code l Not user-friendly l Emphasis on –programmer’s productivity –team development –reusability of code –easier maintenance –portability l Better documented l User-friendly Now:

6 3-6 Programming Languages 1940 1950 1960 1970 1980 1990 2000 Machine code Assembly languages Fortran Basic Pascal Scheme CC++ Java LISP Smalltalk Smalltalk-80 C# Logo

7 3-7 Algorithms “A more or less abstract, formal, and general step-by-step recipe that tells how to perform a certain task or solve a certain problem.” l Examples: –Binary Search (guess-the-number game) –long division –Euclid’s algorithm for finding the greatest common factor (c. 300 BC)

8 3-8 Properties of Algorithms l Abstract: do not depend on a particular language or machine l General: apply to any “size” of task or any input values l Short: Use iterations or recursion to repeat the same steps multiple times

9 3-9 Pseudocode and Flowcharts 1. Start at pos0, facing dir0 2. If wall in front, turn 90º clockwise else go forward 3. If back to initial position and direction, stop 4. Proceed to Step 2 Wall in front? dir  dir + 90º pos = pos0 and dir = dir0? YesNo Yes No pos  pos0 dir  dir0 pos  pos + forward Input: pos0, dir0 Stop

10 3-10 OOP — Object-Oriented Programming l An OOP program models a world of active objects. l An object may have its own “memory,” which may contain other objects. l An object has a set of methods that can process messages of certain types.

11 3-11 OOP (cont’d) l A method can change the object’s state, send messages to other objects, and create new objects. l An object belongs to a particular class, and the functionality of each object is determined by its class. l A programmer creates an OOP application by defining classes.

12 3-12 The Main OOP Concepts: l Inheritance: a subclass extends a superclass; the objects of a subclass inherit features of the superclass and can redefine them or add new features. l Event-driven programs: the program simulates asynchronous handling of events; methods are called automatically in response to events.

13 3-13 OOP Benefits l Facilitates team development l Easier to reuse software components and write reusable software l Easier GUI (Graphical User Interface) and multimedia programming

14 3-14 Software Development Tools l Editor –programmer writes source code l Compiler –translates the source into object code (instructions specific to a particular CPU) l Linker –converts one or several object modules into an executable program l Debugger –stepping through the program “in slow motion,” helps find logical mistakes (“bugs”)

15 3-15 The First “Bug” “(moth) in relay” Mark II Aiken Relay Calculator (Harvard University, 1945)

16 3-16 Compiled Languages: Edit-Compile-Link-Run Editor Source code Compiler Object code Linker Executable program Editor Source code Compiler Object code Editor Source code Compiler Object code

17 3-17 IDE — Integrated Development Environment l Combines editor, compiler, linker, debugger, other tools l Has GUI (graphical user interface) l Compiles + links + runs at the click of a button l Helps put together a project with several modules (source files)

18 3-18 Compiler vs. Interpreter l Compiler: checks syntax generates machine-code instructions not needed to run the executable program the executable runs faster l Interpreter: checks syntax executes appropriate instructions while interpreting the program statements must remain installed while the program is interpreted the interpreted program is slower Editor Source code Interpreter

19 3-19 Java’s Hybrid Approach: Compiler + Interpreter l A Java compiler converts Java source code into instructions for the Java Virtual Machine. l These instructions, called bytecodes, are the same for any computer / operating system. l A Java interpreter executes bytecodes on a particular computer.

20 3-20 Java’s Compiler + Interpreter

21 3-21 Why Bytecodes? l Platform-independent. l Load from the Internet faster than source code. l Interpreter is faster and smaller than it would be for Java source. l Source code is not revealed to end users. l Interpreter performs additional security checks, screens out malicious code.

22 3-22 Java SDK (a.k.a. JDK) — Software Development Kit javac –Java compiler java –Java interpreter appletviewer –tests applets without a browser jar –packs classes into jar files (packages) javadoc –generates HTML documentation (“docs”) from source jdb –command-line debugger All these are command-line tools, no GUI

23 3-23 Java SDK (cont’d) l Available free from Sun Microsystems. l All documentation is online: l Lots of additional Java resources on the Internet: http://java.sun.com/j2se/1.4/docs http://www.skylit.com/javamethods/appxg.html

24 3-24 Java IDEs l GUI front end for SDK Integrates editor, javac, java, appletviewer, debugger, other tools: –specialized Java editor with syntax highlighting, autoindent, tab setting, etc. –clicking on a compiler error message takes you to the offending source code line l Some IDEs have their own copy of SDK; others need SDK installed separately.

25 3-25 Types of Programs: l Console applications l GUI applications l Applets

26 3-26 Console Applications C:\javamethods\Ch03> set classpath=.;C:\javamethods\EasyIO C:\javamethods\Ch03> javac Greetings2.java C:\javamethods\Ch03> java Greetings2 Enter your first name: Josephine Enter your last name: Javadoc Hello, Josephine Javadoc Congratulations on your third program! C:\javamethods\Ch03> _ l Simple text dialog: prompt  input, prompt  input...  result

27 3-27 Greetings2.java public class Greetings2 { public static void main(String[ ] args) { EasyReader console = new EasyReader (); System.out.print("Enter your first name: "); String firstName = console.readLine(); System.out.print("Enter your last name: "); String lastName = console.readLine(); System.out.println("Hello, " + firstName + " " + lastName); System.out.println("Congratulations on your third program!"); } EasyReader.class must be in the same folder as your program (or set the classpath to include its location). The EasyReader class (written by the Java Methods authors) is used for getting keyboard input. Prompts

28 3-28 Command-Line Arguments C:\javamethods\Ch03> javac Greetings.java C:\javamethods\Ch03> java Greetings Josephine Javadoc Hello, Josephine Javadoc public class Greetings { public static void main(String[ ] args) { String firstName = args[ 0 ] ; String lastName = args[ 1 ] ; System.out.println("Hello, " + firstName + " " + lastName); } Command-line arguments are passed to main as an array of Strings.

29 3-29 Command-Line Args (cont’d) l Can be used in GUI applications, too l IDEs provide a way to set them Josephine Javadoc (Or prompt for them)

30 3-30 GUI Applications Menus Buttons Clickable panel Slider

31 3-31 HelloGui.java import java.awt.*; import javax.swing.*; public class HelloGui extends JFrame {... public static void main(String[ ] args) { HelloGui window = new HelloGui(); window.addWindowListener( new ExitButtonListener ()); window.setSize(300, 100); window.show(); } The ExitButtonListener class (written by the Java Methods authors) is used for handling the “window close” button. ExitButtonListener.class must be in the same folder as your program (or set the classpath to include its location). GUI libraries

32 3-32 HelloApplet.java import java.awt.*; import javax.swing.*; public class HelloApplet extends JApplet { public void init() {... }... } No main in applets: the init method is called by the applet viewer or the browser

33 3-33 Review: l What are some of the current software development concerns? l What is OOP? l Define inheritance. l What are editor, compiler, linker, debugger used for? l Define IDE. l How is a compiler different from an interpreter?

34 3-34 Review (cont’d): l Name some of the benefits of Java’s compiler+interpreter approach. l What is a console application? l What are command-line arguments? l What is a GUI application? l What is the difference between a GUI application and an applet? l Where does the EasyReader class come from? What does it do?


Download ppt "An Introduction to Software Development JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,"

Similar presentations


Ads by Google