Title: Chapter 1 Computers, Programs, and Java
1Chapter 1Computers, Programs, and Java
2Computer Science
- Why should anyone who doesnt want to be a
computer scientist learn about computer science? - Manipulation is done with a computer
- Media
- Business data
- Scientific data
- If you can only manipulate data with software
that someone else created, you are limiting your
ability to communicate.
3Hardware
4Software
- Software are the instructions that tell the
hardware what to do. - A set of software instructions that tells the
computer what to do is called a computer program.
- A program is like a recipe
- There are different types of programs that make
up a computer.
5Operating Systems
- An operating system, or OS, is the glue that
binds the hardware to the application software. - An operating system is a collection of computer
programs dedicated to managing the resources of
the system. - What are some tasks the operating system manages?
6Machine Language
- All of the hardware components in a computer
system, including the CPU, operate on a language
made up of binary numbers - Binary numbers are made up of only 2 digits - 0
and 1. - A CPU does not understand any other language.
- Every instruction is eventually translated into
machine language.
7Assembly Language
- Assembly language is one step up from machine
language. - Assembly language employs alphabetic
abbreviations called mnemonics. - For instance, the mnemonic for addition is ADD,
the mnemonic for move is MOV, and so forth.
8High-level language
- A high-level language consists of instructions,
or statements, that are closer to English and
common mathematical notation. - When programming in a high-level language, you do
not have to concern yourself with the specific
machine language of the CPU.
9 Structured Languages
- A structured language allows complex problems to
be solved using a modular, top/down, approach. - C is a structured programming language
-
10Object-Oriented programming (OOP)
- An object-oriented language allows complex
problems to be solved using more natural objects
that model the way we humans think about things
in terms of attributes and behavior. - C and Java are object-oriented programming
languages
11A Quick Language Comparison Feature C C Jav
a
Object-Oriented No Yes Yes Easy
GUIs No No Yes Portable No No Yes Internet
Programming No No Yes Easy Multitasking
No No Yes Easy Database Connectivity No No Yes
Built-In Security No No Yes Simplicity No No
Yes High Speed Execution Yes Yes No Low Level
Coding Yes Yes No Widely Accepted Yes Yes Yes
12 Structured vs. Object-Oriented Languages
- The C language is a structured language that
allows complex problems to be solved using a
modular, top/down, approach. - The Java language is an object-oriented language
that allows complex problems to be solved in
terms of their attributes and behaviors, much
like we humans view the world.
13Java
- In Java, you can write many different kinds of
programs, including applications, applets,
servlets, EJBs, and JavaBeans. - Java applications are designed to be run on a
computer just like any other computer program
written in any other language. - Java applets are programs designed only to be run
over the Internet using a Web browser.
14Why Java?
- Object-oriented
- Portable compile once, deploy many
- Growing in popularity
- Cheap - free
- For our class
- Simpler than C
- A real programming language, not just scripting
- Once you know Java you can pick up any other
language easily
15Creating a Program
- Even when programming in a high level language,
the system must still translate your instructions
into machine language. - High level programming languages use either a
compiler or an interpreter to translate the
instructions into machine code.
16Compiler
- A compiler is a program that takes a high-level
language program and translates the entire
program into machine code all at one time. - All instructions are compiled before any are
executed by the CPU.
17Interpreter
- An interpreter translates and executes one
high-level instruction at a time. - Once a given instruction has been executed, then
it translates and executes the next, and so on.
18Java Programs
- Java is unique in that it uses a compiler and an
interpreter - Type your program into an editor
- Save it in a file with a .java extension source
code - Invoke the Java compiler to translate the source
code into Java bytecode (.class file) - Bytecode is similar to machine language but not
associated to any specific CPU - Any computer with a Java Virtual Machine (JVM)
has a Java interpreter - Java interpreter translates the generic bytecode
into machine language instructions specific to
the CPU
19Language Translation
- A source program is the one that you write in the
Java language and that always has a file
extension of .java. - An object program is the binary byte-code program
generated by the Java compiler, which always has
a file extension of .class.
20Language Translation
- The .class file generated by the Java compiler
contains bytecode - low-level code similar to machine language
- generic and not specific to any particular CPU.
- The Java Virtual Machine (JVM) translates the
generic bytecode into machine language - A computer must have a JVM to run the Java
program.
21Java Translation
22Java Programs
- Why does Java use both a compiler and
interpreter? - What are the pros and cons of this?