COMP 110 Spring 20091 Announcements Computers in class on Friday: Lab Office Hours: Monday 12-2 New students see me after class Administrative Changes.

Slides:



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

 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Week 1 - Wednesday.  What did we talk about last time?  Syllabus  Computers.
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.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 24, 2005.
Introduction to Computers
COMP 14 Introduction to Programming
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.
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,
CS 0008 Day 2 1. Today Hardware and Software How computers store data How a program works Operators, types, input Print function Running the debugger.
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.
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: Introduction to Programming Tyler Johnson January 14, 2009 MWF 11:00AM-12:15PM Sitterson 014.
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.
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.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
Object Oriented Programming Computer Engineering Department JAVA Programming Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2014.
Lecture 2: Classes and Objects, using Scanner and String.
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
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.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
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.
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.
CSci 111 – computer Science I Fall 2014 Cynthia Zickos WRITING A SIMPLE PROGRAM IN JAVA.
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.
Chapter 1- Basic Computing and your first program.
© 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.
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
CS 177 Recitation Week 1 – Intro to Java. Questions?
CS 106 Introduction to Computer Science I 01 / 24 / 2007 Instructor: Michael Eckmann.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Lecture 1b- Introduction
Intro to ETEC Java.
Topics Introduction Hardware and Software How Computers Store Data
Introduction to Computers
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 Spring Announcements Computers in class on Friday: Lab Office Hours: Monday 12-2 New students see me after class Administrative Changes Exercise after lecture

COMP 110 Spring Today in COMP 110 Review 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 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, multiple brains

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 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 Terminology: Objects/Classes Class: archetype/blueprint/mold e.g. Person, Car, Film Object: concrete instance of a class e.g. John Hansen, 2006 Scion xB, American Beauty Classes declare the attributes of objects of its type and the actions they will perform Class: all cars have an attribute “make” and action “drive” Objects: several instance of a class each has a specific model: “Scion xB”, “Toyota Matrix” but performs the same action: “drive”

COMP 110 Spring Terminology: Variables Variables/Fields: specific storage/attributes String title = “Lost in Translation”; int length = 102; double stars = 4.5; Methods: actions a class performs int add(int x, int y) int square(int x) void display(int x) void clear()

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” 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 now, 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 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) Download Java Development Kit (JDK) and jGRASP before lab (see webpage)