SlideShare uma empresa Scribd logo
1 de 32
An Introduction to Software
Development
Java MethodsJava Methods
A & ABA & AB
Object-Oriented Programming
and Data Structures
Maria Litvin ● Gary Litvin
Copyright © 2006 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved.
Chapter 2
2-2
Objectives:
• Understand the software development
process, tools, and priorities
• Understand compilers and interpreters
• Learn about Java Virtual Machine, bytecodes
• Learn to set up and run simple console
applications, GUI applications, and applets in
Java
• Learn basic facts about OOP
2-3
Software Today:
6,460,000,000
2-4
Software Applications
• Large business
systems
• Databases
• Internet, e-mail, etc.
• Military
• Embedded systems
• Scientific research
• AI
• Word processing
and other small
business and
personal productivity
tools
• Graphics / arts /
digital photography
• Games
2-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
1950-1960's: Now:
2-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
Python
2-7
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”)
2-8
The First “Bug”
“(moth) in relay”
Mark II Aiken Relay Calculator (Harvard University, 1945)
2-9
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

2-10
Interpreted Languages:
Edit-Run
Editor Source
code
Interpreter

2-11
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
2-12
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 CPU-specific Java interpreter
interprets bytecodes on a particular
computer.
2-13
Java’s Compiler + Interpreter
Editor



Hello.java

Compiler

Hello.class


Interpreter
Hello,
World!

Interpreter
2-14
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
2-15
JDK — Java Development Kit
• javac
 Java compiler
• java
 Java interpreter
• appletviewer
 tests applets without a
browser
• javadoc
 generates HTML
documentation (“docs”)
from source
• jar
 packs classes into jar
files (packages)
All these are command-line tools,
no GUI
2-16
JDK (cont’d)
• Available free from Sun Microsystems
• All documentation is online:
• Many additional Java resources on the
Internet
http://java.sun.com/javase/index.jsp
2-17
Java IDE
• GUI front end for JDK
• 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
• Usually JDK is installed separately and an
IDE is installed on top of it.
2-18
Types of Programs
• Console applications • GUI applications
• Applets
2-19
Console Applications
C:javamethodsCh02> path=%PATH%;C:Program FilesJavajdk
1.5.0_07bin
C:javamethodsCh02> javac Greetings2.java
C:javamethodsCh02> java Greetings2
Enter your first name: Josephine
Enter your last name: Jaworski
Hello, Josephine Jaworski
Press any key to continue...
• Simple text dialog:
prompt → input, prompt → input ... → result
2-20
Command-Line Arguments
C:javamethodsCh02> javac Greetings.java
C:javamethodsCh02> java Greetings Josephine Jaworski
Hello, Josephine Jaworski
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.
2-21
Command-Line Args (cont’d)
• Can be used in GUI applications, too
• IDEs provide ways to set them (or
prompt for them)
Josephine Jaworski
2-22
Greetings2.java
import 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: ");
String firstName = kboard.nextLine( );
System.out.print("Enter your last name: ");
String lastName = kboard.nextLine( );
System.out.println("Hello, " + firstName + " " + lastName);
System.out.println("Welcome to Java!");
}
}
Prompts
2-23
GUI Applications
Menus
Buttons
Clickable
panel
Slider
2-24
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( );
// 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_CLOSE);
window.setVisible(true);
}
}
GUI libraries
2-25
HelloApplet.java
import java.awt.*;
import javax.swing.*;
public class HelloApplet extends JApplet
{
public void init( )
{
...
}
< ... other code >
}
No main in applets: the init
method is called by JDK’s
appletviewer or the browser
2-26
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.
2-27
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.
2-28
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.
2-29
Inheritance
• A programmer can define hierarchies of
classes
• More general classes are closer to the top
Person
Child Adult
Baby Toddler Teen
2-30
OOP Benefits
• Facilitates team development
• Easier to reuse software components and
write reusable software
• Easier GUI (Graphical User Interface) and
multimedia programming
2-31
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.
2-32
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.

Mais conteúdo relacionado

Mais procurados

java training in jaipur|java training|core java training|java training compa...
 java training in jaipur|java training|core java training|java training compa... java training in jaipur|java training|core java training|java training compa...
java training in jaipur|java training|core java training|java training compa...infojaipurinfo Jaipur
 
Java buzzwords
Java buzzwordsJava buzzwords
Java buzzwordsramesh517
 
basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operatorkamal kotecha
 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)Sujit Majety
 
Introduction to Java Programming
Introduction to Java Programming Introduction to Java Programming
Introduction to Java Programming Saravanakumar R
 
Important features of java
Important features of javaImportant features of java
Important features of javaAL- AMIN
 
Advantages of java
Advantages of javaAdvantages of java
Advantages of javaxxx007008
 
Introduction to Java -unit-1
Introduction to Java -unit-1Introduction to Java -unit-1
Introduction to Java -unit-1RubaNagarajan
 
Java Programming for Designers
Java Programming for DesignersJava Programming for Designers
Java Programming for DesignersR. Sosa
 
Introduction to java
Introduction to java Introduction to java
Introduction to java Sandeep Rawat
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introductionjyoti_lakhani
 

Mais procurados (20)

java training in jaipur|java training|core java training|java training compa...
 java training in jaipur|java training|core java training|java training compa... java training in jaipur|java training|core java training|java training compa...
java training in jaipur|java training|core java training|java training compa...
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Java buzzwords
Java buzzwordsJava buzzwords
Java buzzwords
 
basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operator
 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)
 
JAVA PROGRAMMING
JAVA PROGRAMMING JAVA PROGRAMMING
JAVA PROGRAMMING
 
Java seminar
Java seminarJava seminar
Java seminar
 
Java Introduction
Java IntroductionJava Introduction
Java Introduction
 
Introduction to Java Programming
Introduction to Java Programming Introduction to Java Programming
Introduction to Java Programming
 
Important features of java
Important features of javaImportant features of java
Important features of java
 
Advantages of java
Advantages of javaAdvantages of java
Advantages of java
 
Introduction to Java -unit-1
Introduction to Java -unit-1Introduction to Java -unit-1
Introduction to Java -unit-1
 
Introduction to JAVA
Introduction to JAVAIntroduction to JAVA
Introduction to JAVA
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Core java
Core javaCore java
Core java
 
Java Programming for Designers
Java Programming for DesignersJava Programming for Designers
Java Programming for Designers
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 
Java1
Java1Java1
Java1
 
Features of java
Features of javaFeatures of java
Features of java
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introduction
 

Semelhante a Java Methods - An Introduction to Software Development

Java Chapter 2 Overview.ppt
Java Chapter 2 Overview.pptJava Chapter 2 Overview.ppt
Java Chapter 2 Overview.pptMiltonMolla1
 
Java Chapter 2 Overview.ppt
Java Chapter 2 Overview.pptJava Chapter 2 Overview.ppt
Java Chapter 2 Overview.pptMiltonMolla1
 
Introduction to Software Development
Introduction to Software DevelopmentIntroduction to Software Development
Introduction to Software DevelopmentZeeshan MIrza
 
Android course session 1 ( intoduction to java )
Android course session 1 ( intoduction to java )Android course session 1 ( intoduction to java )
Android course session 1 ( intoduction to java )Keroles M.Yakoub
 
JavaClassPresentation
JavaClassPresentationJavaClassPresentation
JavaClassPresentationjuliasceasor
 
Introduction to java
Introduction to java Introduction to java
Introduction to java Java Lover
 
Java Programming 100 Programming Challenges
Java Programming 100 Programming ChallengesJava Programming 100 Programming Challenges
Java Programming 100 Programming ChallengesJavier Crisostomo
 
PPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptPPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptRajeshSukte1
 
PPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptPPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptCDSukte
 
JAVA object oriented programming (oop).ppt
JAVA object oriented programming (oop).pptJAVA object oriented programming (oop).ppt
JAVA object oriented programming (oop).pptAliyaJav
 
Object oriented programming-with_java
Object oriented programming-with_javaObject oriented programming-with_java
Object oriented programming-with_javaHarry Potter
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programmingJames Wong
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programmingLuis Goldster
 

Semelhante a Java Methods - An Introduction to Software Development (20)

Java Chapter 2 Overview.ppt
Java Chapter 2 Overview.pptJava Chapter 2 Overview.ppt
Java Chapter 2 Overview.ppt
 
Java Chapter 2 Overview.ppt
Java Chapter 2 Overview.pptJava Chapter 2 Overview.ppt
Java Chapter 2 Overview.ppt
 
Introduction to Software Development
Introduction to Software DevelopmentIntroduction to Software Development
Introduction to Software Development
 
unit1.pptx
unit1.pptxunit1.pptx
unit1.pptx
 
1.Intro--Why Java.pptx
1.Intro--Why Java.pptx1.Intro--Why Java.pptx
1.Intro--Why Java.pptx
 
Android course session 1 ( intoduction to java )
Android course session 1 ( intoduction to java )Android course session 1 ( intoduction to java )
Android course session 1 ( intoduction to java )
 
java slides
java slidesjava slides
java slides
 
JavaClassPresentation
JavaClassPresentationJavaClassPresentation
JavaClassPresentation
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 
Java Programming 100 Programming Challenges
Java Programming 100 Programming ChallengesJava Programming 100 Programming Challenges
Java Programming 100 Programming Challenges
 
PPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptPPS Java Overview Unit I.ppt
PPS Java Overview Unit I.ppt
 
PPS Java Overview Unit I.ppt
PPS Java Overview Unit I.pptPPS Java Overview Unit I.ppt
PPS Java Overview Unit I.ppt
 
java full 1.docx
java full 1.docxjava full 1.docx
java full 1.docx
 
java full.docx
java full.docxjava full.docx
java full.docx
 
JAVA object oriented programming (oop).ppt
JAVA object oriented programming (oop).pptJAVA object oriented programming (oop).ppt
JAVA object oriented programming (oop).ppt
 
java completed units.docx
java completed units.docxjava completed units.docx
java completed units.docx
 
java full 1 (Recovered).docx
java full 1 (Recovered).docxjava full 1 (Recovered).docx
java full 1 (Recovered).docx
 
Object oriented programming-with_java
Object oriented programming-with_javaObject oriented programming-with_java
Object oriented programming-with_java
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 

Último

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 

Último (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

Java Methods - An Introduction to Software Development

  • 1. An Introduction to Software Development Java MethodsJava Methods A & ABA & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Chapter 2
  • 2. 2-2 Objectives: • Understand the software development process, tools, and priorities • Understand compilers and interpreters • Learn about Java Virtual Machine, bytecodes • Learn to set up and run simple console applications, GUI applications, and applets in Java • Learn basic facts about OOP
  • 4. 2-4 Software Applications • Large business systems • Databases • Internet, e-mail, etc. • Military • Embedded systems • Scientific research • AI • Word processing and other small business and personal productivity tools • Graphics / arts / digital photography • Games
  • 5. 2-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 1950-1960's: Now:
  • 6. 2-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 Python
  • 7. 2-7 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”)
  • 8. 2-8 The First “Bug” “(moth) in relay” Mark II Aiken Relay Calculator (Harvard University, 1945)
  • 9. 2-9 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 
  • 11. 2-11 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
  • 12. 2-12 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 CPU-specific Java interpreter interprets bytecodes on a particular computer.
  • 13. 2-13 Java’s Compiler + Interpreter Editor    Hello.java  Compiler  Hello.class   Interpreter Hello, World!  Interpreter
  • 14. 2-14 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
  • 15. 2-15 JDK — Java Development Kit • javac  Java compiler • java  Java interpreter • appletviewer  tests applets without a browser • javadoc  generates HTML documentation (“docs”) from source • jar  packs classes into jar files (packages) All these are command-line tools, no GUI
  • 16. 2-16 JDK (cont’d) • Available free from Sun Microsystems • All documentation is online: • Many additional Java resources on the Internet http://java.sun.com/javase/index.jsp
  • 17. 2-17 Java IDE • GUI front end for JDK • 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 • Usually JDK is installed separately and an IDE is installed on top of it.
  • 18. 2-18 Types of Programs • Console applications • GUI applications • Applets
  • 19. 2-19 Console Applications C:javamethodsCh02> path=%PATH%;C:Program FilesJavajdk 1.5.0_07bin C:javamethodsCh02> javac Greetings2.java C:javamethodsCh02> java Greetings2 Enter your first name: Josephine Enter your last name: Jaworski Hello, Josephine Jaworski Press any key to continue... • Simple text dialog: prompt → input, prompt → input ... → result
  • 20. 2-20 Command-Line Arguments C:javamethodsCh02> javac Greetings.java C:javamethodsCh02> java Greetings Josephine Jaworski Hello, Josephine Jaworski 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.
  • 21. 2-21 Command-Line Args (cont’d) • Can be used in GUI applications, too • IDEs provide ways to set them (or prompt for them) Josephine Jaworski
  • 22. 2-22 Greetings2.java import 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: "); String firstName = kboard.nextLine( ); System.out.print("Enter your last name: "); String lastName = kboard.nextLine( ); System.out.println("Hello, " + firstName + " " + lastName); System.out.println("Welcome to Java!"); } } Prompts
  • 24. 2-24 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( ); // 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_CLOSE); window.setVisible(true); } } GUI libraries
  • 25. 2-25 HelloApplet.java import java.awt.*; import javax.swing.*; public class HelloApplet extends JApplet { public void init( ) { ... } < ... other code > } No main in applets: the init method is called by JDK’s appletviewer or the browser
  • 26. 2-26 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.
  • 27. 2-27 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.
  • 28. 2-28 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.
  • 29. 2-29 Inheritance • A programmer can define hierarchies of classes • More general classes are closer to the top Person Child Adult Baby Toddler Teen
  • 30. 2-30 OOP Benefits • Facilitates team development • Easier to reuse software components and write reusable software • Easier GUI (Graphical User Interface) and multimedia programming
  • 31. 2-31 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.
  • 32. 2-32 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.

Notas do Editor

  1. 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.
  2. Students with a penchant for history can find a lot of interesting historical data on programming languages and software methodologies on the Internet.
  3. A Google search for SOFTWARE results in over 6.4 billion 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.
  4. The idea of developing intelligent computers (AI, or artificial intelligence) came about as soon as (or perhaps before) the first computer. Over the years the expectations turned out to be too optimistic. Little progress to report so far.
  5. 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.
  6. 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.
  7. A programming language has a strict syntax. A compiler parses the source code and checks the syntax. There are other programming tools. For example, 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.
  8. This is a neat legend, but actually the term “bug” was used earlier.
  9. 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!
  10. When you use an interpreted language, the program that is being executed is the interpreter; the text of your program serves as data for the interpreter.
  11. 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.
  12. Java Virtual Machine is an imaginary computer with a CPU instruction set that is “the least common denominator” for typical real CPUs.
  13. 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.
  14. 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 non-lethal ones), but they will break into your computer system (which may be much more harmful and expensive) and spread computer viruses.
  15. JDK lacks an editor, so we use non-JDK software to create the source code. Our main tools are javac , java , and appletviewer . IDE usually has a more convenient debugger than JDK’s debugger. We recommend not using a debugger at all while learning how to program.
  16. It may be better to download Java docs together with the JDK and install them on the school server.
  17. 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 JDK be installed. Install the JDK first, before the IDE.
  18. Console applications emulate a teletype device; they are sometimes called terminal applications (comes from old text-only terminals).
  19. Console applications may be not much fun, but they do the job when you need to test a simple calculation or algorithm. The path=... command tells the system where to look for java.exe and javac.exe .
  20. Command-line arguments are not specific to Java: C and C++ have them, as well as other languages under Unix , MS-DOS , etc. In Windows , use the Command Prompt application. The Java source file name is a command-line argument for javac . Likewise, the HTML file name is a command-line argument for appletviewer .
  21. An IDE usually provides a way to set command-line args (on a Mac, too) or prompts for them when you run your program.
  22. The Scanner class has been added to the java.util package in Java 5.0. It simplifies reading numbers, words, and lines of text from the keyboard and files.
  23. 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 for several years.
  24. JFrame is a Swing library class for a generic program window. 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.
  25. Like JFrame , JApplet is also a Swing library class — but for an applet. We redefine its init method.
  26. “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.
  27. For example, a 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 method “forward” may call Position ’s method “move.” 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 .
  28. 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.
  29. We say that a Child IS-A (kind of) Person ; a Toddler IS-A (kind of) Child . Each subclass inherits all the methods of its superclass, and may redefine some of them and/or add new methods.
  30. 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 .
  31. What are some of the current software development concerns? Team development, reusability, easier maintenance, portability, user-friendliness. What are editor, compiler, debugger used for? Creating source code (program’s text); compiling source into object code (CPU instructions); running a program in a controlled manner and correcting bugs, respectively. 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. 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. Define IDE. Integrated Development Environment — combines software development tools under one GUI.
  32. 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. What is OOP? Object-Oriented Programming — a program simulates a world of active objects. Define inheritance. Inheritance is a way to derive a class (a subclass) from another class (the superclass), adding new features and/or redefining some of the features.