Computer Components. Software{ User Programs. Operating System. Hardware

Similar documents
Computer Components. Software{ User Programs. Operating System. Hardware

Basic Concepts. Computer Science. Programming history Algorithms Pseudo code. Computer - Science Andrew Case 2

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

3. Java - Language Constructs I

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

COMP 202 Java in one week

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Program Fundamentals

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

CSC 1214: Object-Oriented Programming

Java Programming. Atul Prakash

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

2 rd class Department of Programming. OOP with Java Programming

DM550 Introduction to Programming part 2. Jan Baumbach.

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

JAVA Ch. 4. Variables and Constants Lawrenceville Press

Chapter 3: Operators, Expressions and Type Conversion

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

Objectives. Problem Solving. Introduction. An overview of object-oriented concepts. Programming and programming languages An introduction to Java

3. Java - Language Constructs I

Java for Python Programmers. Comparison of Python and Java Constructs Reading: L&C, App B

DM503 Programming B. Peter Schneider-Kamp.

Lecture 2: Variables and Operators. AITI Nigeria Summer 2012 University of Lagos.

Introduction to Programming Using Java (98-388)

Lecture Set 2: Starting Java

Lecture Set 2: Starting Java

Accelerating Information Technology Innovation

Chapter 2. Elementary Programming

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

For the course, we will be using JCreator as the IDE (Integrated Development Environment).

Chapter. Focus of the Course. Object-Oriented Software Development. program design, implementation, and testing

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

Programming Lecture 3

An overview of Java, Data types and variables

Java Bytecode (binary file)

COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods

CompSci 125 Lecture 02

BASIC ELEMENTS OF A COMPUTER PROGRAM

Intro to Computer Science & Programming. A Cranes Club Initiative

6.096 Introduction to C++ January (IAP) 2009

CSCI 2101 Java Style Guide

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan

DEPARTMENT OF MATHS, MJ COLLEGE

Basics of Java Programming

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

Course Outline. Introduction to java

Introduction to C# Applications

What did we talk about last time? Examples switch statements

PROGRAMMING FUNDAMENTALS

CS 231 Data Structures and Algorithms, Fall 2016

Java language. Part 1. Java fundamentals. Yevhen Berkunskyi, NUoS

CS313D: ADVANCED PROGRAMMING LANGUAGE

Tester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time

The Java Language Rules And Tools 3

Elementary Programming

Building Java Programs. Introduction to Programming and Simple Java Programs

Index COPYRIGHTED MATERIAL

Variables. Data Types.

Java Identifiers. Java Language Essentials. Java Keywords. Java Applications have Class. Slide Set 2: Java Essentials. Copyright 2012 R.M.

Operators and Expressions

-Alfred North Whitehead. Copyright Pearson Education, 2010 Based on slides by Marty Stepp and Stuart Reges from

The MaSH Programming Language At the Statements Level

Lecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value

Fundamentals of Programming

COMP 202 Java in one week

Fundamental of Programming (C)

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

COMP-202: Foundations of Programming. Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015

Introduction to Java Applications

More Programming Constructs -- Introduction

Java Fall 2018 Margaret Reid-Miller

Section 2.2 Your First Program in Java: Printing a Line of Text

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

The Java Language The Java Language Reference (2 nd ed.) is the defining document for the Java language. Most beginning programming students expect

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Language Fundamentals Summary

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

SKILL AREA 304: Review Programming Language Concept. Computer Programming (YPG)

Syntax and Variables

The keyword list thus far: The Random class. Generating "Random" Numbers. Topic 16

JAVA Programming Fundamentals

Variables and Operators 2/20/01 Lecture #

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

Java Language Basics: Introduction To Java, Basic Features, Java Virtual Machine Concepts, Primitive Data Type And Variables, Java Operators,

Chapter 1. Introduction to Computers and Programming. M hiwa ahmad aziz

Topic 16. battle -they are strictly limited in number, they require fresh horses, and must only be made at decisive moments." -Alfred North Whitehead

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

Computational Expression

The Java language has a wide variety of modifiers, including the following:

Operators. Java operators are classified into three categories:

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

Algorithms and Programming I. Lecture#12 Spring 2015

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

Transcription:

Computer Components Software{ User Programs Operating System Hardware

What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point A to point B. A program may say... if starting at location A, go north 3 blocks, then go East 2 blocks.

What are Programs? Input Processing Output

High/Low Level Programming Languages Low level programming languages are languages which have instruction sets that are limited and specific to the computer hardware being run on. Programmers need to know how the hardware works to use it. High level programming languages provide a layer of abstraction that allows for the programmer to only have to learn a hardware independent language to write software.

Low Level Languages Pros Can be more optimized Usually smaller executables Cons Platform dependent Slower development Harder to understand Easier to introduce bugs When to use it: Need extra optimization, Need small executables (embedded systems) Example: Assembly (different for each OS/Architecture)

High Level Languages Pros Faster development (libraries/etc.) Easier to understand (abstraction) Can be platform independent Cons Usually larger executables Abstraction layer usually adds overhead for processing resulting in slower executables When to use it: Need portability, need faster turn-around time for development, when programmer time is more valuable than processing time Examples: Java, C, C++, C#, Javascript, PHP, Perl, Python, Lisp, Scheme, R, etc.

Assembly Example (Low Level) mov ax,cs mov ds,ax mov ah,9 mov dx, offset Hello int 21h xor ax,ax int 21h Hello: db "Hello World!",13,10,"$"

Python Example (High Level) print( hello World! )

Java Example (High Level) class HelloWorld { static public void main( String args[] ) { System.out.println( "Hello World!" ); } }

Anatomy of a Program Traditional Language Source Code Interpreted Language Source Code Compiler Interpreter Compiled Code Byte Code Linker Virtual Machine Executable Execution

Bytecode vs. Executable Bytecode Cross platform Allows for replacement of small components without recompiling entire programs Generally slower performance Executable Runs on one platform Programs generally compile down to larger executables Generally faster performance

Algorithms

Algorithms A series of repeated instructions that solve a problem

Algorithms A series of repeated instructions that solve a problem For example: To read a file and print it's contents a program could: open a file it isn't yet, check if it has reached the end of a file, if not read a line and print it's contents, repeat To sort a list of numbers it could: compare the first two number, swap the number if necessary, then proceed to second and third numbers and repeat until all numbers are sorted

Bugs

Bugs All programmers run into bugs... lots and lots of bugs. Bugs are errors in a program. Bugs come in three different varieties:

Bugs All programmers run into bugs... lots and lots of bugs. Bugs are errors in a program. Bugs come in three different varieties: Compile time errors: (syntax/type/etc.) The rules of the language have been violated. Examples: improper spacing, missing colon, etc.

Bugs All programmers run into bugs... lots and lots of bugs. Bugs are errors in a program. Bugs come in three different varieties: Compile time errors: (syntax/type/etc.) The rules of the language have been violated. Examples: improper spacing, missing colon, etc. Runtime errors (crashes): Errors during execution Example: input file may not be readable

Bugs All programmers run into bugs... lots and lots of bugs. Bugs are errors in a program. Bugs come in three different varieties: Compile time errors: (syntax/type/etc.) The rules of the language have been violated. Examples: improper spacing, missing colon, etc. Runtime errors (crashes): Errors during execution Example: input file may not be readable Logic errors: A problem that is caused by a flawed algorithm or set of instructions used to solve a problem. Example: If you use a less than sign where you should have used a greater than sign

Pseudo-Code The expression of programming logic in a language independent nature. Good for design phase of coding Examples: if student_grade >= 60 print passed else print failed

Writing a Program Design Write Code Fix Compile Time Errors Run Program

Basic Programming Concepts Keywords Statements Operators Data Types Variables Assignment Constants

Keywords Keywords are reserved words that have special meaning in a particular programming language. These words can not be used for any other purpose (e.g. variable names). Java keywords are: abstract, continue, for, new, switch, assert, default, goto, package, synchronized, boolean, do, if, private, this, break, double, implements, protected, throw, byte, else, import, public, throws, case, enum, instanceof, return, transient, catch, extends, int, short, try, char, final, interface, static, void, class, finally, long, strictfp**, volatile, const*, float, native, super, while

Statements Programs are made up of a series of statements Similar to a sentence in a natural language, each statement presents a command that the interpreter understands The interpreter parses or reads the statement determines what is being requested and executes that statement

Basic Data Types Integers (Real numbers): short (16 bits), int (32 bits), long (64 bits) Single text character: char 32bit decimal numbers: float 64bit (more precise) decimal numbers: double True/False (similar to a bit): boolean 8 bits: byte Strings (are actually objects): store a series of characters

Operators Different data types have different operators Operators can be part of a statement Operators act on the operands around them Unary operators take 1 argument e.g. setting a number to a negative value: -3 Binary operators take 2 arguments e.g. arithmetic operators: 1-3 Ternary operators takes 3 arguments // if x < y set largest to y, else set it to x largest = x < y? y : x;

Operators on Numbers (in order of precedence with respect to divisions) + Additive operator (also used for String concatenation) - Subtraction operator * Multiplication operator / Division operator % Remainder operator ( ) Dictate order of operations

Comments Provides: Documentation Clarifying what specific code is doing Make code easy for the author or other programmers to understand Line comments start with the // characters // this is a comment Block comments start with /* and end with */ /* this is a block comment comment, it spans multiple lines */

Variables Names Variables are labels used by programmers for storage of data Variable name in java: Can be long Are case sensitive (Alpha!= alpha) Can contain letters, numbers, and underscores ( _ ) Must not start with a number Can not be a keyword

Variables Names (Examples) thisvariablenameisvalid = "valid naming conventions" this_variable_name_is_valid = "also valid" names = "names are valid" Names = "not the same as names" numbers_between_0_and_9 = "another valid" 0_9_can_not_start_a_name = "invalid" if = "keywords are not allowed" special_chars_!_allowed = "invalid"

Constants A constant is a stored value that doesn't change Used for things that will remain constant throughout the program. (e.g. pi, conversions between metric and standard units, etc) When representing data that doesn't change it's often a good idea to use constants Generally constants are in all CAPITAL letters

Variable Assignment Statements public static final float PI = 3.14159265; public float radius = 5; public float area_circle = PI * radius * radius;

Data Output System.out.println() System - http://docs.oracle.com/javase/7/docs/api/java/l ang/system.html out.println() http://docs.oracle.com/javase/7/docs/api/java/io/ PrintStream.html

Data Output For numbers with strings: public static String year = 2013 System.out.print( The year is: + year)

Data Output For numbers with strings: public static String year = 2013 ; // Not what we want: System.out.println( Next year is: + (1 + year); // Convert string to int then add: System.out.println( Next year is: + (1 + Integer.toString(year)));

Type Conversion In certain circumstances you data types may need to be converted to other data types (e.g. converting a string into an integer or vice versa). String int foo = 31337 ; int bar = Integer.parseInt(foo); int String Integer.toString(bar) int!= Integer int is a primitive with no functions Integer is an object that has functions to manipulate it

Data Input For strings: Scanner reader = new Scanner(System.in); System.out.println("Enter input: ); String input=reader.nextline(); For numbers: Scanner reader = new Scanner(System.in); System.out.println("Enter an intger"); int input=reader.nextint();

Natural Languages Syntax: punctuation and spacing Grammar: forms well defined sentences (e.g. subject verb-object) Parts of speech: nouns, verbs, adjectives Semantics: The meaning of the words Example: The quick brow fox jumped over the lazy dog.

Programming Languages Syntax: punctuation (e.g. parentheses, colons, spacing) Grammar: forms well defined statements (e.g. if statement is true then perform subsequent statement) Parts of speech: keywords, variables, operators, etc. Semantics: The meaning of the words Example: if a == b: print( a is equal to b )

Coding Style Just as in natural languages the style of coding matters. Style determines the level of readability, maintainability, and efficiency. Several things make up a coding style: Formatting, Naming schemes, Comments, and more!