Chapter 1 - Introduction. Announcements Info Sheet Web Site: www.cs.wisc.edu/~dakoop/cs302 www.cs.wisc.edu/~dakoop/cs302 Lab Hours NotecardsPictures.

Slides:



Advertisements
Similar presentations
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Advertisements

Lecture 1: Overview of Computers & Programming
Chapter 1 These slides for CSE 110 Sections are based in part on the textbook-authors’ slides, which are copyright by the authors. The authors state that.
Week 1 - Wednesday.  What did we talk about last time?  Syllabus  Computers.
Chapter 1: An Overview of Computers and Programming Languages J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program.
CHAPTER 1 INTRODUCTION GOALS  To understand the activity of programming  To learn about the architecture of computers  To learn about machine code and.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 1 “ Introduction to Java and OOP”
1 Programming & Programming Languages Overview l Machine operations and machine language. l Example of machine language. l Different types of processor.
1 Programming & Programming Languages Overview l Machine operations and machine language. l Example of machine language. l Different types of processor.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages C++ Programming:
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
Chapter 1 - Introduction. Ch 1Goals To understand the activity of programming To learn about the architecture of computers To learn about machine code.
COMP Computer Basics Yi Hong May 13, 2015.
CS190/295 Programming in Python for Life Sciences: Lecture 1 Instructor: Xiaohui Xie University of California, Irvine.
Introduction to Computers and Python. What is a Computer? Computer- a device capable of performing computations and making logical decisions at speeds.
Computer Programming-1 CSC 111 Chapter 1 : Introduction.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
Chapter Introduction to Computers and Programming 1.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
Introducing Java.
COMPUTER SOFTWARE Section 2 “System Software: Computer System Management ” CHAPTER 4 Lecture-6/ T. Nouf Almujally 1.
Topics Introduction Hardware and Software How Computers Store Data
Week 1 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
INTRODUCTION TO COMPUTING
1 TOPIC 1 INTRODUCTION TO COMPUTER SCIENCE AND PROGRAMMING Topic 1 Introduction to Computer Science and Programming Notes adapted from Introduction to.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
What is a Computer? An, electrical machine, that can be programmed to accept data (input), process it into useful information (output) and store it away.
Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Chapter One: Introduction.
Week 1 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Chapter 1 CSIS-120: Java Intro. What is Programming?  A: It is what makes computer so useful.  The flexibility of a computer is amazing  Write a term.
C++ Programming Language Lecture 1 Introduction By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter 1 – Introduction.
Introduction to Computer Systems and the Java Programming Language.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 1: An Overview of Computers and Programming Languages.
CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture.
Fall 2006Slides adapted from Java Concepts companion slides1 Introduction Advanced Programming ICOM 4015 Lecture 1 Reading: Java Concepts Chapter 1.
Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.
CHAPTER 1 INTRODUCTION 1 st Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
CHAPTER 1 INTRODUCTION 2 nd Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
CS 127 Introduction to Computer Science. What is a computer?  “A machine that stores and manipulates information under the control of a changeable program”
1 TOPIC 1 INTRODUCTION TO COMPUTER SCIENCE AND PROGRAMMING Topic 1 Introduction to Computer Science and Programming Notes adapted from Introduction to.
1 WELCOME TO CIS 1068! Instructor: Alexander Yates.
Beginning Snapshots Chapter 0. C++ An Introduction to Computing, 3rd ed. 2 Objectives Give an overview of computer science Show its breadth Provide context.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
Chapter 1 : Overview of Computer and Programming By Suraya Alias
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Chapter 1 Introduction. Chapter Goals To understand the activity of programming To learn about the architecture of computers To learn about machine code.
CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To learn about the architecture of computers To learn about machine code.
How a Computer Processes Data. With today’s technology a little knowledge about what’s inside a computer can make you a more effective user and help you.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
ITP 109 Week 2 Trina Gregory Introduction to Java.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 1: An Overview of Computers and Programming Languages.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Chapter 1 Introduction 2nd Semester H
Topics Introduction Hardware and Software How Computers Store Data
Chapter 1: An Overview of Computers and Programming Languages
Lecture 1: Introduction to JAVA
Java programming lecture one
Topics Introduction Hardware and Software How Computers Store Data
Introduction CSC 111.
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
Computer Programming-1 CSC 111
Presentation transcript:

Chapter 1 - Introduction

Announcements Info Sheet Web Site: Lab Hours NotecardsPictures

A Simple Program Most simple program – Hello World Outputs “Hello, World!” to the screen Outputs “Hello, World!” to the screen public class HelloTester { public static void main(String[] args) { //display a greeting in the console System.out.println(“Hello, world!”); }}

Questions / Outline What is a computer program? What makes a computer program work? How do you write computer programs? What does it mean to “program in Java”? What is object-oriented programming?

Computer Programs Computers perform operations based on sequences of instructions A program is simply a sequence of instructions The behavior of a program is what happens when the computer executes the instructions Note: Programs may behave differently given different user input

Computer Programs Sophisticated programs require teams of highly skilled programmers and other professionals Computer programs are used to make many tasks more efficient There are programs for a wide variety of tasks There are programs for a wide variety of tasks Flexibility arises because we program a specific task for the computer

Computers A computer is a machine that can accomplish a set of basic instructions Stores data Stores data Interacts with devices Interacts with devices Executes programs Executes programs A program is a set of instructions and decisions used to carry out a task

Computers Computers have come a long way, and will continue to advance – but they still maintain the basic components: CPU CPU Storage Storage Input and Output Devices Input and Output Devices

CPU Central Processing Unit (CPU) - Brain of the computer It’s a chip made with millions of transistors It’s a chip made with millions of transistors Athlon, Pentium, PowerPC Athlon, Pentium, PowerPC Executes instructions given by a program Executes instructions given by a program

Storage Storage is where a computer stores information that helps it execute instructions 3 Major Types Primary Primary Secondary Secondary Removable Removable

Primary Storage Random Access Memory(RAM) Fast but expensive Fast but expensive All electronic, so it loses info when power is stopped All electronic, so it loses info when power is stopped

Secondary Hard Disk Less expensive, but slow Less expensive, but slow Maintains data even when the computer is turned off Maintains data even when the computer is turned off

Removable Floppies, CD-ROMs, Zip Disks, Thumb Drives Maintain information without power, plus you can take them with you

Connections Network: computers can be interconnected with each other Peripheral Devices: how computers and humans communicate Input: keyboard, mouse, iris scanner Input: keyboard, mouse, iris scanner Output: speakers, screen, printer Output: speakers, screen, printer Internal Bus: The computer sends and receives data to it’s different parts via a bus (think of this as a highway)

Questions Where is a program stored when it is not currently running? Which part of the computer carries out arithmetic operations, such as addition and multiplication?

Programming Very simply, programming is writing a computer program While this may sound straightforward, it’s actually much more complex…

From Instructions to Code A computer needs to be able to understand what instructions it needs to execute There is only one real language a computer understands: However, there are many languages a program can be written in Machine Code Machine Code Assembly Language Assembly Language High Level Languages High Level Languages

Machine Code The most basic level of instructions Everything is in binary (ones and zeros) Humans cannot easily read machine code, but the only language a computer can read is machine code

Problems With Machine Code Very primitve Commands: Add, subtract, load from memory Commands: Add, subtract, load from memory Leads to coding of several hundred lines to perform one simple operation Leads to coding of several hundred lines to perform one simple operation Not Intuitive Can you look at machine code and tell what the program is doing? Can you look at machine code and tell what the program is doing? Not universal Each CPU translates different binary strings to mean different things Each CPU translates different binary strings to mean different things

Assembly Language add 1, R2, R3 Not used in Java Has a direct translation to machine code Slightly easier to read Still has only a small set of instructions that it can perform Takes a long time to write a big program Hard to find errors and still not universal

High Level Languages sum = Math.sqrt(3) + 2 * 5; High level languages are much more understandable and expressive One statement is converted into several machine code instructions One statement is converted into several machine code instructions The conversion is done by the compiler Compiler: High-Level to Assembly Assembler: Assembly to Machine Code

The Java Programming Language Simple – easy to understand Safe – more secure, less error-prone Platform-Independent - "write once, run anywhere") Rich Library – lots of tasks are already accomplished for you Designed with the internet in mind

Java Virtual Machine Unique to Java Instead of compiling on processor, Java compiles to a virtual processor that is the same for every computer Lesson: The code is the same no matter what computer you are on, so you don’t have to make a Mac version and a PC version, etc.

Flaws Simple programs takes a little more effort than with C++ and other languages Many revisions made – make sure you update if you work from home to Java 5.0+ Rich libraries  Lots to learn

Programming Tools There are many tools available for programming in two categories: Editor & Compiler Pair Editor & Compiler Pair Integrated Development Environment (IDE) Integrated Development Environment (IDE) We will be using the Eclipse IDE Originally developed by IBM Originally developed by IBM Now an open-source project Now an open-source project Free & available for many platforms Free & available for many platforms

Programming Tips Become familiar with the environment you’ll be using Organize your files in a logical manner Save and backup your work often You only need to backup source files You only need to backup source files Know which copy of your program you’re working on Know which copy of your program you’re working on

Writing a Simple Program Recall our simple program: public class HelloTester { public static void main(String[] args) { //display a greeting in the console window System.out.println(“Hello, world!”); }} Prints “Hello, world!” to the screen

Simple Program What does each line mean? Class Declaration Class Declaration Method Declaration Method Declaration Method Body Method BodyComments Program Statements

Class Declaration public class HelloTester A class is an essential part of a Java program – all instructions are contained within a class A class is an essential part of a Java program – all instructions are contained within a class Every program contains one or more classes Every program contains one or more classes Important: If we create a class named HelloTester, the filename must be HelloTester.java (case-sensitive!) Important: If we create a class named HelloTester, the filename must be HelloTester.java (case-sensitive!)

Method Declaration public static void main(String[] args) {} Classes contains both data and methods Classes contains both data and methods Methods are sequences of instructions Methods are sequences of instructions For example, a Robot class might contain methods for walking, talking, and grabbing For example, a Robot class might contain methods for walking, talking, and grabbing Every program must have a method called main Every program must have a method called main A program always starts by executing the sequence of instructions in the main method A program always starts by executing the sequence of instructions in the main method

Method Declaration public static void main(String[] args) {} String[] args is a parameter of the main method, meaning it is data the method is given as input String[] args is a parameter of the main method, meaning it is data the method is given as input public and static are modifiers that describe what kind of method main is public and static are modifiers that describe what kind of method main is void is the return type of the method void is the return type of the method

Method Body //display a greeting in the console window System.out.println(“Hello, world!”); Contains the sequence of instructions that the method should execute Contains the sequence of instructions that the method should execute Also contains comments which are descriptions of what a line or a sequence of lines is trying to accomplish Also contains comments which are descriptions of what a line or a sequence of lines is trying to accomplish Each instruction ends in a semi-colon (;), but comments do not have such restrictions Each instruction ends in a semi-colon (;), but comments do not have such restrictions

Comments //display a greeting in the console window “//” signifies not to execute this line of code “//” signifies not to execute this line of code Anything written after “//” is ignored Anything written after “//” is ignored The main purpose of comments is to explain code to anyone reading your code (including yourself!) The main purpose of comments is to explain code to anyone reading your code (including yourself!) Other varieties of comments: Other varieties of comments: /* Anything in here is ignored */ /* Anything in here is ignored */ /** Anything in here is ignored, but can be used for automatic documentation */ /** Anything in here is ignored, but can be used for automatic documentation */

Sequence of Instructions System.out.println(“Hello, world!”); The only thing we are trying to do is print “Hello, world!” to the screen The only thing we are trying to do is print “Hello, world!” to the screen This takes only one instruction – usually we have many more This takes only one instruction – usually we have many more The type of instruction is a method call on an object The type of instruction is a method call on an object

Notes Java is case-sensitive Cannot call the method Main instead of main Cannot call the method Main instead of main Cannot call system.out.println() instead of System.out.println() Cannot call system.out.println() instead of System.out.println() Java is free form – the amount of white space is irrelevant to the computer (although it is important for readability) You could have all instructions on one line… You could have all instructions on one line…

Programming Errors Two types of errors Syntax Errors = compile-time errors Syntax Errors = compile-time errors These are caught when you ask Java to convert your program to machine code Your program must follow a set of rules called a grammar (just like a sentence in English) Logic Errors = run-time errors Logic Errors = run-time errors Not problems in the syntax, but problems in logic Program does not accomplish what the programmer intended

Programming & Compiling The sequence of instructions that a programmer writes is called source code Saved as a.java file Saved as a.java file A compiler takes source code and creates machine code Saved by compiler as.class file Saved by compiler as.class file Java combines previously written code (libraries) with the source code when it runs the program

From Editing to Executing Create source code (.java files) Compiler converts source code to machine code (.class files) Class files are integrated with library files (files that define a set of useful classes) To run the program, JVM combines class files with library files and runs the program

Edit-Compile-Test Edit: Write or revise your source code Compile: Run the compiler program to translate source code to machine code If there are syntax errors, go back and edit If there are syntax errors, go back and edit Test: Run your program, see if it works, and try to break If there are logic errors, go back and edit If there are logic errors, go back and edit

Object Oriented Programming This is an introduction to programming with Java It is not simply a course in Java syntax One of the big selling points of Java is the fact that it is object-oriented We will cover the concepts of OOP later, but it is helpful to have some background of this paradigm earlier

What is Object Oriented Programming? It is an evolutionary form of modular programming with more formal rules that allow pieces of software to be reused and interchanged between programs. A style of computer programming which entails building of independent pieces of code which interact with each other.

What are the advantages to OOP? CohesiveEfficientClearer

Objects and Classes Analogy: class : object as blueprint : house Objects simply represent an entity Think of objects as nouns (eg a robot) Think of objects as nouns (eg a robot) Objects have data (eg name=Fred) and methods (eg moveRight(), turnLeft() ) Objects have data (eg name=Fred) and methods (eg moveRight(), turnLeft() ) To use objects, simply call the method on the object: To use objects, simply call the method on the object:robot.moveRight();robot.getName();

Objects and Classes Classes are blueprints to build objects They are a template/mold for an object, but they aren’t the actual objects They are a template/mold for an object, but they aren’t the actual objects They define what objects know (eg their name) and what they can do (eg moveRight) They define what objects know (eg their name) and what they can do (eg moveRight) Just like you can’t water the front lawn of a blueprint, you can’t accomplish anything with a class Just like you can’t water the front lawn of a blueprint, you can’t accomplish anything with a class You use classes to build objects You use classes to build objects

Methods Each method call executes the code in that method (it’s a mini-program) You can call methods on objects Methods may do different things for different objects Methods may do different things for different objects You can only call methods that are defined by the class on the object You can only call methods that are defined by the class on the object