programmingcsweb.cs.wfu.edu/~pauca/csc111/1-programmingbasics.pdfcomputer programming • computer...

21
Overview of Computer Science CSC 111 - Fall 2017 Programming

Upload: ngothien

Post on 28-Apr-2018

222 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Programmingcsweb.cs.wfu.edu/~pauca/csc111/1-ProgrammingBasics.pdfComputer Programming • Computer program - source code • A sequence of instructions written in a particular computer

Overview of Computer ScienceCSC 111 - Fall 2017

Programming

Page 2: Programmingcsweb.cs.wfu.edu/~pauca/csc111/1-ProgrammingBasics.pdfComputer Programming • Computer program - source code • A sequence of instructions written in a particular computer

Application Development• All apps developed in some computer language

• Process

Compiler

Write programin high level language

compile to generate executable Run the executable

Page 3: Programmingcsweb.cs.wfu.edu/~pauca/csc111/1-ProgrammingBasics.pdfComputer Programming • Computer program - source code • A sequence of instructions written in a particular computer

High-Level Language• Human-oriented language

• Natural language constructs

• Mathematical notation

• Syntax and semantics rules

• Enables human to write instructions for a computer to execute

• No ambiguity in these instructions

• Examples:

• Java, C++, C#, Objective-C, Javascript, etc.

Page 4: Programmingcsweb.cs.wfu.edu/~pauca/csc111/1-ProgrammingBasics.pdfComputer Programming • Computer program - source code • A sequence of instructions written in a particular computer

Compiler• Translates high-level code into machine-specific

code

• Java compiler

• C++ compiler

• C# compiler,

• Objective-C compiler

• Programmer uses compiler to translate source code to executable

Page 5: Programmingcsweb.cs.wfu.edu/~pauca/csc111/1-ProgrammingBasics.pdfComputer Programming • Computer program - source code • A sequence of instructions written in a particular computer

Executable• Written in machine language

• Specific to each CPU, e.g. Intel, AMD, etc

• In binary, sequence of 0s and 1s, e.g. 0011010111

• Only specific CPU can interpret

• Assembly language

• Mnemonic representation of machine code

Page 6: Programmingcsweb.cs.wfu.edu/~pauca/csc111/1-ProgrammingBasics.pdfComputer Programming • Computer program - source code • A sequence of instructions written in a particular computer

What to use to write the source code?

• Integrated Development Environments (IDEs)

• Editor - to write the source code

• Compiler - to produce the executable

• Console & Debugger - to run and test the code

• Sample IDEs

• Xcode - for Apple apps

• Eclipse, IntelliJ IDEA - for Java & Android apps

• Atom - for HTML, CSS, Javascript

• etc.

Page 7: Programmingcsweb.cs.wfu.edu/~pauca/csc111/1-ProgrammingBasics.pdfComputer Programming • Computer program - source code • A sequence of instructions written in a particular computer

IntelliJ IDEA - Java

Page 8: Programmingcsweb.cs.wfu.edu/~pauca/csc111/1-ProgrammingBasics.pdfComputer Programming • Computer program - source code • A sequence of instructions written in a particular computer

Xcode - Objective C

Page 9: Programmingcsweb.cs.wfu.edu/~pauca/csc111/1-ProgrammingBasics.pdfComputer Programming • Computer program - source code • A sequence of instructions written in a particular computer

Sample iPad App• Verbal Victor

• Developed at Wake Forest in 2010 for people with speech and communication disabilities

• Sold over 15000 copies world wide at $13 each

• Conventional devices: $300 - $7000

• Severe physical disability: >$25,000

• Cost of developing an App?

• Anywhere from $10K to $100K or more...

Page 10: Programmingcsweb.cs.wfu.edu/~pauca/csc111/1-ProgrammingBasics.pdfComputer Programming • Computer program - source code • A sequence of instructions written in a particular computer

Verbal Victor

Page 11: Programmingcsweb.cs.wfu.edu/~pauca/csc111/1-ProgrammingBasics.pdfComputer Programming • Computer program - source code • A sequence of instructions written in a particular computer

Computer Programming• Computer program - source code

• A sequence of instructions written in a particular computer language

• Computer reads in and executes program one instruction at the time

• Programming

• Highly creative process

• Develop a solution for a particular problem

• Solution specified as a well-defined, unambiguous sequence of instructions is called an algorithm

Page 12: Programmingcsweb.cs.wfu.edu/~pauca/csc111/1-ProgrammingBasics.pdfComputer Programming • Computer program - source code • A sequence of instructions written in a particular computer

Algorithms• Programs that solve specific problems

• Can you write clear instructions for finding the winning number among a deck of lottery tickets?

• If I think of a number between 0 and 100, can you write instructions for guessing my number in less than 100 tries? less than 50? less than 7?

• If pi = 4 - 4/3 + 4/5 - 4/7 + ... can you find a way to approximate pi?

• If I give you 100 numbers, can you write instructions for sorting them from largest to smallest?

Page 13: Programmingcsweb.cs.wfu.edu/~pauca/csc111/1-ProgrammingBasics.pdfComputer Programming • Computer program - source code • A sequence of instructions written in a particular computer

Java Programming• Java language

• Defines syntax and semantics

• Java compiler

• Translates Java source code into Java byte code

• Execution

• Java bytecode executed by the Java Virtual Machine (JVM) in your computer

Page 14: Programmingcsweb.cs.wfu.edu/~pauca/csc111/1-ProgrammingBasics.pdfComputer Programming • Computer program - source code • A sequence of instructions written in a particular computer

First Java Program• Hello World

/* * 8/30/17

* * The first obligatory Java program * */ public class Hello { // Here is the main method public static void main(String[] args) { System.out.println("Hello World!"); }}

Page 15: Programmingcsweb.cs.wfu.edu/~pauca/csc111/1-ProgrammingBasics.pdfComputer Programming • Computer program - source code • A sequence of instructions written in a particular computer

First Java Program• Comments: Ignored by the computer

/* * 8/30/17

* * The first obligatory Java program * */ public class Hello { // Here is the main method public static void main(String[] args) { System.out.println("Hello World!"); }}

Page 16: Programmingcsweb.cs.wfu.edu/~pauca/csc111/1-ProgrammingBasics.pdfComputer Programming • Computer program - source code • A sequence of instructions written in a particular computer

First Java Program• Class definition

/* * 8/30/17

* * The first obligatory Java program * * @author Paul Pauca */

public class Hello { // Here is the main method public static void main(String[] args) { System.out.println("Hello World!"); }}

Page 17: Programmingcsweb.cs.wfu.edu/~pauca/csc111/1-ProgrammingBasics.pdfComputer Programming • Computer program - source code • A sequence of instructions written in a particular computer

First Java Program• Method definition

/* * 8/30/17

* * The first obligatory Java program * */ public class Hello { // Here is the main method public static void main(String[] args) { System.out.println("Hello World!"); }}

Page 18: Programmingcsweb.cs.wfu.edu/~pauca/csc111/1-ProgrammingBasics.pdfComputer Programming • Computer program - source code • A sequence of instructions written in a particular computer

Some Rules• Each part of code follows specific syntax rules

• Comment block: /* text */

• Class definition: public class IDENTIFIER { }

• Method definition: public static void IDENTIFIER( ) { }

• Identifiers

• Words made up by you

• Cannot have spaces, arithmetic operators, or other characters such as #$^&!

• Instructions

• Must be terminated by a semicolon

Page 19: Programmingcsweb.cs.wfu.edu/~pauca/csc111/1-ProgrammingBasics.pdfComputer Programming • Computer program - source code • A sequence of instructions written in a particular computer

Instructions for Printing to the Screen

• println() - print and add a new line•System.out.println(“Hello”);

•System.out.println(“World”);

• print() - print only (no new line)•System.out.print(“Hello”);

•System.out.print(“World”);

HelloWorld

HelloWorld

Page 20: Programmingcsweb.cs.wfu.edu/~pauca/csc111/1-ProgrammingBasics.pdfComputer Programming • Computer program - source code • A sequence of instructions written in a particular computer

Want to get fancy?• Use a Dialog window/* * 8/23/06

* * Uses a message dialog window * */

import javax.swing.JOptionPane;

public class FancyHello { public static void main(String[] args) { JOptionPane.showMessageDialog(null, "Hello World!", "Display Message", JOptionPane.INFORMATION_MESSAGE); System.out.println("Goodbye cruel planet..."); }}

Page 21: Programmingcsweb.cs.wfu.edu/~pauca/csc111/1-ProgrammingBasics.pdfComputer Programming • Computer program - source code • A sequence of instructions written in a particular computer

Want to get fancy?• Use a Dialog window/* * 8/30/17

* * Uses a message dialog window * */

import javax.swing.JOptionPane;

public class FancyHello { public static void main(String[] args) { JOptionPane.showMessageDialog(null, "Hello World!", "Display Message", JOptionPane.INFORMATION_MESSAGE); System.out.println("Goodbye cruel planet..."); }}