Download L6_Intro to programming

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Programming language wikipedia , lookup

C Sharp syntax wikipedia , lookup

Comment (computer programming) wikipedia , lookup

Falcon (programming language) wikipedia , lookup

Structured programming wikipedia , lookup

Scala (programming language) wikipedia , lookup

Name mangling wikipedia , lookup

Library (computing) wikipedia , lookup

Object-oriented programming wikipedia , lookup

Software bug wikipedia , lookup

Program optimization wikipedia , lookup

Go (programming language) wikipedia , lookup

History of compiler construction wikipedia , lookup

Compiler wikipedia , lookup

Assembly language wikipedia , lookup

One-pass compiler wikipedia , lookup

Java (programming language) wikipedia , lookup

Java performance wikipedia , lookup

Interpreter (computing) wikipedia , lookup

C Sharp (programming language) wikipedia , lookup

Transcript
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
High-Level Language (HLL)
Assembly Lanuage
Machine Language
Hardware
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 Source
to 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
Source
Code
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
Data for Java Program
Java Program
Java Compiler
Byte-Code
Program
Java
Virtual
Machine
Byte-Code Interpreter
Machine-Language
Instructions
Computer Execution
of Machine-Language Instructions
Output of Java Program
Basic Program Development
Edit and
save program
errors
errors
Compile program
Execute program and
evaluate results
1
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 Computer
Download and Install
JCreator LE
JSDK
Java 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 HelloWorld
public class HelloWorld
{
public static void main(String[] args)
{
}
}
Your first Java Program
public 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 …