Title: Introduction to Programming
1Introduction to Programming
- Dr. Tim Margush
- University of Akron
2Goals
- Learn about programming a computer
- Understand basic computer architecture
- See the relationship between programming
languages and architecture - Become familiar with programming tools
- Compile and execute a Java program
3What is Programming
- Creating a collection of instructions that will
be followed by a computing device - What instructions does it understand?
- How are the instructions recorded?
- What are the rules for ordering the instructions?
- How does the computer know what instructions it
is to execute?
4Basic Computer Architecture
5VonNeumann Architecture
- Program instructions and data are numerically
encoded and stored in RAM - The CPU fetches and executes instructions
- Default execution order is sequence
- Instructions can interrupt the sequential
processing to begin a fetch sequence from an
arbitrary location
6Fetch-Execute Cycle
- IP Instruction pointer
- Address of next instruction to be fetched
- Fetch instruction at IP
- Increment IP (anticipate sequence)
- Decode and execute instruction
See it in action compliments of Richard
Jones http//www.ib-computing.com/oldIB/FE_cycle.h
tm
7Programming Languages
- Machine language
- Numeric 04 A2 C9 FF 29
- Assembly language
- Mnemonic, symbolic LOAD R13,AGE
- Assembled to machine language
- High-level language
- Expressive and symbolic, almost natural(?)
discount price .25 - Compiled to machine language
8Steps to Run a Program
- Edit, Compile, Load, Execute
- The sequence below illustrates the process in the
context of the Java programming language
notepad Sample.java
java Sample
javac Sample.java
9Java
- Simple, familiar (C-like), object-oriented,
robust, secure, architecture-neutral,
interpreted, dynamic, multi-threaded,
high-performance - Programs are compiled to a standard intermediate
format (class file) - Class files are interpreted by a Java Virtual
Machine (JVM) specific to each host environment
10Programming Tools
- Editor
- Any text editor will suffice (notepad)
- A Java-aware editor will provide formatting and
shortcuts, and suggestions appropriate to the
language (jEdit) - An integrated development environment (IDE) will
automatically connect the editor with project
management and compilation, execution, and
debugging tools (jGRASP or Eclipse)
11Programming Tools (2)
- Compiler
- SUN provides free and commercial compilers
- Sun Java J2SE (Java version 2, standard edition)
- Other vendors bundle compilers with their IDE
- Borland Jbuilder
- Symantec VisualCafe
- IBM WebSphere Studio
- Metrowerks CodeWarrior
12Programming Tools (3)
- Java Virtual Machine
- SUN (included with SDK)
- Microsoft (often included with IE installations)
- Others? (students sometimes write their own)
- Sometimes called a Java Runtime Environment (JRE)
- Specific to each platform (hardware/OS)
- Required to run Java programs
13jGRASP
- Free IDE that uses Suns Java SDK
- Download from http//www.jgrasp.org
14Eclipse
- Open Source IDE that uses Suns Java SDK
- Download from http//www.eclipse.org
15Java Programs
- Source code
- Stored in a file with .java extension
- Usually placed in a folder that holds all of the
files related to one program - Class file
- The compiled version of a source file
- Usually located in the same folder as the source
16A Simple Java Program
Class name
Method name
- public class MyName
- public static void main(String args)
- //display my name
- System.out.println("My name is Harold.")
-
Method parameters
Program comment
String argument
Method call
System output object
17Compiling the Program (jGRASP)
Compile button
Source code
Compile messages
18Running the Program (jGRASP)
Run button
Class file from compile
Program output
19Compiling the Program (Eclipse)
Compile button
Source code
Compile messages
20Running the Program (Eclipse)
Run button
Program output
21Summary
- Programs are instructions that will be followed
by a central processing unit (CPU) in the context
of a computing system - Data and program instructions are in RAM during
program execution - Programs are written in machine, assembly, or a
high-level language - High-level languages (such as Java) are compiled
before they can be run
22Summary (2)
- The steps to running a program are edit,
compile, load (link and run) - Java programs are executed in a virtual machine
(JVM) that is the standardized across all
computing platforms - Java programs are collections of classes
- Classes contain methods (actions)
- When a class file is run as an application, the
JVM follows the instructions in the method named
main