+ All Categories
Home > Documents > An intro to programming. The purpose of writing a program is to solve a problem or take advantage of...

An intro to programming. The purpose of writing a program is to solve a problem or take advantage of...

Date post: 28-Dec-2015
Category:
Upload: adrian-pitts
View: 214 times
Download: 0 times
Share this document with a friend
25
An intro to programming
Transcript
Page 1: 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.

An intro to programming

Page 2: 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.

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.

Page 3: 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.

What is a program?

• A program is computer coding that:

• Takes input• Performs some

calculation on the input

• Displays output

Page 4: 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.

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

Page 5: 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.

Writing programs

• You need:– Knowledge of a coding language– Problem solving skills– Familiarity with analysis and

design process– Software development tools

Page 6: 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.

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 )

Page 7: 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.

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.

Page 8: 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.

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

Page 9: 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.

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

Page 10: 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.

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

Page 11: 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.
Page 12: 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.

1

Basic Program Development

errors

errors

Edit andsave program

Compile program

Execute program andevaluate results

Page 13: 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.

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

Page 14: 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.

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.

Page 15: 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.

STOP

Page 16: 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.

A closer look at Java SDK and JCreator IDE.

Page 17: 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.

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

Page 18: 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.

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

Page 19: 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.

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

Page 20: 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.

For Home ComputerDownload and Install

JCreator LEJSDKJava API documentation

All from jcreator.com/download.htm

Page 21: 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.

Organizing Work• The H drive is your personal workspace in the

classroom.• Create folders to organize work by topic, week,

semester …

Page 22: 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.

Your first Java Program

• Start Jcreator• Follow instructions to create a Java

program named HelloWorldpublic class HelloWorld{

public static void main(String[] args){}

}

Page 23: 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.

Your first Java Programpublic class HelloWorld{

public static void main(String[] args)

{System.out.println(“Hello

World”);}

}

Page 24: 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.

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

Page 25: 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.

On Your Own

• Open HelloWorld source code and add more output lines.

• Open java program named Basics – Compile, execute, modify, compile …


Recommended