Date post: | 28-Dec-2015 |
Category: |
Documents |
Upload: | adrian-pitts |
View: | 214 times |
Download: | 0 times |
An intro to programming
The purpose of writing a program is to solve a problem or take advantage of an opportunity
Consists of multiple steps:Understanding problem or opportunity.Breaking the problem into manageable pieces (decomposing).Designing a solution.Considering alternatives to the solution and refining the solution.Implementing the solution. Testing the solution and fixing the problems.
What is a program?
• A program is computer coding that:
• Takes input• Performs some
calculation on the input
• Displays output
What is a program?
• A program is…– A collection of statements– Written in a programming language– A specification of the steps taken to
solve a problem
• Programs have grammar rules– Specify how the statements are formed– How the statements are combined
Writing programs
• You need:– Knowledge of a coding language– Problem solving skills– Familiarity with analysis and
design process– Software development tools
Programming Language Hierarchy
H ard w are
M ach in e L an g u ag e
A ssem b ly L an u ag e
H ig h -L eve l L an g u ag e (H L L )
The highs and lows of programming languages ...
• High-Level Language (HLL)– closest to natural
language– words, numbers, and
math symbols– not directly understood
by hardware– “portable” source code
(hardware independent)– Java, C, C++, COBOL,
FORTRAN, BASIC, Lisp, Ada, etc.
• Machine Language(lowest level)– least natural language for
humans, most natural language for hardware
– just 0s and 1s– directly understood by
hardware– not portable (hardware
dependent)
In order for a program to run on a computer, it must be in that computer’s machine language. Each type of CPU has it’s own language.
Getting from Sourceto Machine Code
• “Compiling a program”translating from a high-level language source code to machine
(object, or executable) code.
• “Compiler”a program that translates HLL source code to machine (object,
or executable) code.
• “Assembly”translating from assemble language source code to machine
(object, or executable) code.
• “Assembler”a program that translates assembly source code to machine
(object, or executable) code.
• Compilers need to know the specific target hardware
Compilers vs. Assemblers vs. Interpreters
• Compilers and Assemblers– translation is a separate user step– translation is “off-line,” i.e. not at run time
• Interpreters - another way to translate source to object code– interpretation (from source to object code) is not a
separate user step– translation is “on-line,” i.e. at run time
SourceCode
Java Program Translation• Both Compilation and
Interpretation• Intermediate Code:
“Byte Code”– portable low-level
code– similar to assembly
code,but hardware independent
– invisible to Java programmer
• Interpreter translates from generic byte code to hardware-specific machine code
Java Program Data for Java Program
Java Compiler
Byte-CodeProgram
Byte-Code Interpreter
Machine-LanguageInstructions
Computer Executionof Machine-Language Instructions
Output of Java Program
JavaVirtualMachine
1
Basic Program Development
errors
errors
Edit andsave program
Compile program
Execute program andevaluate results
The Java Software Development Kit (SDK)
• Can be downloaded free from Sun website.
• a development environment for building applications, applets, and components using the Java programming language
• These tools are designed to be used from the command line. Except for the appletviewer, these tools do not provide
a Graphical User Interface
Java
• Java was released in 1995 by Sun Microsystems.
• It is written in the language C++.
• Java is platform-independent, object-oriented, and easy to use on the Internet.
STOP
A closer look at Java SDK and JCreator IDE.
Java™ SDK, Standard Edition • a development environment for
building applications, applets, and components using the Java programming language
• includes tools useful for developing and testing programs written in the Java programming language and running on the Java platform
• Except for the appletviewer, these tools do not provide a graphical user interface
API Specification
• Application Programming Interface (API) documentation online and downloadable
• Contains detailed documentation on all classes and packages in the java standard library
• java API Specification
The Java Virtual Machine (JVM) – key to portability
• is an abstract (virtual) computer that runs compiled Java programs – virtual" because it is generally implemented in
software on top of a "real" hardware platform and operating system
•Makes java code portable
•code compiled on any platform will run on any other platform having Java Virtual Machine
For Home ComputerDownload and Install
JCreator LEJSDKJava API documentation
All from jcreator.com/download.htm
Organizing Work• The H drive is your personal workspace in the
classroom.• Create folders to organize work by topic, week,
semester …
Your first Java Program
• Start Jcreator• Follow instructions to create a Java
program named HelloWorldpublic class HelloWorld{
public static void main(String[] args){}
}
Your first Java Programpublic class HelloWorld{
public static void main(String[] args)
{System.out.println(“Hello
World”);}
}
Creation of a .class file - bytecode
• Go back to your project directory and look at the new files:– HelloWorld.java – source code– HelloWorld.class - bytecode
On Your Own
• Open HelloWorld source code and add more output lines.
• Open java program named Basics – Compile, execute, modify, compile …