COMP 110: Introduction to Programming Tyler Johnson January 14, 2009 MWF 11:00AM-12:15PM Sitterson 014.

Slides:



Advertisements
Similar presentations
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Advertisements

CSCE 145: Algorithmic Design I Chapter 1 Intro to Computers and Java Muhammad Nazmus Sakib.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
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.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
1 Fall 2008ACS-1903 Chapter 1 Topics Java History Java Programs Why Program? Computer Systems: Hardware and Software Programming Languages What Is a Program.
Wednesday, 9/4/02, Slide #1 1 CS 106 Intro to CS 1 Wednesday, 9/4/02  Today: Introduction, course information, and basic ideas of computers and programming.
Introduction to Computers
Begin Java having used Alice Pepper - Some slides from Alice in Action with Java.
1 Programming & Programming Languages Overview l Machine operations and machine language. l Example of machine language. l Different types of processor.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
COMP Computer Basics Yi Hong May 13, 2015.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Why Program? Computer – programmable machine designed to follow instructions Program – instructions in computer memory to make it do something Programmer.
Introducing Java.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Topics Introduction Hardware and Software How Computers Store Data
COMP 110 Computer Basics Luv Kohli August 25, 2008 MWF 2-2:50 pm Sitterson
COMP 110 Spring Announcements Computers in class on Friday: Lab Office Hours: Monday 12-2 New students see me after class Administrative Changes.
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.
Catie Welsh January 12, 2011 MWF 1-1:50 pm Sitterson
CS 106 Introduction to Computer Science I 01 / 25 / 2010 Instructor: Michael Eckmann.
Introduction to Computers
1 Introduction to Computers Prof. Sokol Computer and Information Science Brooklyn College.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 1 Introduction to Computers and Programming.
1 Agenda Administration Background Our first C program Working environment Exercise Memory and Variables.
Introduction to Computers and Java Chapter 1.3. A Sip of Java: Outline History of the Java Language Applets A First Java Program Compiling a Java Program.
1 Introduction to Java Brief history of Java Sample Java Program Compiling & Executing Reading: => Section 1.1.
Session One Introduction. Personal Introduction Role of programmers Robot Examination HUD & HID Uploading Code.
Object Oriented Programming Computer Engineering Department JAVA Programming Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2014.
Introduction to Computer Systems and the Java Programming Language.
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
Week 1 - Friday.  What did we talk about last time?  Our first Java program.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Mrs. Ulshafer August, 2013 Java Programming Chapter 1.
Fall 2006Slides adapted from Java Concepts companion slides1 Introduction Advanced Programming ICOM 4015 Lecture 1 Reading: Java Concepts Chapter 1.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Introduction to Programming
Introduction Chapter 1 8/31 & 9/1 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
1 WELCOME TO CIS 1068! Instructor: Alexander Yates.
Chapter 1- Basic Computing and your first program.
Chapter 1 Introduction. Chapter Goals To understand the activity of programming To learn about the architecture of computers To learn about machine code.
COMP 110: Introduction to Programming Tyler Johnson Feb 16, 2009 MWF 11:00AM-12:15PM Sitterson 014.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Computer and Programming. Computer Basics: Outline Hardware and Memory Programs Programming Languages and Compilers.
Ch 1 - Introduction to Computers and Programming Hardware Terminology Main Memory Auxiliary Memory Drives Writing Algorithms Using Pseudocode Programming.
1 Introduction to Computers Prof. Sokol Computer and Information Science Brooklyn College.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
CS 177 Recitation Week 1 – Intro to Java. Questions?
CS 106 Introduction to Computer Science I 01 / 24 / 2007 Instructor: Michael Eckmann.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Lecture 1b- Introduction
Topics Introduction Hardware and Software How Computers Store Data
Console Output, Variables, Literals, and Introduction to Type
Something about Java Introduction to Problem Solving and Programming 1.
Mobile Development Workshop
Michele Weigle - COMP 14 - Spr 04
Introduction to Computers
Topics Introduction Hardware and Software How Computers Store Data
Introduction to Java Brief history of Java Sample Java Program
Computer Programming-1 CSC 111
Presentation transcript:

COMP 110: Introduction to Programming Tyler Johnson January 14, 2009 MWF 11:00AM-12:15PM Sitterson 014

COMP 110 Spring Announcements Hand in HW0 at the front of the room after class

COMP 110 Spring Questions?

COMP 110 Spring Today in COMP 110 Hardware and Memory Programs and Compiling Your first JAVA program!

COMP 110 Spring Before Programming Need to know basics of a computer If you drive a car you should know it runs on gasoline What’s in the box?

COMP 110 Spring Hardware vs. Software Hardware Physical machine CPU, Memory Software Set of instructions for the machine to execute

COMP 110 Spring Hardware ENIAC One of the first general purpose programmable computers Visit the computer museum in the first floor lobby of Sitterson Hall

COMP 110 Spring Hardware CPU (Central Processing Unit) Executes instructions specified by a programmer GHz - number of instructions per second, how fast is the computer Dual Core - multiple processing units per CPU

COMP 110 Spring Memory Holds data for the computer to process Main Memory (RAM – Random Access Memory) Used for intermediate calculations Used to store the current program itself! Expensive Auxiliary Memory (Secondary Memory) Disk drives, CDs, Flash drives Cheap

COMP 110 Spring Measuring Memory Measured in bytes For example 2 gigabytes (GB) of RAM Megabyte (MB) = 1 million (10 6 ) bytes (or 1,048,576 = 2 20 bytes) Gigabyte (GB) = 1 billion (10 9 ) bytes (or 1,073,741,824 = 2 30 bytes)

COMP 110 Spring What is a Byte? Data, such as numbers and keyboard characters are stored as series of bits A bit is a digit with value 1 or 0 Examples is a byte with value is a byte with value is a byte with value 97 A byte is composed of 8 bits Just large enough to store a keyboard character

COMP 110 Spring Encoding Characters How to encode keyboard characters? Assign each character a number Example (ASCII) ( ) 65 = A ( ) 66 = B ( ) 67 = C ….

COMP 110 Spring Main Memory Called RAM (Random Access Memory) Fast access Access any location in memory in constant time Addressable Every byte has an address that is used when writing or reading data to memory

COMP 110 Spring What is a Program? Set of instructions for a computer to follow Example instructions: Add two numbers Divide two numbers Store a number at a memory location

COMP 110 Spring Programs Programs take data as input and produce a useful result Example A spell-checking program takes a text file as input and produces a list of misspelled words as output InputProgramOutput

COMP 110 Spring Programming Languages Modern programming languages (Java, C/C++) are designed to be human-readable Called high-level languages Computers can’t understand high level languages A Compiler translates our human-readable program into a machine-readable program Compiler is a program as well!

COMP 110 Spring Role of Compilers Program Source Code Compiler Machine Code Human-readable, What you will be writing in this class Machine-readable, What the machine actually executes Note: Java uses a slightly different approach, which we’ll see later

COMP 110 Spring Human- vs Machine Readable A human-readable instruction to add two numbers a = b + c; The equivalent machine-readable instruction might look this!

COMP 110 Spring Review What we’ve covered so far Hardware & Memory Programs and Compiling Now let’s learn a bit about Java

COMP 110 Spring Java A high-level programming language Java source code is human-readable Originally envisioned as a programming language for home appliances Is now the language of choice for internet applications Example internet application using Java

COMP 110 Spring Java Java is an interpreted language Compiler produces bytecode instead of machine code Bytecode is not quite readable by any machine When a Java program is run, an interpreter translates the bytecode into machine code on-the- fly The Java interpreter is called the Java Virtual Machine (JVM)

COMP 110 Spring Compiling & Running Java Programs Java program Java compiler Bytecode program Bytecode interpreter (Java JVM) Machine code Compiling a Java program Running a Java program Human- readable Machine- readable Java JVM- readable

COMP 110 Spring Java Interpreter Why is Java interpreted? The short answer is portability Can run the same byte code on any machine! No need to recompile for Windows or Mac OS X Ideal for internet applications

COMP 110 Spring Your First Java Program Source code on the next slide Displays a welcome message Asks the user to input two numbers Displays the sum of the numbers

COMP 110 Spring Sample Java Program (Section 1.2) import java.util.Scanner; public class FirstProgram { public static void main(String[] args) { System.out.println("Hello out there."); System.out.println("I will add two numbers for you."); System.out.println("Enter two whole numbers on a line:"); int n1, n2; Scanner keyboard = new Scanner(System.in); n1 = keyboard.nextInt(); n2 = keyboard.nextInt(); System.out.println("The sum of those two numbers is"); System.out.println(n1 + n2); } }

COMP 110 Spring Importing Packages import java.util.Scanner; Tells the compiler that this program uses the class “Scanner” in the package “java.util” A class is a piece of code that we give a name to So that when the Scanner class is used later in the program, the compiler knows what we’re referring to A package is a library of classes that have already been defined for you “java.util” – for various utilities such as reading input from the keyboard

COMP 110 Spring Begin the Program public class FirstProgram { … } Begin the class “FirstProgram” A class is just a piece of code that we give a name to Everything within the curly braces will be part of “FirstProgram”

COMP 110 Spring Classes Java programs are rarely written as a single piece of code all in one file They are typically divided into separate pieces called classes For know, think of classes as pieces of Java code

COMP 110 Spring Main Method public static void main(String[] args) { … } Begin the method called “main” Everything between the curly braces is part of the method “main” Methods contain lines of code that actually perform some action (statements) The group of statements within a method make up the method body Every Java program has a method called main

COMP 110 Spring Program Set-Up So far we have import java.util.Scanner; public class FirstProgram { public static void main(String[] args) { …} As of yet, the code performs no action Now for the body of the “main” method where the action occurs

COMP 110 Spring Output to Screen System.out.println("Hello out there."); System.out.println("I will add two numbers for you."); System.out.println("Enter two whole numbers on a line:"); These statements prints what is in quotes out to the screen Example System.out.println("Hello out there."); Causes “Hello out there.” to be printed out to screen

COMP 110 Spring Methods and Objects What does “System.out.println” mean? “System.out” is an object Java programs use objects to perform actions The actions are defined by methods “println” is a method that prints a message to the screen The println method is part of the System.out object

COMP 110 Spring Invoking Methods on Objects myCar.start() airplane.land() System.out.println(“Hi”.) ObjectsMethods Argument

COMP 110 Spring Variable int n1, n2; Declares “n1” and “n2” as variables that will be used to store data int is the data type that will be used for n1 and n2 int indicates an integer (whole number)

COMP 110 Spring Create Scanner Object Scanner keyboard = new Scanner(System.in); Enables the program to read data from the keyboard Creates an object of Scanner class called “keyboard” Class Object Class

COMP 110 Spring Call Method on Object n1 = keyboard.nextInt(); Read an integer from the keyboard and store it in n1 Object Method Invoke/Call

COMP 110 Spring Output to Screen System.out.println("The sum of those two numbers is"); System.out.println(n1 + n2); Add n1 and n2 Print the sum to the screen

COMP 110 Spring Sample Java Program (Section 1.2) import java.util.Scanner; public class FirstProgram { public static void main(String[] args) { System.out.println("Hello out there."); System.out.println("I will add two numbers for you."); System.out.println("Enter two whole numbers on a line:"); int n1, n2; Scanner keyboard = new Scanner(System.in); n1 = keyboard.nextInt(); n2 = keyboard.nextInt(); System.out.println("The sum of those two numbers is"); System.out.println(n1 + n2); } }

COMP 110 Spring Friday Recitation jGRASP Your first Java program Bring Laptop (fully charged) Textbook Download Java Development Kit (JDK) and jGRASP before lab (see webpage) Finish reading Sections 1.1, 1.2

COMP 110 Spring Announcements Hand in HW0 at the front of the room after class