An Introduction To Computer, Programming and Java
An Introduction To Computer, Programming and Java
An Introduction To Computer, Programming and Java
1
What is a Computer?
A computer is a machine that performs computations,
logical operations, or more generally, data manipulation
according to some prescribed sequence of instructions
called a computer program.
2
The Hardware
The major hardware components:
3
The Central Processing Unit
The CPU does:
the computing
the processing
the majority of the work
4
The Central Processing Unit
The ALU performs calculations, billions per second
The CU controls or coordinates which calculations the
ALU performs
The CPU clock determines how frequently the computer
hardware executes instructions.
A system’s hardware components are synchronized with
the clock. Every time the clock ticks, another hardware
action occurs.
5
Primary or Random Access Memory
How Data is Stored
binary format
a sequence of 0’s and 1's called bits.
ASCII encoding:
‘a’ is represented by 01100001
‘b’ is encoded as 01100010
6
Where Data is Stored
When the CPU executes a program, the program
instructions, along with relevant data, are stored in
primary memory.
7
Where Data Is Stored
You can conceptualize RAM as a collection of storage cells or
boxes, each capable of holding just a single byte of
information.
8
Secondary Memory
Long term
Permanent storage
9
Secondary Memory
The programs that you use every day such as word
processors, spreadsheets, and games are permanently
stored on secondary storage devices.
10
Input/Output Devices
Standard input devices: Output devices:
keyboards monitors
mouses printers
joysticks speakers
stylus pens
cameras
microphones
11
The Software
The programs that run on a computer are collectively known
as software. Word processors, internet browsers, editors,
database management systems, computer games, and
spreadsheets are all part of your computer's software library.
12
Programming Languages
Machine Language Assembly Language High-Level
Language
13
Programming Languages
…
ADDF3 R1, R2, R3
Assembler …
1101101010011010
… …
14
Programming Languages
total = 3 + 4;
15
Popular High-Level Languages
COBOL (COmmon Business Oriented Language)
FORTRAN (FORmula TRANslation)
BASIC (Beginner All-purpose Symbolic Instructional Code)
Pascal (named for Blaise Pascal)
Ada (named for Ada Lovelace)
C (whose developer designed B first)
Visual Basic (Basic-like visual language developed by
Microsoft)
Delphi (Pascal-like visual language developed by Borland)
C++ (an object-oriented language, based on C)
C# (a Java-like language developed by Microsoft)
Java (We use it in the book)
16
Programming and Algorithms
An algorithm is a finite, step-by-step procedure for
accomplishing some task or solving a problem.
17
Compiling Source Code
A program written in a high-level language is called a source
program. A computer cannot understand a source program.
Program called a compiler is used to translate the source
program into a machine language program called an object
program. The object program is often then linked with other
supporting library code before the object can be executed on
the machine.
Library Code
18
The Compiler
The program must be translated into the machine language
of that computer.
20
The Java Virtual Machine
In order to make Java a cross-platform programming
language, Java's creative team designed an abstract
computer implemented in software called the Java Virtual
Machine (JVM). You install software on your computer
that simulates a JVM computer. The machine language of
the JVM is called bytecode. Java programs are first
compiled into bytecode, and then executed.
21
The Java Virtual Machine
The Java interpreter, which is part of the JVM, executes
each bytecode instruction, one by one.
23
PDA and Cell Phone
24
Java’s History
James Gosling and Sun Microsystems
Oak
HotJava
The first Java-enabled Web browser
Bought by Oracle Corporation in January 2010
Java History Website:
http://en.wikipedia.org/wiki/Java_(programming_language)
25
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
http://www.cs.armstrong.edu/liang/intro8e/JavaCharacteristics.pdf
26
Characteristics of Java
Java Is Simple Java is partially modeled on C++, but greatly
simplified and improved. Some people refer to
Java Is Object-Oriented Java as "C++--" because it is like C++ but
Java Is Distributed with more functionality and fewer negative
aspects.
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
27
Characteristics of Java
Java Is Simple Java is inherently object-oriented.
Java Is Object-Oriented Although many object-oriented languages
began strictly as procedural languages,
Java Is Distributed Java was designed from the start to be
Java Is Interpreted object-oriented. Object-oriented
programming (OOP) is a popular
Java Is Robust programming approach that is replacing
Java Is Secure traditional procedural programming
techniques.
Java Is Architecture-Neutral
Java Is Portable One of the central issues in software
development is how to reuse code. Object-
Java's Performance oriented programming provides great
Java Is Multithreaded flexibility, modularity, clarity, and
reusability through encapsulation,
Java Is Dynamic
inheritance, and polymorphism.
28
Characteristics of Java
Java Is Simple Distributed computing involves several
computers working together on a network.
Java Is Object-Oriented Java is designed to make distributed
Java Is Distributed computing easy. Since networking
capability is inherently integrated into
Java Is Interpreted Java, writing network programs is like
Java Is Robust sending and receiving data to and from a
file.
Java Is Secure
Java Is Architecture-Neutral
Java Is Portable
Java's Performance
Java Is Multithreaded
Java Is Dynamic
29
Characteristics of Java
Java Is Simple You need an interpreter to run Java
Java Is Object-Oriented programs. The programs are compiled into
the Java Virtual Machine code called
Java Is Distributed bytecode. The bytecode is machine-
Java Is Interpreted independent and can run on any machine
that has a Java interpreter, which is part of
Java Is Robust the Java Virtual Machine (JVM).
Java Is Secure
Java Is Architecture-Neutral
Java Is Portable
Java's Performance
Java Is Multithreaded
Java Is Dynamic
30
Characteristics of Java
Java Is Simple Java compilers can detect many problems
that would first show up at execution time
Java Is Object-Oriented in other languages.
Java Is Distributed
Java has eliminated certain types of error-
Java Is Interpreted prone programming constructs found in
Java Is Robust other languages.
Java Is Secure
Java has a runtime exception-handling
Java Is Architecture-Neutral feature to provide programming support
Java Is Portable for robustness.
Java's Performance
Java Is Multithreaded
Java Is Dynamic
31
Characteristics of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java Is Robust Java implements several security
mechanisms to protect your system against
Java Is Secure harm caused by stray programs.
Java Is Architecture-Neutral
Java Is Portable
Java's Performance
Java Is Multithreaded
Java Is Dynamic
32
Characteristics of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java Is Robust
Java Is Secure
Write once, run anywhere
Java Is Architecture-Neutral
Java Is Portable With a Java Virtual Machine (JVM),
you can write one program that will
Java's Performance run on any platform.
Java Is Multithreaded
Java Is Dynamic
33
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 neutral,
Java Is Portable Java programs are portable. They can
Java's Performance be run on any platform without being
recompiled.
Java Is Multithreaded
Java Is Dynamic
34
Characteristics of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java Is Robust
Java Is Secure
Because Java is interpreted, the
Java Is Architecture-Neutral bytecode is not directly executed by
Java Is Portable the system, but is run through the
Java's Performance interpreter. However, its speed is
more than adequate for most
Java Is Multithreaded interactive applications, where the
Java Is Dynamic CPU is often idle, waiting for input
or for data from other sources.
35
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
integrated in Java, whereas in other
Java Is Multithreaded languages you have to call procedures
Java Is Dynamic specific to the operating system to enable
multithreading.
36
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 evolving
Java's Performance environment. New code can be loaded on the
fly without recompilation. There is no need for
Java Is Multithreaded developers to create, and for users to install,
major new software versions. New features can
Java Is Dynamic
be incorporated transparently as needed.
37
JDK Versions
JDK 1.02 (1995)
JDK 1.1 (1996)
JDK 1.2 (1998)
JDK 1.3 (2000)
JDK 1.4 (2002)
JDK 1.5 (2004) a. k. a. JDK 5 or Java 5
JDK 1.6 (2006) a. k. a. JDK 6 or Java 6
JDK 1.7 (2010) a. k. a. JDK 7 or Java 7
http://www.oracle.com/technetwork/java
38
JDK Editions
Java Standard Edition (J2SE)
J2SE can be used to develop client-side
standalone applications or applets.
Java Enterprise Edition (J2EE)
J2EE can be used to develop server-side
applications such as Java servlets and Java
ServerPages.
Java Micro Edition (J2ME).
J2ME can be used to develop applications for
mobile devices such as cell phones.
39
A Simple Java Program
Listing 1.1
40
Creating and Editing Using NotePad
To use NotePad, type
notepad Welcome.java
from the command prompt.
41
Creating and Editing Using WordPad
To use WordPad, type
write Welcome.java
from the command prompt.
42
Creating, Compiling, and Running Programs
Create/Modify Source Code
Result
44
Acknowledgement
The lecture notes for this course include slides from:
Daniel Liang – Introduction to Java Programming, 2011
Antonio Martinez – Java Programming: From the Ground
Up, 2010
45