Java Basics Lecture: January 26, 2012 (On-line Lecture 1)

Similar documents
COMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2016

CS 177 Recitation. Week 1 Intro to Java

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

COMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2015

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

Midterms Save the Dates!

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

Computer Hardware. Java Software Solutions Lewis & Loftus. Key Hardware Components 12/17/2013

Introduction to Software Development (ISD) David Weston and Igor Razgon

CSE 142. Lecture 1 Course Introduction; Basic Java. Portions Copyright 2008 by Pearson Education

Lab # 2. For today s lab:

COMP163. Introduction to Computer Programming. Introduction and Overview of the Hardware

St. Edmund Preparatory High School Brooklyn, NY

Darrell Bethea May 25, 2011

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction

CHAPTER 1 Introduction to Computers and Java

CMSC 150 LECTURE 1 INTRODUCTION TO COURSE COMPUTER SCIENCE HELLO WORLD

! Learn how to think like a computer scientist. ! Learn problem solving. ! Read and write code. ! Understand object oriented programming

A very simple program. Week 2: variables & expressions. Declaring variables. Assignments: examples. Initialising variables. Assignments: pattern

ICOM 4015: Advanced Programming

CS 121 Intro to Programming:Java - Lecture 2. Professor Robert Moll (+ TAs) CS BLDG

Introduction to Computers and Java. Objectives. Outline. Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich.

Introduction to Computers and Java

Microprocessors I MICROCOMPUTERS AND MICROPROCESSORS

Introduction to Computers and Java

An Introduction to Computers and Java CSC 121 Spring 2015 Howard Rosenthal

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

CSCI 1103: Introduction

Introduction to Computers and Java. Objectives. Outline. Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich.

Programming with Java

Week 2: Data and Output

(Refer Slide Time 00:01:09)

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

A PROGRAM IS A SEQUENCE of instructions that a computer can execute to

Software and Programming 1

Introduction to Java Unit 1. Using BlueJ to Write Programs

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

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

Machine Architecture and Number Systems CMSC104. Von Neumann Machine. Major Computer Components. Schematic Diagram of a Computer. First Computer?

CPS122 Lecture: From Python to Java last revised January 4, Objectives:

First Java Program - Output to the Screen

Chapter 1. Introduction to Computers and Java Objects. Background information. » important regardless of programming language. Introduction to Java

CS 121 Intro to Programming:Java - Lecture 2. Professor Robert Moll (+ TAs) CS BLDG

CSE 1223: Introduction to Computer Programming in Java Chapter 1 Computer Basics

Introduction to Computer Programming for Non-Majors CSC 2301, Fall The Department of Computer Science

2/9/2012. Chapter One: Introduction. Chapter Goals

Chapter 1: Why Program? Main Hardware Component Categories 8/23/2014. Main Hardware Component Categories: Why Program?

The Programming Process Summer 2010 Margaret Reid-Miller

CSC116: Introduction to Computing - Java

Program Fundamentals

Topics. Hardware and Software. Introduction. Main Memory. The CPU 9/21/2014. Introduction to Computers and Programming

CSc 2010 Principles of Computer Science, Fall 2013 Practice Problems for Midterm 3* * 3 17 % 9-20 % (26 / 7) "2"

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

CS 11 java track: lecture 1

EECE 321: Computer Organization

Chapter 1: Introduction to Computers and Java

8/23/2014. Chapter Topics. Introduction. Java History. Why Program? Java Applications and Applets. Chapter 1: Introduction to Computers and Java

Notes from the Boards Set # 5 Page

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

CSC 121 Computers and Scientific Thinking

Pace University. Fundamental Concepts of CS121 1

Chapter 1: Introduction to Computers and Programming

Introduction Basic elements of Java

Midterms Save the Dates!

COMP Computer Basics. Yi Hong May 13, 2015

These are notes for the third lecture; if statements and loops.

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

Algorithms and Programming I. Lecture#12 Spring 2015

Pointers, Arrays and Parameters

From Algorithms to Architecture....a lightning introduction to computer architecture

AP Computer Science Unit 1. Writing Programs Using BlueJ

Introduction to Computers and Java

1.00 Lecture 4. Promotion

Chapter Goals. Chapter One: Introduction. Prerequisites. What Is Programming?

Chapter 1 INTRODUCTION

Using Classes and Objects. Lecture 7. Midterms Save the Dates! Extra Credit Survey

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

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

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

CS 116. Lab Assignment # 1 1

Lecture 02, Fall 2018 Friday September 7

Darrell Bethea May 10, MTWRF 9:45-11:15 AM Sitterson 011

Lesson 01 Introduction

Lecture 1 - Introduction (Class Notes)

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

AP Computer Science Unit 1. Programs

AP Computer Science Unit 1. Writing Programs Using BlueJ

Pharmacy college.. Assist.Prof. Dr. Abdullah A. Abdullah

9/11/08 (c) 2008 Matthew J. Rutherford Class (c) 2008 Matthew J. Rutherford Class

AP Computer Science Summer Assignment (updated 5/29/2018) DUE : Sept. 4, 2018

Programming 1 - Honors

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

CSC116: Introduction to Computing - Java

Introduction to Computers and Java

Chapter 1 Introduction to Computers, Programs, and Java

Introduction. Lecture 1 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz

CS 220: Introduction to Parallel Computing. Beginning C. Lecture 2

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 10: OCT. 6TH INSTRUCTOR: JIAYIN WANG

Welcome to CSE 142! Whitaker Brand. University of Washington, Winter 2018

S206E Lecture 19, 5/24/2016, Python an overview

Transcription:

Java Basics Lecture: January 26, 2012 (On-line Lecture 1) CMPSCI 121, Spring 2012 Introduction to Problem Solving with Computers Prof. Erik Learned-Miller

Logistics Previous lectures are on-line. See links on syllabus page. Some of you have just been enrolled in Spire, but may not have OWL accounts yet. We will try to do that today. 1

Assignments due next Tuesday Read Chapter 0 Do Configuration Tester OWL Survey OWL Tutorial Figure out how to install and start DrJava 2

You might as well get started on Chapter 1 Reading Chapter 1 Embedded Exercises Chapter 2 Reading. 3

Late Assignments With a class this large, we just can t manage late assignments. Instead, we give you an allowance of assignments you can drop. WARNING: An assignment that is 1 minute late will get a 0. Don t turn it in at the last second! 4

Trying again, and multiple turn-ins Embedded E-book exercises Try as many times as you want Weekly OWL Exercises Check UNIT menu. If number of tries is limited, it will tell you total, and also number you have left. Programming Assignments Turn in as many times as you want. Turn in a version well before the deadline! 5

Dropping Assignments Embedded E-book exercises Can t drop any of these 12 Weekly OWL exercises You can drop lowest 2 of these 8 Programming Assignments You can drop 1 of these 6

Dropping Assignments Dropping assignments is meant for when you are sick or have an unavoidable conflict. If you drop 2 assignments early (when you re not sick), and then you can t finish a 3 rd one because you re sick, you will get a 0 for it. 7

My recommendation Since the hardest assignments are at the end of the class, and You want to save your drops as long as possible Don t skip any assignments until the end of the term, or unless you re really sick. If you re really sick (or have another SERIOUS excuse, like death in the family), get a doctors note in case it lasts for more than 2 assignments. 8

On-line lectures 9

On-line lectures 10

On-line lectures 11

Basic terminology and structure Memory Central processing unit (CPU) Secondary storage Input and output devices (IO devices) 12

Memory Bits and Bytes Binary numbers Convention: 0 is low voltage, 1 is high voltage How does the computer remember a number? Take a class in digital logic or digital circuit design. How to represent things other than numbers? Letters? (Morse Code) Colors? More conventions Volatility 13

Conventions Question: How to store a letter with nothing but 1 s and 0 s? Answer: A convention that everyone agrees on. Example: Morse code 14

Morse Code 15

More conventions How do I store a single color in a computer? Another convention: 000000 = red 000001 = blue 000010 = green 111111 = yellow 16

To store an image Just store the numbers associated with the color of each pixel, and then do color by number to recreate the image. 17

Memory (Primary storage) Remembers 1 bit. Memory module. Remembers 1,000,000,000 bits!!! volatile memory 18

Central Processing Unit (CPU) Solves math problems. Not built to move data around or store data Examples: Intel s Pentium Intel s Xeon Advanced Micro Devices Opteron The good old days: 80386, 6502, Z80. Multi-core chips: multiple CPU s on a chip. Like having more than one TA. Great, but can be tough to manage! 19

CPUs 20

Secondary Storage Hard disks, floppy disks, magnetic tapes Hold the data when you turn off the power Non-volatile storage Changes magnetization of tape Think of a cassette tape. 21

Hard disk http://www.karbosguide.com/books/pcarchitecture/images/893.jpg 22

Multi-platter hard drive 23

Old-school Disk Storage http://www.juneberry78s.com/sounds/78turntable.jpg 24

Input/Output devices (IO) Anything that allows you to put information into your computer Keyboard, mouse, microphone, Electroencephalogram recorder! Or to get information out of your computer Printer, monitor (screen), haptic feedback device, telepresence device, brain stimulator 25

Nature 442, 164-171 (13 July 2006) doi:10.1038/nature04970; Received 22 March 2006; Accepted 6 June 2006 Neural Prosthetics Neuronal ensemble control of prosthetic devices by a human with tetraplegia 26

Portability of Java Java gets translated to bytecode Same bytecode used on all machines Each machine has a translator from bytecode to machine-specific machine language How does a computer do these translations? Take a class in compilers. 27

Finally: Programming 1 public class Greetings{! 2 public static void main(string[] args){! 3 System.out.print("Hello ");! 4 System.out.print("out ");! 5 System.out.print("there");! 6 }! 7 }! 28

Writing a program in DrJava Open Dr. Java Open a New edit window Click on New Type in the program Save the program Use the name that appears immediately after the first occurrence of the word class Greetings Compile the program Click compile. If errors are reported, fix errors. Run the program Click run 29

Editing Programs (or code ) Details of the code affect how it will work Semicolons, quotations marks, parentheses, etc. Follow E-book carefully. Beware the single line editing window: 30

Example problem 31

Printing Strings and Numbers System.out.println( Stuff I want to say. ); Stuff I want to say. System.out.println( Sch + wing ); Schwing System.out.println(3+5); 8 System.out.println( 3+5 ); 3+5 32

Printing Strings and Numbers System.out.println(5+ a ); 5a System.out.println( a + 5); Why? a5 It makes sense to convert a number to a string Put quotes around it. It doesn t (always) make sense to convert a string to a number. How do we convert Hello to a number? 33

Strings and numbers Mixtures of strings and numbers. From left to right, combine strings and numbers. number + number number string + string string number + string string string + number string (how can you remember this?) What will this do? System.out.println(3+5+ a +3+5); 34

Strings and numbers What will this do? System.out.println(3+5+ a +3+5); 3+5+ a +3+5 8 3+5+ a +3+5 8a 3+5+ a +3+5 8a3 3+5+ a +3+5 8a35 35

Confused? Go to DrJava and experiment! 36

Variables Variables are used to store something for later use: x = 3; y = 5; s = Erik ; pi = 3.14159; 37

Variable names Can t use arbitrary names Why? Don t start with numbers: 3x Don t use most special symbols: xy?!!! 38

Declaration Tells Java what a variable represents x is an integer. int x; x is a String. String x; 39

Insight into declarations Declarations tell the computer which convention to use. Tells the computer how to interpret a certain set of ones and zeros in memory. 40

Assignment Gives a variable a value. x=3; s= Hello ; y = x + 5; // What will y be? z=0; 41

Assignment Assignments are NOT statements of equality. x=y Does NOT mean that x equals y. Instead, it means, take the value that is currently in y and put it in x. Consider this assignment: x=x+1 This means: take the value that is currently in x, add one to it, and then put that sum back into x. 42

Assignment How to say x=y. x gets y, Not x equals y. 43

Declaration and assignment together int x = 3; Could have been instead: int x; x = 3; 44