Escolar Documentos
Profissional Documentos
Cultura Documentos
TSF 1030
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
Objectives
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
What is a Computer?
A computer consists of a CPU, memory, hard disk, floppy disk,
monitor, printer, and communication devices.
Bus
Storage
Devices
e.g., Disk, CD,
and Tape
Memory
CPU
Communication
Devices
Input
Devices
Output
Devices
e.g., Modem,
and NIC
e.g., Keyboard,
Mouse
e.g., Monitor,
Printer
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
Programs
Computer programs, known as software, are instructions to the
computer.
Through programs we tell a computer what to do
Without programs, a computer is an empty machine.
Computers do not understand human languages, so you need to use
computer languages to communicate with them.
Programs are written using programming languages.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
Programming Languages
Machine Language Assembly Language
High-Level Language
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
Programming Languages
Machine Language
Assembly Language
High-Level Language
Assembler
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
1101101010011010
Programming Languages
Machine Language Assembly Language
High-Level Language
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
Source File
Compiler
Machine-language
File
Linker
Executable File
What is OOP?
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
What is OOP?
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
Why Java?
Java enables users to develop and deploy applications on the
Internet
for servers,
desktop
computers, and
small
hand-held devices.
The future of computing is being profoundly influenced by the Internet, and Java
promises to remain a big part of that future.
Java is a general purpose programming language.
Java
12
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
Javas History
Oak
HotJava
The first Java-enabled Web browser
http://java.sun.com/features/1998/05/birthday.html
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
15
Companion
Website
Characteristics of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java Is Robust
Java Is Secure
Java Is Architecture-Neutral
Java Is Portable
Java's Performance
Java Is Multithreaded
Java Is Dynamic
www.cs.armstrong.edu/liang/intro8e/JavaCharacteristics.pdf
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
16
Companion
Website
Characteristics of Java
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
17
Companion
Website
Characteristics of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java Is Robust
Java Is Secure
Java Is Architecture-Neutral
Java Is Portable
Java's Performance
Java Is Multithreaded
Java Is Dynamic
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
18
Companion
Website
Characteristics of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java Is Robust
Java Is Secure
Java Is Architecture-Neutral
Java Is Portable
Java's Performance
Java Is Multithreaded
Java Is Dynamic
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
19
Companion
Website
Characteristics of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java Is Robust
Java Is Secure
Java Is Architecture-Neutral
Java Is Portable
Java's Performance
Java Is Multithreaded
Java Is Dynamic
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
20
Companion
Website
Characteristics of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java Is Robust
Java Is Secure
Java Is Architecture-Neutral
Java Is Portable
Java's Performance
Java Is Multithreaded
Java Is Dynamic
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
21
Companion
Website
Characteristics of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java implements several security
Java Is Robust
mechanisms to protect your system against
harm caused by stray programs.
Java Is Secure
Java Is Architecture-Neutral
Java Is Portable
Java's Performance
Java Is Multithreaded
Java Is Dynamic
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
22
Companion
Website
Characteristics of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java Is Robust
Java Is Secure
Java Is Architecture-Neutral
Java Is Portable
Java's Performance
Java Is Multithreaded
Java Is Dynamic
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
23
Companion
Website
Characteristics of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java Is Robust
Java Is Secure
Java Is Architecture-Neutral
Because Java is architecture
Java Is Portable
neutral, Java programs are
Java's Performance
portable. They can be run on any
platform without being
Java Is Multithreaded
recompiled.
Java Is Dynamic
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
24
Companion
Website
Characteristics of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java Is Robust
Java Is Secure
Java Is Architecture-Neutral
Javas performance Because Java
Java Is Portable
is architecture neutral, Java
Java's Performance
programs are portable. They can
be run on any platform without
Java Is Multithreaded
being recompiled.
Java Is Dynamic
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
25
Companion
Website
Characteristics of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java Is Robust
Java Is Secure
Java Is Architecture-Neutral
Java Is Portable
Java's Performance
Multithread programming is smoothly
Java Is Multithreaded integrated in Java, whereas in other
languages you have to call
Java Is Dynamic
procedures specific to the operating
system to enable multithreading.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
26
Companion
Website
Characteristics of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java Is Robust
Java Is Secure
Java Is Architecture-Neutral
Java Is Portable
Java was designed to adapt to an
Java's Performance
evolving environment. New code can be
loaded on the fly without recompilation.
Java Is Multithreaded
There is no need for developers to create,
Java Is Dynamic
and for users to install, major new
software versions. New features can be
incorporated transparently as needed.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
27
JDK Versions
28
JDK Editions
29
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
30
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
31
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
32
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
33
Method Welcome()
0 aload_0
Source Code
Bytecode
Run Byteode
i.e., java Welcome
Result
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011IfPearson
Education,
Inc. All
runtime errors
or incorrect
result
rights reserved. 0132130807
34
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
35
animation
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
36
animation
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
37
animation
38
Companion
Website
Set
set classpath=.
Compile
javac Welcome.java
Run
java Welcome
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
39
Companion
Website
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
40
words
Modifiers
Statements
Blocks
Classes
Methods
The
main method
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
41
Comments
Three types of comments in Java.
Line comment: A line comment is preceded by two
slashes (//) in a line.
Paragraph comment: A paragraph comment is enclosed
between /* and */ in one or multiple lines.
42
Reserved Words
Reserved words or keywords are words that have a
specific meaning to the compiler and cannot be used for
other purposes in the program.
For example, when the compiler sees the word class, it
understands that the word after class is the name for the
class.
Other reserved words are public, static, void
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
43
Modifiers
Java uses certain reserved words called modifiers that
specify the properties of the data, methods, and classes and
how they can be used.
Examples of modifiers are public and static.
Other modifiers are private, final, abstract, and protected.
A public datum, method, or class can be accessed by other
programs.
A private datum or method cannot be accessed by other
programs..
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
44
Statements
A statement represents an action or a sequence of actions.
The statement System.out.println("Welcome to Java!")
is a statement to display the greeting "Welcome to Java!"
Every statement in Java ends with a semicolon (;).
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
45
Blocks
A pair of braces in a program forms a block that groups
components of a program.
Class block
Method block
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
46
Classes
The class is the essential Java construct. A class is a
template or blueprint for objects.
To program in Java, you must understand classes and be
able to write and use them.
Program is defined by using one or more classes.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
47
Methods
What is System.out.println? It is a method:
a collection of statements that performs a sequence of
operations to display a message on the console.
It can be used even without fully understanding the
details of how it works.
It is used by invoking a statement with a string argument.
The string argument is enclosed within parentheses
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All
rights reserved. 0132130807
48
main Method
The main method provides the control of program flow.
The Java interpreter executes the application by invoking
the main method.
The main method looks like this:
49