SlideShare a Scribd company logo
Java How to Program, 10/e
Late Objects Version
©1992-2015 by Pearson Education, Inc. All Rights Reserved.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 Java is one of the world’s most widely used computer
programming languages.
 You’ll learn to write instructions commanding
computers to perform tasks.
 Software (i.e., the instructions you write) controls
hardware (i.e., computers).
 You’ll learn object-oriented programming—today’s
key programming methodology.
 You’ll create and work with many software objects.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 For many organizations, the preferred language for
meeting their enterprise programming needs is Java.
 Java is also widely used for implementing Internet-
based applications and software for devices that
communicate over a network.
 According to Oracle, 97% of enterprise desktops, 89%
of PC desktops, three billion devices (Fig. 1.1) and
100% of all Blu-ray Disc™ players run Java, and there
are over 9 million Java developers.
(http://www.oracle.com/technetwork/articles/java/javaone12revie
w-1863742.html.)
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
Java Standard Edition
Java How to Program, 10/e is based on Java Standard
Edition 7 (Java SE 7) and Java Standard Edition 8 (Java
SE 8)
Java Standard Edition contains the capabilities needed
to develop desktop and server applications.
Prior to Java SE 8, Java supported three programming
paradigms—procedural programming, object-oriented
programming and generic programming. Java SE 8 adds
functional programming.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
Java Enterprise Edition
Java is used in such a broad spectrum of applications
that it has two other editions.
The Java Enterprise Edition (Java EE) is geared toward
developing large-scale, distributed networking
applications and web-based applications.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 Java Micro Edition (Java ME)
◦ a subset of Java SE.
◦ geared toward developing applications for resource-
constrained embedded devices, such as
 Smartwatches
 MP3 players
 television set-top boxes
 smart meters (for monitoring electric energy usage)
 and more.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 Computers can perform calculations and make logical
decisions phenomenally faster than human beings can.
 Today’s personal computers can perform billions of
calculations in one second—more than a human can
perform in a lifetime.
 Supercomputers are already performing thousands of
trillions (quadrillions) of instructions per second!
 Computers process data under the control of sequences of
instructions called computer programs.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 These software programs guide the computer through
ordered actions specified by people called computer
programmers.
 You’ll learn a key programming methodology that’s
enhancing programmer productivity, thereby reducing
software development costs—object-oriented programming.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 A computer consists of various devices referred to as
hardware
◦ (e.g., the keyboard, screen, mouse, hard disks, memory, DVD drives
and processing units).
 Computing costs are dropping dramatically, owing to rapid
developments in hardware and software technologies.
 Computers that might have filled large rooms and cost
millions of dollars decades ago are now inscribed on silicon
chips smaller than a fingernail, costing perhaps a few
dollars each.
 Silicon-chip technology has made computing so economical
that computers have become a commodity.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 Every year or two, the capacities of computers have
approximately doubled inexpensively.
 This remarkable trend often is called Moore’s Law.
 Named for the person who identified the trend, Gordon
Moore, co-founder of Intel.
 Moore’s Law and related observations apply especially
to the amount of memory that computers have for
programs, the amount of secondary storage (such as disk
storage) they have to hold programs and data over longer
periods of time, and their processor speeds—the speeds
at which they execute their programs (i.e., do their work).
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 Similar growth has occurred in the communications
field.
 Costs have plummeted as enormous demand for
communications bandwidth (i.e., information-carrying
capacity) has attracted intense competition.
 Such phenomenal improvement is fostering the
Information Revolution.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 Objects, or more precisely, the classes objects come
from, are essentially reusable software components.
◦ There are date objects, time objects, audio objects, video
objects, automobile objects, people objects, etc.
◦ Almost any noun can be reasonably represented as a software
object in terms of attributes (e.g., name, color and size) and
behaviors (e.g., calculating, moving and communicating).
 Software development groups can use a modular,
object-oriented design-and-implementation approach
to be much more productive than with earlier popular
techniques like “structured programming”—object-
oriented programs are often easier to understand,
correct and modify.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 The Automobile as an Object
◦ Let’s begin with a simple analogy.
◦ Suppose you want to drive a car and make it go faster by pressing its
accelerator pedal.
◦ Before you can drive a car, someone has to design it.
◦ A car typically begins as engineering drawings, similar to the blueprints
that describe the design of a house.
◦ Drawings include the design for an accelerator pedal.
◦ Pedal hides from the driver the complex mechanisms that actually make
the car go faster, just as the brake pedal hides the mechanisms that slow
the car, and the steering wheel “hides” the mechanisms that turn the car.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
◦ Enables people with little or no knowledge of how engines,
braking and steering mechanisms work to drive a car easily.
◦ Before you can drive a car, it must be built from the
engineering drawings that describe it.
◦ A completed car has an actual accelerator pedal to make it go
faster, but even that’s not enough—the car won’t accelerate on
its own (hopefully!), so the driver must press the pedal to
accelerate the car.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 Performing a task in a program requires a method.
 The method houses the program statements that actually
perform its tasks.
 Hides these statements from its user, just as the accelerator
pedal of a car hides from the driver the mechanisms of
making the car go faster.
 In Java, we create a program unit called a class to house the
set of methods that perform the class’s tasks.
 A class is similar in concept to a car’s engineering
drawings, which house the design of an accelerator pedal,
steering wheel, and so on.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 Just as someone has to build a car from its engineering
drawings before you can actually drive a car, you must
build an object of a class before a program can perform
the tasks that the class’s methods define.
 An object is then referred to as an instance of its class.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 Just as a car’s engineering drawings can be reused many times
to build many cars, you can reuse a class many times to build
many objects.
 Reuse of existing classes when building new classes and
programs saves time and effort.
 Reuse also helps you build more reliable and effective
systems, because existing classes and components often have
undergone extensive testing, debugging and performance
tuning.
 Just as the notion of interchangeable parts was crucial to the
Industrial Revolution, reusable classes are crucial to the
software revolution that has been spurred by object
technology.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 When you drive a car, pressing its gas pedal sends a
message to the car to perform a task—that is, to go
faster.
 Similarly, you send messages to an object.
 Each message is implemented as a method call that
tells a method of the object to perform its task.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 A car has attributes
 Color, its number of doors, the amount of gas in its
tank, its current speed and its record of total miles
driven (i.e., its odometer reading).
 The car’s attributes are represented as part of its design
in its engineering diagrams.
 Every car maintains its own attributes.
 Each car knows how much gas is in its own gas tank,
but not how much is in the tanks of other cars.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
◦ An object, has attributes that it carries along as it’s used in a
program.
◦ Specified as part of the object’s class.
◦ A bank-account object has a balance attribute that represents
the amount of money in the account.
◦ Each bank-account object knows the balance in the account it
represents, but not the balances of the other accounts in the
bank.
◦ Attributes are specified by the class’s instance variables.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 Classes (and their objects) encapsulate, i.e., encase,
their attributes and methods.
 Objects may communicate with one another, but
they’re normally not allowed to know how other
objects are implemented—implementation details are
hidden within the objects themselves.
 Information hiding, as we’ll see, is crucial to good
software engineering.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 A new class of objects can be created conveniently by
inheritance—the new class (called the subclass) starts
with the characteristics of an existing class (called the
superclass), possibly customizing them and adding
unique characteristics of its own.
 In our car analogy, an object of class “convertible”
certainly is an object of the more general class
“automobile,” but more specifically, the roof can be
raised or lowered.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 Interfaces are collections of related methods that typically
enable you to tell objects what to do, but not how to do it
(we’ll see an exception to this in Java SE 8).
 In the car analogy, a “basic-driving-capabilities” interface
consisting of a steering wheel, an accelerator pedal and a
brake pedal would enable a driver to tell the car what to do.
 Once you know how to use this interface for turning,
accelerating and braking, you can drive many types of cars,
even though manufacturers may implement these systems
differently.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 A class implements zero or more interfaces, each of which can
have one or more methods, just as a car implements separate
interfaces for basic driving functions, controlling the radio,
controlling the heating and air conditioning systems, and the
like.
 Just as car manufacturers implement capabilities differently,
classes may implement an interface’s methods differently.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 How will you create the code (i.e., the program
instructions) for your programs?
 Follow a detailed analysis process for determining your
project’s requirements (i.e., defining what the system is
supposed to do)
 Develop a design that satisfies them (i.e., specifying
how the system should do it).
 Carefully review the design (and have your design
reviewed by other software professionals) before
writing any code.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 Analyzing and designing your system from an object-
oriented point of view is called an object-oriented-
analysis-and-design (OOAD) process.
 Languages like Java are object oriented.
 Object-oriented programming (OOP) allows you to
implement an object-oriented design as a working
system.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 The Unified Modeling Language (UML) is the most
widely used graphical scheme for modeling object-
oriented systems.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 Microprocessors have had a profound impact in
intelligent consumer-electronic devices.
 1991
◦ Recognizing this, Sun Microsystems funded an internal
corporate research project led by James Gosling, which
resulted in a C++-based object-oriented programming language
that Sun called Java.
◦ Key goal of Java is to be able to write programs that will run
on a great variety of computer systems and computer-
controlled devices.
◦ This is sometimes called “write once, run anywhere.”
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 1993
◦ The web exploded in popularity
◦ Sun saw the potential of using Java to add dynamic content to
web pages.
 Java drew the attention of the business community
because of the phenomenal interest in the web.
 Java is used to develop large-scale enterprise
applications, to enhance the functionality of web
servers, to provide applications for consumer devices
and for many other purposes.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
Java Class Libraries
Rich collections of existing classes and methods
Also known as the Java APIs (Application Programming
Interfaces).
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 Normally there are five phases
◦ edit
◦ compile
◦ load
◦ verify
◦ execute.
 See the Before You Begin section for information on
downloading and installing the JDK on Windows,
Linux and OS X.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 Phase 1 consists of editing a file with an editor
program
◦ Using the editor, you type a Java program (source code).
◦ Make any necessary corrections.
◦ Save the program.
◦ Java source code files are given a name ending with the .java
extension indicating that the file contains Java source code.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 Linux editors: vi and emacs.
 Windows provides Notepad.
 OSX provides TextEdit.
 Many freeware and shareware editors available online:
◦ Notepad++ (notepad-plus-plus.org)
◦ EditPlus (www.editplus.com)
◦ TextPad (www.textpad.com)
◦ jEdit (www.jedit.org).
 Integrated development environments (IDEs)
◦ Provide tools that support the software development process, such as
editors, debuggers for locating logic errors (errors that cause programs
to execute incorrectly) and more.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 Popular Java IDEs
◦ Eclipse (www.eclipse.org)
◦ NetBeans (www.netbeans.org)
◦ IntelliJ IDEA (www.jetbrains.com)
 On the book’s website at
www.deitel.com/books/jhtp10
◦ Dive-Into® videos that show you how to execute this book’s
Java applications and how to develop new Java applications
with Eclipse, NetBeans and IntelliJ IDEA.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 Phase 2: Compiling a Java Program into Bytecodes
◦ Use the command javac (the Java compiler) to compile a
program. For example, to compile a program called
Welcome.java, you’d type
 javac Welcome.java
◦ If the program compiles, the compiler produces a .class file
called Welcome.class that contains the compiled version.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 Java compiler translates Java source code into bytecodes
that represent the tasks to execute.
 The Java Virtual Machine (JVM)—a part of the JDK and
the foundation of the Java platform—executes bytecodes.
 Virtual machine (VM)—a software application that
simulates a computer
◦ Hides the underlying operating system and hardware from the
programs that interact with it.
 If the same VM is implemented on many computer
platforms, applications written for that type of VM can be
used on all those platforms.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 Bytecode instructions are platform independent
 Bytecodes are portable
◦ The same bytecode instructions can execute on any platform
containing a JVM that understands the version of Java in which the
bytecode instructions were compiled.
 The JVM is invoked by the java command. For example, to
execute a Java application called Welcome, you’d type the
command
 java Welcome
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 Phase 3: Loading a Program into Memory
◦ The JVM places the program in memory to execute it—this is
known as loading.
◦ Class loader takes the .class files containing the program’s
bytecodes and transfers them to primary memory.
◦ Also loads any of the .class files provided by Java that your
program uses.
 The .class files can be loaded from a disk on your
system or over a network.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 Phase 4: Bytecode Verification
◦ As the classes are loaded, the bytecode verifier examines their
bytecodes
◦ Ensures that they’re valid and do not violate Java’s security
restrictions.
 Java enforces strong security to make sure that Java
programs arriving over the network do not damage
your files or your system (as computer viruses and
worms might).
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
 Phase 5: Execution
◦ The JVM executes the program’s bytecodes.
◦ JVMs typically execute bytecodes using a combination of
interpretation and so-called just-in-time (JIT) compilation.
◦ Analyzes the bytecodes as they’re interpreted
◦ A just-in-time (JIT) compiler—such as Oracle’s Java HotSpot™
compiler—translates the bytecodes into the underlying computer’s
machine language.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
◦ When the JVM encounters these compiled parts again, the
faster machine-language code executes.
◦ Java programs go through two compilation phases
◦ One in which source code is translated into bytecodes (for
portability across JVMs on different computer platforms)
and
◦ A second in which, during execution, the bytecodes are
translated into machine language for the actual computer on
which the program executes.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.
©1992-2015 by Pearson Education, Inc. All
Rights Reserved.

More Related Content

PPTX
1.2_IntrotoOOP.pptx
PPTX
GDSC FY Orientation.pptx
PDF
01장 Introduction to Computers and Java
DOC
Resume
DOC
Dot Net Profile
DOC
Resume
PPTX
Intro to C++ - Class 2 - Objects & Classes
PPTX
Intro To C++ - Class 2 - An Introduction To C++
1.2_IntrotoOOP.pptx
GDSC FY Orientation.pptx
01장 Introduction to Computers and Java
Resume
Dot Net Profile
Resume
Intro to C++ - Class 2 - Objects & Classes
Intro To C++ - Class 2 - An Introduction To C++

Similar to Introduction to Computers, the Internet and java (20)

PPTX
IT Technologies Career perspective
DOCX
Over view of Technologies
PDF
Project report
PPT
pengenalan mengenai computer dan internet
DOCX
Basic Computer.docx
PDF
Parallel universe-issue-29
PDF
Baparekraf Digital Talent Day: Monitoring dan Coaching Penerima Fasilitasi BD...
PDF
Engineering Effectiveness
PDF
Jobs in the Cloud
PDF
Software development Services
PDF
Cloudsclick profile
PDF
Web Development SEO Expate BD LTD 1 01.02.2023 .pdf
PPTX
Automotive Software Cost Estimation - The UCE Approach - Emmanuel Mary
PDF
IRJET- Cross-Platform Supported E-Learning Mobile Application
PDF
The 4 d space of future automotive mobility; klaus schaaf @ yotr
PDF
Mse sept13 (3/3)
PDF
Making machine learning model deployment boring - Big Data Expo 2019
PDF
Portable Code Compiler
DOCX
ICT, Importance of programming and programming languages
DOC
Resume-RDn-Detailed
IT Technologies Career perspective
Over view of Technologies
Project report
pengenalan mengenai computer dan internet
Basic Computer.docx
Parallel universe-issue-29
Baparekraf Digital Talent Day: Monitoring dan Coaching Penerima Fasilitasi BD...
Engineering Effectiveness
Jobs in the Cloud
Software development Services
Cloudsclick profile
Web Development SEO Expate BD LTD 1 01.02.2023 .pdf
Automotive Software Cost Estimation - The UCE Approach - Emmanuel Mary
IRJET- Cross-Platform Supported E-Learning Mobile Application
The 4 d space of future automotive mobility; klaus schaaf @ yotr
Mse sept13 (3/3)
Making machine learning model deployment boring - Big Data Expo 2019
Portable Code Compiler
ICT, Importance of programming and programming languages
Resume-RDn-Detailed
Ad

Recently uploaded (20)

PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
assetexplorer- product-overview - presentation
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
ai tools demonstartion for schools and inter college
PDF
top salesforce developer skills in 2025.pdf
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
Introduction to Artificial Intelligence
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Odoo Companies in India – Driving Business Transformation.pdf
Design an Analysis of Algorithms II-SECS-1021-03
Computer Software and OS of computer science of grade 11.pptx
Designing Intelligence for the Shop Floor.pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
assetexplorer- product-overview - presentation
How to Choose the Right IT Partner for Your Business in Malaysia
Softaken Excel to vCard Converter Software.pdf
ai tools demonstartion for schools and inter college
top salesforce developer skills in 2025.pdf
Design an Analysis of Algorithms I-SECS-1021-03
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
VVF-Customer-Presentation2025-Ver1.9.pptx
2025 Textile ERP Trends: SAP, Odoo & Oracle
Understanding Forklifts - TECH EHS Solution
Introduction to Artificial Intelligence
Ad

Introduction to Computers, the Internet and java

  • 1. Java How to Program, 10/e Late Objects Version ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 2. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 3. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 4. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 5.  Java is one of the world’s most widely used computer programming languages.  You’ll learn to write instructions commanding computers to perform tasks.  Software (i.e., the instructions you write) controls hardware (i.e., computers).  You’ll learn object-oriented programming—today’s key programming methodology.  You’ll create and work with many software objects. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 6.  For many organizations, the preferred language for meeting their enterprise programming needs is Java.  Java is also widely used for implementing Internet- based applications and software for devices that communicate over a network.  According to Oracle, 97% of enterprise desktops, 89% of PC desktops, three billion devices (Fig. 1.1) and 100% of all Blu-ray Disc™ players run Java, and there are over 9 million Java developers. (http://www.oracle.com/technetwork/articles/java/javaone12revie w-1863742.html.) ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 7. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 8. Java Standard Edition Java How to Program, 10/e is based on Java Standard Edition 7 (Java SE 7) and Java Standard Edition 8 (Java SE 8) Java Standard Edition contains the capabilities needed to develop desktop and server applications. Prior to Java SE 8, Java supported three programming paradigms—procedural programming, object-oriented programming and generic programming. Java SE 8 adds functional programming. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 9. Java Enterprise Edition Java is used in such a broad spectrum of applications that it has two other editions. The Java Enterprise Edition (Java EE) is geared toward developing large-scale, distributed networking applications and web-based applications. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 10.  Java Micro Edition (Java ME) ◦ a subset of Java SE. ◦ geared toward developing applications for resource- constrained embedded devices, such as  Smartwatches  MP3 players  television set-top boxes  smart meters (for monitoring electric energy usage)  and more. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 11.  Computers can perform calculations and make logical decisions phenomenally faster than human beings can.  Today’s personal computers can perform billions of calculations in one second—more than a human can perform in a lifetime.  Supercomputers are already performing thousands of trillions (quadrillions) of instructions per second!  Computers process data under the control of sequences of instructions called computer programs. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 12.  These software programs guide the computer through ordered actions specified by people called computer programmers.  You’ll learn a key programming methodology that’s enhancing programmer productivity, thereby reducing software development costs—object-oriented programming. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 13.  A computer consists of various devices referred to as hardware ◦ (e.g., the keyboard, screen, mouse, hard disks, memory, DVD drives and processing units).  Computing costs are dropping dramatically, owing to rapid developments in hardware and software technologies.  Computers that might have filled large rooms and cost millions of dollars decades ago are now inscribed on silicon chips smaller than a fingernail, costing perhaps a few dollars each.  Silicon-chip technology has made computing so economical that computers have become a commodity. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 14.  Every year or two, the capacities of computers have approximately doubled inexpensively.  This remarkable trend often is called Moore’s Law.  Named for the person who identified the trend, Gordon Moore, co-founder of Intel.  Moore’s Law and related observations apply especially to the amount of memory that computers have for programs, the amount of secondary storage (such as disk storage) they have to hold programs and data over longer periods of time, and their processor speeds—the speeds at which they execute their programs (i.e., do their work). ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 15.  Similar growth has occurred in the communications field.  Costs have plummeted as enormous demand for communications bandwidth (i.e., information-carrying capacity) has attracted intense competition.  Such phenomenal improvement is fostering the Information Revolution. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 16.  Objects, or more precisely, the classes objects come from, are essentially reusable software components. ◦ There are date objects, time objects, audio objects, video objects, automobile objects, people objects, etc. ◦ Almost any noun can be reasonably represented as a software object in terms of attributes (e.g., name, color and size) and behaviors (e.g., calculating, moving and communicating).  Software development groups can use a modular, object-oriented design-and-implementation approach to be much more productive than with earlier popular techniques like “structured programming”—object- oriented programs are often easier to understand, correct and modify. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 17.  The Automobile as an Object ◦ Let’s begin with a simple analogy. ◦ Suppose you want to drive a car and make it go faster by pressing its accelerator pedal. ◦ Before you can drive a car, someone has to design it. ◦ A car typically begins as engineering drawings, similar to the blueprints that describe the design of a house. ◦ Drawings include the design for an accelerator pedal. ◦ Pedal hides from the driver the complex mechanisms that actually make the car go faster, just as the brake pedal hides the mechanisms that slow the car, and the steering wheel “hides” the mechanisms that turn the car. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 18. ◦ Enables people with little or no knowledge of how engines, braking and steering mechanisms work to drive a car easily. ◦ Before you can drive a car, it must be built from the engineering drawings that describe it. ◦ A completed car has an actual accelerator pedal to make it go faster, but even that’s not enough—the car won’t accelerate on its own (hopefully!), so the driver must press the pedal to accelerate the car. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 19.  Performing a task in a program requires a method.  The method houses the program statements that actually perform its tasks.  Hides these statements from its user, just as the accelerator pedal of a car hides from the driver the mechanisms of making the car go faster.  In Java, we create a program unit called a class to house the set of methods that perform the class’s tasks.  A class is similar in concept to a car’s engineering drawings, which house the design of an accelerator pedal, steering wheel, and so on. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 20.  Just as someone has to build a car from its engineering drawings before you can actually drive a car, you must build an object of a class before a program can perform the tasks that the class’s methods define.  An object is then referred to as an instance of its class. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 21.  Just as a car’s engineering drawings can be reused many times to build many cars, you can reuse a class many times to build many objects.  Reuse of existing classes when building new classes and programs saves time and effort.  Reuse also helps you build more reliable and effective systems, because existing classes and components often have undergone extensive testing, debugging and performance tuning.  Just as the notion of interchangeable parts was crucial to the Industrial Revolution, reusable classes are crucial to the software revolution that has been spurred by object technology. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 22. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 23.  When you drive a car, pressing its gas pedal sends a message to the car to perform a task—that is, to go faster.  Similarly, you send messages to an object.  Each message is implemented as a method call that tells a method of the object to perform its task. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 24.  A car has attributes  Color, its number of doors, the amount of gas in its tank, its current speed and its record of total miles driven (i.e., its odometer reading).  The car’s attributes are represented as part of its design in its engineering diagrams.  Every car maintains its own attributes.  Each car knows how much gas is in its own gas tank, but not how much is in the tanks of other cars. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 25. ◦ An object, has attributes that it carries along as it’s used in a program. ◦ Specified as part of the object’s class. ◦ A bank-account object has a balance attribute that represents the amount of money in the account. ◦ Each bank-account object knows the balance in the account it represents, but not the balances of the other accounts in the bank. ◦ Attributes are specified by the class’s instance variables. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 26.  Classes (and their objects) encapsulate, i.e., encase, their attributes and methods.  Objects may communicate with one another, but they’re normally not allowed to know how other objects are implemented—implementation details are hidden within the objects themselves.  Information hiding, as we’ll see, is crucial to good software engineering. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 27.  A new class of objects can be created conveniently by inheritance—the new class (called the subclass) starts with the characteristics of an existing class (called the superclass), possibly customizing them and adding unique characteristics of its own.  In our car analogy, an object of class “convertible” certainly is an object of the more general class “automobile,” but more specifically, the roof can be raised or lowered. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 28.  Interfaces are collections of related methods that typically enable you to tell objects what to do, but not how to do it (we’ll see an exception to this in Java SE 8).  In the car analogy, a “basic-driving-capabilities” interface consisting of a steering wheel, an accelerator pedal and a brake pedal would enable a driver to tell the car what to do.  Once you know how to use this interface for turning, accelerating and braking, you can drive many types of cars, even though manufacturers may implement these systems differently. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 29.  A class implements zero or more interfaces, each of which can have one or more methods, just as a car implements separate interfaces for basic driving functions, controlling the radio, controlling the heating and air conditioning systems, and the like.  Just as car manufacturers implement capabilities differently, classes may implement an interface’s methods differently. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 30.  How will you create the code (i.e., the program instructions) for your programs?  Follow a detailed analysis process for determining your project’s requirements (i.e., defining what the system is supposed to do)  Develop a design that satisfies them (i.e., specifying how the system should do it).  Carefully review the design (and have your design reviewed by other software professionals) before writing any code. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 31.  Analyzing and designing your system from an object- oriented point of view is called an object-oriented- analysis-and-design (OOAD) process.  Languages like Java are object oriented.  Object-oriented programming (OOP) allows you to implement an object-oriented design as a working system. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 32.  The Unified Modeling Language (UML) is the most widely used graphical scheme for modeling object- oriented systems. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 33.  Microprocessors have had a profound impact in intelligent consumer-electronic devices.  1991 ◦ Recognizing this, Sun Microsystems funded an internal corporate research project led by James Gosling, which resulted in a C++-based object-oriented programming language that Sun called Java. ◦ Key goal of Java is to be able to write programs that will run on a great variety of computer systems and computer- controlled devices. ◦ This is sometimes called “write once, run anywhere.” ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 34.  1993 ◦ The web exploded in popularity ◦ Sun saw the potential of using Java to add dynamic content to web pages.  Java drew the attention of the business community because of the phenomenal interest in the web.  Java is used to develop large-scale enterprise applications, to enhance the functionality of web servers, to provide applications for consumer devices and for many other purposes. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 35. Java Class Libraries Rich collections of existing classes and methods Also known as the Java APIs (Application Programming Interfaces). ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 36. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 37.  Normally there are five phases ◦ edit ◦ compile ◦ load ◦ verify ◦ execute.  See the Before You Begin section for information on downloading and installing the JDK on Windows, Linux and OS X. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 38.  Phase 1 consists of editing a file with an editor program ◦ Using the editor, you type a Java program (source code). ◦ Make any necessary corrections. ◦ Save the program. ◦ Java source code files are given a name ending with the .java extension indicating that the file contains Java source code. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 39. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 40.  Linux editors: vi and emacs.  Windows provides Notepad.  OSX provides TextEdit.  Many freeware and shareware editors available online: ◦ Notepad++ (notepad-plus-plus.org) ◦ EditPlus (www.editplus.com) ◦ TextPad (www.textpad.com) ◦ jEdit (www.jedit.org).  Integrated development environments (IDEs) ◦ Provide tools that support the software development process, such as editors, debuggers for locating logic errors (errors that cause programs to execute incorrectly) and more. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 41.  Popular Java IDEs ◦ Eclipse (www.eclipse.org) ◦ NetBeans (www.netbeans.org) ◦ IntelliJ IDEA (www.jetbrains.com)  On the book’s website at www.deitel.com/books/jhtp10 ◦ Dive-Into® videos that show you how to execute this book’s Java applications and how to develop new Java applications with Eclipse, NetBeans and IntelliJ IDEA. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 42.  Phase 2: Compiling a Java Program into Bytecodes ◦ Use the command javac (the Java compiler) to compile a program. For example, to compile a program called Welcome.java, you’d type  javac Welcome.java ◦ If the program compiles, the compiler produces a .class file called Welcome.class that contains the compiled version. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 43. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 44.  Java compiler translates Java source code into bytecodes that represent the tasks to execute.  The Java Virtual Machine (JVM)—a part of the JDK and the foundation of the Java platform—executes bytecodes.  Virtual machine (VM)—a software application that simulates a computer ◦ Hides the underlying operating system and hardware from the programs that interact with it.  If the same VM is implemented on many computer platforms, applications written for that type of VM can be used on all those platforms. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 45.  Bytecode instructions are platform independent  Bytecodes are portable ◦ The same bytecode instructions can execute on any platform containing a JVM that understands the version of Java in which the bytecode instructions were compiled.  The JVM is invoked by the java command. For example, to execute a Java application called Welcome, you’d type the command  java Welcome ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 46.  Phase 3: Loading a Program into Memory ◦ The JVM places the program in memory to execute it—this is known as loading. ◦ Class loader takes the .class files containing the program’s bytecodes and transfers them to primary memory. ◦ Also loads any of the .class files provided by Java that your program uses.  The .class files can be loaded from a disk on your system or over a network. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 47. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 48.  Phase 4: Bytecode Verification ◦ As the classes are loaded, the bytecode verifier examines their bytecodes ◦ Ensures that they’re valid and do not violate Java’s security restrictions.  Java enforces strong security to make sure that Java programs arriving over the network do not damage your files or your system (as computer viruses and worms might). ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 49. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 50.  Phase 5: Execution ◦ The JVM executes the program’s bytecodes. ◦ JVMs typically execute bytecodes using a combination of interpretation and so-called just-in-time (JIT) compilation. ◦ Analyzes the bytecodes as they’re interpreted ◦ A just-in-time (JIT) compiler—such as Oracle’s Java HotSpot™ compiler—translates the bytecodes into the underlying computer’s machine language. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 51. ◦ When the JVM encounters these compiled parts again, the faster machine-language code executes. ◦ Java programs go through two compilation phases ◦ One in which source code is translated into bytecodes (for portability across JVMs on different computer platforms) and ◦ A second in which, during execution, the bytecodes are translated into machine language for the actual computer on which the program executes. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.
  • 52. ©1992-2015 by Pearson Education, Inc. All Rights Reserved.