programmingcsweb.cs.wfu.edu/~pauca/csc111/1-programmingbasics.pdfcomputer programming • computer...
Post on 28-Apr-2018
222 Views
Preview:
TRANSCRIPT
Overview of Computer ScienceCSC 111 - Fall 2017
Programming
Application Development• All apps developed in some computer language
• Process
Compiler
Write programin high level language
compile to generate executable Run the executable
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.
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
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
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.
IntelliJ IDEA - Java
Xcode - Objective C
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...
Verbal Victor
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
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?
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
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!"); }}
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!"); }}
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!"); }}
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!"); }}
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
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
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..."); }}
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..."); }}
top related