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

Slides:



Advertisements
Similar presentations
What is a Computer Program? For a computer to be able to do anything (multiply, play a song, run a word processor), it must be given the instructions.
Advertisements

Designing a Program & the Java Programming Language
A Programmer's Introduction to Java - from a S/370 user (c) IDMS/SQL News
Introduction To Java Objectives For Today â Introduction To Java â The Java Platform & The (JVM) Java Virtual Machine â Core Java (API) Application Programming.
Lab#1 (14/3/1431h) Introduction To java programming cs425
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
©2004 Brooks/Cole Chapter 1: Getting Started Sections Covered: 1.1Introduction to Programming 1.2Constructing a Java Program 1.3The print() and println()
Computers: Tools for an Information Age
Java Programming, 3e Concepts and Techniques Chapter 1 An Introduction to Java and Program Design.
PHY281Introduction to JavaSlide 1 Introduction to Java In this section we will learn how how to use Java and write our first Java Applet:  The Java Development.
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
Developing User Interfaces (DUI) Chris North cs3724: HCI.
Java Programming, 2E Introductory Concepts and Techniques Chapter 1 An Introduction to Java and Program Design.
Programming Languages: Telling the Computers What to Do Chapter 16.
CS413: Java Programming language Applications Applets
Java Workshop for Teachers May 6, 2005 A Brief Look at the Java Programming Language.
COMPUTER PROGRAMMING Source: Computing Concepts (the I-series) by Haag, Cummings, and Rhea, McGraw-Hill/Irwin, 2002.
An intro to programming. The purpose of writing a program is to solve a problem or take advantage of an opportunity Consists of multiple steps:  Understanding.
111 © 2002, Cisco Systems, Inc. All rights reserved.
CSE 1340 Class 3. Class 03 objectives State the difference between Machine Language vs. High Level Languages Discuss some characteristics of the Java.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Computer Concepts 2014 Chapter 12 Computer Programming.
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
POS 406 Java Technology And Beginning Java Code
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Programming Concept Chapter I Introduction to Java Programming.
Introduction to Java Programming with Forte Y. Daniel Liang.
Clement Allen, PhD Florida A&M University SUMMER 2006.
1 Programming Fundamentals AITI-GP. 2 Introduction to Programming.
Visual C++ Programming: Concepts and Projects
The Joy of Programming (also known as) Introduction to Object-Oriented Programming.
CS 3131 Introduction to Programming in Java Rich Maclin Computer Science Department.
An Introduction to Software Development Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006.
2-1 Hardware CPU Memory - 2 kinds Network Graphics Input and Output Devices.
2-1 Hardware CPU Memory - 2 kinds Network Graphics Input and Output Devices.
Chapter 1 Section 1.1 Introduction to Java Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
Java Applets. 2 Introduction to Java Applet Programs Applications are ___________________ programs –executed with Java interpreter Applet is a small program.
Fall 2006Slides adapted from Java Concepts companion slides1 Introduction Advanced Programming ICOM 4015 Lecture 1 Reading: Java Concepts Chapter 1.
Session 1 Introduction to Java. Objectives Java Simplified / Session 1 / 2 of 32 Explain the history of Java Explain Java in brief List the types of Java.
National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.
The Programming Process Define the problem* Make or buy software? Design the program * Code (write) the program Test (debug) the program Document the.
4-Nov-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming Design Topic 1: The Java Environment Maj Joel.
Java Classes, Objects, and Events: A Preview JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and web applications Very rich GUI libraries Portability (machine independence) A real Object.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Algorithms Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin,
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Creating a Java Application and Applet
introductory lecture on java programming
ITP 109 Week 2 Trina Gregory Introduction to Java.
Computer Programming Week 1: The Basics of CP 1 st semester 2012 School of Information Technology Website:
Programming 2 Intro to Java Machine code Assembly languages Fortran Basic Pascal Scheme CC++ Java LISP Smalltalk Smalltalk-80.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
PROGRAMMING (1) LECTURE # 1 Programming and Languages: Telling the Computer What to Do.
Introduction to Java Programming, 4E Y. Daniel Liang.
Your Interactive Guide to the Digital World Discovering Computers 2012 Chapter 13 Computer Programs and Programming Languages.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
CS-140 Dick Steflik Lecture 3. Java C++ Interpreted optimized for the internet Runs on virtual ized machine Derived from C++ Good object model Widely.
An Introduction to Software Development
CSCI-235 Micro-Computer Applications
Java programming lecture one
An Introduction to Software Development
Introduction CSC 111.
The Programming Process
Presentation transcript:

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

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 Software Today: 84,700,000

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, , etc. l Graphics / arts / digital photography l Games

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:

3-6 Programming Languages Machine code Assembly languages Fortran Basic Pascal Scheme CC++ Java LISP Smalltalk Smalltalk-80 C# Logo

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)

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

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

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.

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.

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.

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

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”)

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

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

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)

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

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.

3-20 Java’s Compiler + Interpreter

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.

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

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:

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.

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

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

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

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.

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)

3-30 GUI Applications Menus Buttons Clickable panel Slider

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

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

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?

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?