SlideShare a Scribd company logo
An Introduction to Software Development Java Methods 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
Objectives: Understand the software development process, tools, and priorities Learn about algorithms and see examples Learn basic facts about OOP Understand compilers and interpreters Learn about Java Virtual Machine,  bytecodes Learn to set up simple console applications, GUI applications, and applets in Java
Software Today: 84,700,000
Software Applications Large business systems Databases Military Embedded systems Scientific research AI Word processing and other small business and personal productivity tools Internet, e-mail, etc. Graphics / arts / digital photography Games
Software Development Emphasis on efficiency fast algorithms small program size limited memory use Often cryptic code Not user-friendly Emphasis on programmer’s productivity team development reusability of code easier maintenance portability Better documented User-friendly Early era (1950s) : Now :
Programming Languages 1940  1950  1960  1970  1980  1990  2000 Machine code Assembly languages Fortran Basic Pascal Scheme C C++ Java LISP Smalltalk  Smalltalk-80 C# Logo
Algorithms Examples: Binary Search (guess-the-number game)  long division Euclid’s algorithm for finding the greatest common factor (c. 300 BC) “ 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.”
Properties of Algorithms Abstract : do not depend on a particular language or machine General : apply to any “size” of task or any input values Short : Use iterations or recursion to repeat the same steps multiple times
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? Yes No Yes No pos    pos0 dir    dir0 pos     pos + forward Input: pos0, dir0 Stop
OOP — O bject- O riented  P rogramming 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.
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.
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.
OOP Benefits Facilitates team development Easier to reuse software components and write reusable software Easier GUI ( G raphical  U ser  I nterface) and multimedia programming
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 stepping through the program “in slow motion,” helps find logical mistakes (“bugs”)
The First “Bug” “ (moth) in relay” Mark II Aiken Relay Calculator (Harvard University, 1945)
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 
IDE — I ntegrated  D evelopment  E nvironment Combines editor, compiler, linker, debugger, other tools Has GUI (graphical user interface) Compiles + links + runs at the click of a button Helps put together a project with several modules (source files)
Compiler vs.  Interpreter Compiler: checks syntax generates machine-code instructions not  needed to run the executable program the executable runs faster 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 
Java’s Hybrid Approach: Compiler + Interpreter A Java  compiler  converts Java source code into instructions for the  Java Virtual Machine. These instructions, called  bytecodes , are the same for any computer / operating system. A Java  interpreter  executes bytecodes on a particular computer.
Java’s Compiler + Interpreter
Why Bytecodes? Platform-independent. Load from the Internet faster than source code. Interpreter is faster and smaller than it would be for Java source. Source code is not revealed to end users. Interpreter performs additional security checks, screens out malicious code.
Java SDK (a.k.a. JDK) — S oftware  D evelopment  K it 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
Java SDK (cont’d) Available free from Sun Microsystems. All documentation is online: Lots of additional Java resources on the Internet: http://java.sun.com/j2se/1.4/docs http://www.skylit.com/javamethods/appxg.html
Java IDEs 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 Some IDEs have their own copy of SDK; others need SDK installed separately.
Types of Programs: Console applications GUI applications Applets
Console Applications Simple text dialog: prompt    input, prompt    input ...    result 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>  _
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
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  String s.
Command-Line Args (cont’d) Can be used in GUI applications, too IDEs provide a way to set them Josephine Javadoc (Or prompt for them)
GUI Applications Menus Buttons Clickable panel Slider
HelloGui.java import java.awt.*; import javax.swing.*; public class HelloGui  extends  JFrame { ... <  other code  > 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
HelloApplet.java import java.awt.*; import javax.swing.*; public class HelloApplet  extends  JApplet { public void init() { ... } ... <  other methods  > } No  main  in applets: the  init  method is called by the applet viewer or the browser
Review: What are some of the current software development concerns? What is  OOP ? Define  inheritance . What are  editor ,  compiler ,  linker ,  debugger  used for? Define  IDE . How is a compiler different from an interpreter?
Review (cont’d): Name some of the benefits of Java’s compiler+interpreter approach. 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? Where does the  EasyReader  class come from?  What does it do?

More Related Content

What's hot (20)

PPT
Software estimation
Md Shakir
 
PPT
Software Engineering (Introduction to Software Engineering)
ShudipPal
 
PPTX
Software process Models
SADEED AMEEN
 
PPT
ppt on sOFTWARE DEVELOPMENT LIFE CYCLE
Swarnima Tiwari
 
PPSX
Programming Fundamental Presentation
fazli khaliq
 
PPT
Slides chapter 2
Priyanka Shetty
 
PPTX
Chapter 2 software process models
Golda Margret Sheeba J
 
PPTX
software maintenance
rajshreemuthiah
 
PPTX
Waterfall Model
Nahin Kumar Dey
 
PPTX
V model
Vaibhav Dash
 
PPTX
Waterfall model in SDLC
HND Assignment Help
 
PPT
Software Engineering ppt
shruths2890
 
PDF
Software Development Life Cycle (SDLC)
Angelin R
 
PPT
Software design
Benazir Fathima
 
PPT
Software Quality Assurance
Sachithra Gayan
 
PPTX
Spiral model ppt
Shakthi Weerasinghe
 
PPTX
Water fall model
Akhil Bevara
 
PPTX
6 basic steps of software development process
Riant Soft
 
PPT
SDLC - Software Development Life Cycle
Saravanan Manoharan
 
PPT
Agile software development
Muhammad Amjad Rana
 
Software estimation
Md Shakir
 
Software Engineering (Introduction to Software Engineering)
ShudipPal
 
Software process Models
SADEED AMEEN
 
ppt on sOFTWARE DEVELOPMENT LIFE CYCLE
Swarnima Tiwari
 
Programming Fundamental Presentation
fazli khaliq
 
Slides chapter 2
Priyanka Shetty
 
Chapter 2 software process models
Golda Margret Sheeba J
 
software maintenance
rajshreemuthiah
 
Waterfall Model
Nahin Kumar Dey
 
V model
Vaibhav Dash
 
Waterfall model in SDLC
HND Assignment Help
 
Software Engineering ppt
shruths2890
 
Software Development Life Cycle (SDLC)
Angelin R
 
Software design
Benazir Fathima
 
Software Quality Assurance
Sachithra Gayan
 
Spiral model ppt
Shakthi Weerasinghe
 
Water fall model
Akhil Bevara
 
6 basic steps of software development process
Riant Soft
 
SDLC - Software Development Life Cycle
Saravanan Manoharan
 
Agile software development
Muhammad Amjad Rana
 

Viewers also liked (18)

PPTX
Software (Application and System Software)
Project Student
 
PPTX
Hardware and Software
Project Student
 
PPT
Requirement analysis and specification, software engineering
Rupesh Vaishnav
 
PPT
Lecture 15 requirements modeling - scenario, information and analysis class...
IIUI
 
PDF
SE_Lec 00_ Software Engineering 1
Amr E. Mohamed
 
PPT
Lecture 16 requirements modeling - scenario, information and analysis classes
IIUI
 
PPT
Lecture 17 design concepts (2)
IIUI
 
PPT
Introduction to Software Engineering 1
IIUI
 
PDF
Chapter 08 secondary storage
IIUI
 
PPTX
Software engineering : Layered Architecture
Muhammed Afsal Villan
 
PPT
Lecture 13 requirements modeling - flow & behavior (2)
IIUI
 
PDF
Chapter 04 computer codes
IIUI
 
PPT
Lecture 20 software testing (2)
IIUI
 
PPT
Lecture 14 requirements modeling - flow and behavior
IIUI
 
PDF
Chapter 09 io devices
IIUI
 
PPT
Lect3 ch15-unit2
Mobeen Mustafa
 
PPT
Lecture 2 introduction to Software Engineering 1
IIUI
 
PPTX
Layered Software Architecture
Lars-Erik Kindblad
 
Software (Application and System Software)
Project Student
 
Hardware and Software
Project Student
 
Requirement analysis and specification, software engineering
Rupesh Vaishnav
 
Lecture 15 requirements modeling - scenario, information and analysis class...
IIUI
 
SE_Lec 00_ Software Engineering 1
Amr E. Mohamed
 
Lecture 16 requirements modeling - scenario, information and analysis classes
IIUI
 
Lecture 17 design concepts (2)
IIUI
 
Introduction to Software Engineering 1
IIUI
 
Chapter 08 secondary storage
IIUI
 
Software engineering : Layered Architecture
Muhammed Afsal Villan
 
Lecture 13 requirements modeling - flow & behavior (2)
IIUI
 
Chapter 04 computer codes
IIUI
 
Lecture 20 software testing (2)
IIUI
 
Lecture 14 requirements modeling - flow and behavior
IIUI
 
Chapter 09 io devices
IIUI
 
Lect3 ch15-unit2
Mobeen Mustafa
 
Lecture 2 introduction to Software Engineering 1
IIUI
 
Layered Software Architecture
Lars-Erik Kindblad
 
Ad

Similar to Introduction to Software Development (20)

PPT
Java Methods - An Introduction to Software Development
RajKumar Radhamanalan
 
PDF
ITFT - Java Coding
Blossom Sood
 
PPTX
Introduction to java
Ali Baba
 
PPT
JAVA object oriented programming (oop).ppt
AliyaJav
 
PPTX
Java Starting
Raja Sekhar
 
PPTX
Introduction to java
AbhishekMondal42
 
PDF
Javanotes
John Cutajar
 
PPTX
Object oriented programming-with_java
Hoang Nguyen
 
PPTX
Object oriented programming
Fraboni Ec
 
PPTX
Object oriented programming-with_java
Tony Nguyen
 
PPTX
Object oriented programming
Luis Goldster
 
PPTX
Object oriented programming-with_java
Harry Potter
 
PPTX
Object oriented programming
Young Alista
 
PPTX
Object oriented programming
James Wong
 
PPT
basic_java.ppt
sujatha629799
 
PPTX
Java
Sneha Mudraje
 
PPT
Java presentation
Karan Sareen
 
PPT
JavaClassPresentation
juliasceasor
 
PPTX
Chapter-introduction about java programming
DrRajeshkumarPPatel
 
PPTX
Introduction to java
Kalai Selvi
 
Java Methods - An Introduction to Software Development
RajKumar Radhamanalan
 
ITFT - Java Coding
Blossom Sood
 
Introduction to java
Ali Baba
 
JAVA object oriented programming (oop).ppt
AliyaJav
 
Java Starting
Raja Sekhar
 
Introduction to java
AbhishekMondal42
 
Javanotes
John Cutajar
 
Object oriented programming-with_java
Hoang Nguyen
 
Object oriented programming
Fraboni Ec
 
Object oriented programming-with_java
Tony Nguyen
 
Object oriented programming
Luis Goldster
 
Object oriented programming-with_java
Harry Potter
 
Object oriented programming
Young Alista
 
Object oriented programming
James Wong
 
basic_java.ppt
sujatha629799
 
Java presentation
Karan Sareen
 
JavaClassPresentation
juliasceasor
 
Chapter-introduction about java programming
DrRajeshkumarPPatel
 
Introduction to java
Kalai Selvi
 
Ad

Recently uploaded (20)

PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Digital Circuits, important subject in CS
contactparinay1
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 

Introduction to Software Development

  • 1. An Introduction to Software Development Java Methods 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. Objectives: Understand the software development process, tools, and priorities Learn about algorithms and see examples Learn basic facts about OOP Understand compilers and interpreters Learn about Java Virtual Machine, bytecodes Learn to set up simple console applications, GUI applications, and applets in Java
  • 4. Software Applications Large business systems Databases Military Embedded systems Scientific research AI Word processing and other small business and personal productivity tools Internet, e-mail, etc. Graphics / arts / digital photography Games
  • 5. Software Development Emphasis on efficiency fast algorithms small program size limited memory use Often cryptic code Not user-friendly Emphasis on programmer’s productivity team development reusability of code easier maintenance portability Better documented User-friendly Early era (1950s) : Now :
  • 6. Programming Languages 1940 1950 1960 1970 1980 1990 2000 Machine code Assembly languages Fortran Basic Pascal Scheme C C++ Java LISP Smalltalk Smalltalk-80 C# Logo
  • 7. Algorithms Examples: Binary Search (guess-the-number game) long division Euclid’s algorithm for finding the greatest common factor (c. 300 BC) “ 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.”
  • 8. Properties of Algorithms Abstract : do not depend on a particular language or machine General : apply to any “size” of task or any input values Short : Use iterations or recursion to repeat the same steps multiple times
  • 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? Yes No Yes No pos  pos0 dir  dir0 pos  pos + forward Input: pos0, dir0 Stop
  • 10. OOP — O bject- O riented P rogramming 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.
  • 11. 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.
  • 12. 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.
  • 13. OOP Benefits Facilitates team development Easier to reuse software components and write reusable software Easier GUI ( G raphical U ser I nterface) and multimedia programming
  • 14. 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 stepping through the program “in slow motion,” helps find logical mistakes (“bugs”)
  • 15. The First “Bug” “ (moth) in relay” Mark II Aiken Relay Calculator (Harvard University, 1945)
  • 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. IDE — I ntegrated D evelopment E nvironment Combines editor, compiler, linker, debugger, other tools Has GUI (graphical user interface) Compiles + links + runs at the click of a button Helps put together a project with several modules (source files)
  • 18. Compiler vs. Interpreter Compiler: checks syntax generates machine-code instructions not needed to run the executable program the executable runs faster 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. Java’s Hybrid Approach: Compiler + Interpreter A Java compiler converts Java source code into instructions for the Java Virtual Machine. These instructions, called bytecodes , are the same for any computer / operating system. A Java interpreter executes bytecodes on a particular computer.
  • 20. Java’s Compiler + Interpreter
  • 21. Why Bytecodes? Platform-independent. Load from the Internet faster than source code. Interpreter is faster and smaller than it would be for Java source. Source code is not revealed to end users. Interpreter performs additional security checks, screens out malicious code.
  • 22. Java SDK (a.k.a. JDK) — S oftware D evelopment K it 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. Java SDK (cont’d) Available free from Sun Microsystems. All documentation is online: Lots of additional Java resources on the Internet: http://java.sun.com/j2se/1.4/docs http://www.skylit.com/javamethods/appxg.html
  • 24. Java IDEs 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 Some IDEs have their own copy of SDK; others need SDK installed separately.
  • 25. Types of Programs: Console applications GUI applications Applets
  • 26. Console Applications Simple text dialog: prompt  input, prompt  input ...  result 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> _
  • 27. Greetings2.java public class Greetings2 { public static void main(String[ ] args) { EasyReader console = new EasyReader (); System.out.print(&quot;Enter your first name: &quot;); String firstName = console.readLine(); System.out.print(&quot;Enter your last name: &quot;); String lastName = console.readLine(); System.out.println(&quot;Hello, &quot; + firstName + &quot; &quot; + lastName); System.out.println(&quot;Congratulations on your third program!&quot;); } } 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. 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(&quot;Hello, &quot; + firstName + &quot; &quot; + lastName); } } Command-line arguments are passed to main as an array of String s.
  • 29. Command-Line Args (cont’d) Can be used in GUI applications, too IDEs provide a way to set them Josephine Javadoc (Or prompt for them)
  • 30. GUI Applications Menus Buttons Clickable panel Slider
  • 31. HelloGui.java import java.awt.*; import javax.swing.*; public class HelloGui extends JFrame { ... < other code > 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. HelloApplet.java import java.awt.*; import javax.swing.*; public class HelloApplet extends JApplet { public void init() { ... } ... < other methods > } No main in applets: the init method is called by the applet viewer or the browser
  • 33. Review: What are some of the current software development concerns? What is OOP ? Define inheritance . What are editor , compiler , linker , debugger used for? Define IDE . How is a compiler different from an interpreter?
  • 34. Review (cont’d): Name some of the benefits of Java’s compiler+interpreter approach. 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? Where does the EasyReader class come from? What does it do?

Editor's Notes

  • #2: 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.
  • #3: Students with a penchant for history can find a lot of interesting historical data on programming languages and software methodologies on the Internet. Those who are more interested in algorithms may be intrigued by recursion and may try to come up with recursive versions of common algorithms.
  • #4: A Google search for SOFTWARE results in over 80 million hits. Computers run everything from power grids, water utilities, TV satellites, and telephone networks to cars and coffee makers. Try to envision our lives if all programs were suddenly wiped out. Also try to appreciate the total effort that was needed to develop this invisible universe.
  • #5: The idea of developing intelligent computers (AI, or artificial intelligence) came about as soon (or perhaps before) as the first computer. Over the years the expectations turned out to be too optimistic. Little progress to report so far.
  • #6: The main premise of the current software development culture is that hardware keeps getting faster and cheaper, so efficiency is no longer an issue. As a result, the performance of some programs even on fast computers may be rather sluggish, and we are forced to upgrade our computers every couple of years. This arrangement is good for both hardware and software companies: new computers have room for new software, bigger and slower software calls for new computers. This disregard for efficiency and economy in commercial software may be partly intentional.
  • #7: Thousands of programming languages and dialects have been described; many evolved over the years, others have disappeared, some existed for years but recently gained new popularity (e.g., Perl, Python). Java was initially meant for embedded systems (like home appliances) and for “interactive TV” but has survived due to the Internet. Machine code is called “first generation”; assembly languages are second generation; “high-level languages” (Fortran, Basic, Pascal, Smalltalk, etc.) are third generation. Fourth generation — visual prototyping systems with automatic code generation — was a buzzword in the 1980s (in the field called CASE, Computer-Aided Software Engineering), but the promise never really materialized.
  • #8: This is the time to play the “I’m thinking of a number from one to one hundred” game. Other simple algorithms (e.g., bubble sort) can be staged with students. Students should be encouraged to come up with their own examples of “interesting” algorithms.
  • #9: Iterations and recursion make an algorithm different from a cookbook recipe. In most cookbook instructions, each step is performed once. This works because the chef is slow. But a computer is very fast, billions of times faster than a programmer. If we had to write out separately every instruction that a computer executes, we wouldn’t be able to take advantage of its speed. In non-trivial algorithms, the same sequences of steps are repeated multiple times (but the values of variables are updated at each step).
  • #10: Flowcharts are pretty much history: they are really not used in software development any more since programming has switched to OOP. One should specify when a given algorithm applies (preconditions) and its final state (postconditions). What are the preconditions here? The room is rectangular; the robot is placed next to a wall. What if the preconditions aren’t satisfied? Infinite loop, the program “hangs.”
  • #11: “ Methods” in Java are like functions in C or C++. Calling an object’s method is often phrased as “sending a message” to the object.
  • #12: In the previous example, the program may have a class Robot and an object of that class. A Robot object keeps in its memory its initial and current position. A robot has methods to step forward and to turn. Another class may be Position; the initial and current positions may be objects of that class. Robot’s methods “forward” and “turn” may call Position’s methods “move” and “turn.” The number of classes in a project may be quite large, but they are usually short. In Java each class is stored in a separate file. (An exception are the so-called inner classes that are embedded inside another class. They are not discussed in this book.) The name of the file must be exactly the same as the name of the class (including upper and lower case) with the extension .java .
  • #13: Event-driven applications are necessitated by GUI: the program cannot predict which button or menu the user will click next; it reacts to different events as they come. The robot program may have a step button, for instance. Inheritance allows you to reuse most of the code in a class and redefine or add a couple of things. We could extend Robot into a JumpingRobot, adding a method “jump.” These concepts will become clearer in the next chapter and in the subsequent chapters.
  • #14: At least these are the claims. OOP is definitely good for GUI development. But is it universally applicable in any type of project? OOP originated in academia; in a rather unique situation, businesses have spent millions of dollars converting to OOP and retraining their programmers without serious formal cost-benefit analysis. Prior to OOP the big thing was structured programming and top-down development .
  • #15: A programming language has a strict syntax. A compiler parses the source code and checks the syntax. There are other programming tools. “Make” keeps track of the project and the time marks on files and recompiles only those files whose source code has changed. Version control software allows a team of programmers to keep track of changes to files, so that two programmers are not working with the same file at the same time.
  • #16: This is a neat legend, but actually the term “bug” was used earlier.
  • #17: If you read your code carefully and reason about it before compiling, the number of cycles through Edit-Compile-Link-Run will be reduced, perhaps even to one!
  • #18: An IDE is especially helpful in Java because a project may have a large number of source files (each class is in a separate file).
  • #19: A Java interpreter is built into a Java-enabled browser for running applets. Due to a legal dispute between Sun and Microsoft, Internet Explorer does not have the latest version of Java built in, but Sun provides a Java “plug-in” for it. Netscape 6.0 has the latest version of Java.
  • #20: Java Virtual Machine is an imaginary computer with a CPU instruction set that is “the least common denominator” for typical real CPUs.
  • #21: There is also JIT (Just In Time) compiler technology where the program is interpreted and compiled at the same time. On subsequent runs the compiled code is used; there is no need to reinterpret it.
  • #22: Java’s culture is pretty open, and many applets are available on the Internet with their source code. Still, software vendors may want to protect their source code. For obvious reasons, the interpreter wouldn’t allow an applet to read or write files on your computer. Hackers have peculiar ethics (or rather, a gap in ethics): they won’t go around checking locks on the doors of houses or cars or spread real disease germs (even if nonlethal ones), but they will break into your computer system (which may be much more harmful and expensive) and spread computer viruses.
  • #23: SDK lacks an editor, so we use non-SDK software to create the source code. Our main tools are javac, java, and appletviewer. IDE usually has a more convenient debugger than SDK’s debugger. We recommend not using a debugger at all.
  • #24: It may be better to download Java docs together with the SDK and install them on the school server.
  • #25: Most Java IDEs are written in Java. JCreator is an exception: it is written in C++ and is a little more compact and faster. It requires that SDK be installed. If an IDE does not come with an SDK, then install the SDK first, before the IDE.
  • #26: Console applications emulate a teletype device; they are sometimes called terminal applications (comes from old text-only terminals).
  • #27: Console applications may be not much fun, but they do the job when you need to test a simple calculation or algorithm. Classpath is explained at skylit.com/javamethods/faqs.html . C:\\javamethods\\EasyIO presumably holds EasyReader.class (see the next slide).
  • #28: We supplied EasyReader and EasyWriter because native Java IO classes are quite confusing and rather hard to use.
  • #29: Command-line arguments are not specific to Java: C and C++ have them, as well as other languages under Unix, DOS, etc. In Windows, use the Command Prompt application. There’s no command-line mode on a Mac. The Java source file name is a command line argument for javac. Likewise, the HTML file name is a command-line argument for appletviewer.
  • #30: An IDE usually provides a way to set command-line args (on a Mac, too) or prompts for them when you run your program.
  • #31: This screen is from the Marine Biology Simulation case study, developed by Alyce Brady for the College Board and used on the AP CS exams.
  • #32: JFrame is a Swing library class for a generic program window. The ExitButtonListener class is tiny and its code could be written “inline” in the program itself, but we didn’t want to clutter the program with cryptic code and syntax. In a GUI program the program itself defines the initial dimensions of the program window. In an applet, the dimensions are defined in the &lt;applet&gt; tag in the HTML file.
  • #33: Like JFrame , JApplet is also a Swing library class — but for an applet. We redefine its init method.
  • #34: What are some of the current software development concerns? Team development, reusability, easier maintenance, portability, user-friendliness. What is OOP? Object-Oriented Programming — a program simulates a world of active objects. Define inheritance. Inheritance is when one class (a subclass) extends another class (the superclass), adding new features and/or redefining some of the features. What are editor, compiler, linker, debugger used for? Creating source code (program text); compiling source into object code (CPU instructions); combining object module(s) and libraries into an executable program; running a program in a controlled manner and correcting bugs, respectively. Define IDE. Integrated Development Environment — combines software development tools under one GUI. How is a compiler different from an interpreter? A compiler creates object modules that can be linked into an executable. The compiler is not needed to run the executable. An interpreter interprets the source and executes appropriate instructions. It must be installed and active to execute program statements.
  • #35: Name some benefits of Java’s compiler + interpreter approach. Bytecodes are device-independent, load faster, allow for security checks, and don’t reveal source code. What is a console application? An application in the style of the old teletype or terminal (console): uses a dialog with text prompts and user input. What are command-line arguments? An array of strings passed to the program from the operating system command line that runs the program (or from a special option box in an IDE). What is a GUI application? An application with a graphical user interface, often used with a mouse or another pointing device. What is the difference between a GUI application and an applet? An application runs on the computer where it is installed. An applet is embedded in a web page and is usually downloaded from the Internet (or a local network) together with the HTML document. Where does the EasyReader class come from? What does it do? It comes from Maria and Gary Litvin with the Java Methods book. It simplifies console input and reading files.