1 WELCOME TO CIS 1068! Instructor: Alexander Yates.

Slides:



Advertisements
Similar presentations
Programming for Beginners
Advertisements

Begin Java Pepper. Objectives What is a program? Learn the basics of your programming tool: BlueJ Write a first Java program and see it run Make some.
JAVA BASICS SYNTAX, ERRORS, AND DEBUGGING. OBJECTIVES FOR THIS UNIT Upon completion of this unit, you should be able to: Explain the Java virtual machine.
JAVA BASICS SYNTAX, ERRORS, AND DEBUGGING. GCOC – A.P. Computer Science A College Board Computer Science A Topics Covered Program Design - Read and understand.
Building Java Programs Chapter 1 Introduction to Java 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.
Portions Copyright 2008 by Pearson Education CSE 142 Lecture 1 Course Introduction; Basic Java.
Copyright 2008 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading: self-check: #1-14.
CHAPTER 1 INTRODUCTION GOALS  To understand the activity of programming  To learn about the architecture of computers  To learn about machine code and.
Java Intro. A First Java Program //The Hello, World! program in Java public class Hello { public static void main(String[] args) { System.out.println("Hello,
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.
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 1: Introduction to Java Programming.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
Copyright 2013 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
1 Building Java Programs Chapter 1: Introduction to Java Programming These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may.
Copyright 2008 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading: self-check: #1-14.
Using C Programming Language.  The programs that run on a computer are referred to as software.  You’ll learn key programming methodology that are enhancing.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
Introducing Java.
Topic 2 Java Basics “When a programming language is created that allows programmers to program in simple English, it will be discovered that programmers.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
CSC204 – Programming I Lecture 4 August 28, 2002.
Programming With C.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
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.
Copyright 2009 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading: self-check: #1-14.
Robert Crawford, MBA West Middle School.  Explain how the binary system is used by computers.  Describe how software is written and translated  Summarize.
Output in Java Hello World!. Structure of a Java Program  All Java files in ICS3U1 have the following structure: class HelloWorld { }  Notice the open.
Building Java Programs Chapter 1 Introduction to Java Programming Copyright (c) Pearson All rights reserved.
Object- Oriented Programming (CS243)
Anatomy of a Java Program. AnotherQuote.java 1 /** A basic java program 2 * 3 Nancy Harris, James Madison University 4 V1 6/2010.
Chapter 1 Introduction. Chapter Goals To understand the activity of programming To learn about the architecture of computers To learn about machine code.
1 WELCOME TO CSE 142! host: benson limketkai University of Washington, Summer 2007.
CSC 110 – Intro to Computing - Programming
1 WELCOME TO CSE 142! host: benson limketkai University of Washington, Spring 2008.
CS 177 Recitation Week 1 – Intro to Java. Questions?
Copyright 2010 by Pearson Education CSE 142, Fall 2011 Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
Chapter 3 Introducing Java. Objectives and Goals 1. Define terminology associated with object- oriented programming. 2. Explain why Java is a widely used.
Advanced Programming CS206 Introduction 1. Programming Language Code A programming language is a language that uses specially defined words, grammar,
Copyright 2010 by Pearson Education CSE 142, Spring 2012 Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading: 1.1 -
Welcome to CSE 142! Zorah Fung University of Washington, Summer Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs.
Copyright 2010 by Pearson Education APCS Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
Zorah Fung University of Washington, Winter 2016
Chapter 1 – Introduction
CSC201: Computer Programming
Welcome to CSE 142! Whitaker Brand and Benson Limketkai
Chapter 3 GC 101 Java Fundamentals.
CSCI 161 – Introduction to Programming I William Killian
Chapter 2, Part I Introduction to C Programming
CSE 190D, Winter 2013 Building Java Programs Chapter 1
Benson Limketkai and Marty Stepp University of Washington, Spring 2010
Benson Limketkai University of Washington, Spring 2011
Building Java Programs
Whitaker Brand University of Washington, Winter 2018
Brett Wortzman University of Washington, Summer 2011
Advanced Programming CS206
Topic 2 Java Basics “When a programming language is created that allows programmers to program in simple English, it will be discovered that programmers.
Building Java Programs
Building Java Programs
Welcome to CSE 142!.
CSE 142, Summer 2012 Building Java Programs Chapter 1
CSE 142, Spring 2012 Building Java Programs Chapter 1
Zorah Fung University of Washington, Spring 2015
CSE 142, Winter 2014 Building Java Programs Chapter 1
© A+ Computer Science - Basic Java © A+ Computer Science -
Zorah Fung University of Washington, Winter 2016
Presentation transcript:

1 WELCOME TO CIS 1068! Instructor: Alexander Yates

2 What is computer science? computers? science? programming? late lonely nights in front of the computer? ALGORITHMIC THINKING al·go·rithm: a step-by-step procedure for solving a problem or accomplishing some end especially by a computer How does that relate to programming?

3 Just like Legos…

6 How to do well in this course Keep up with the assignments  The course material is cumulative  From a former student: “Procrastination will eventually come around to bite you in the ass!” If you don’t understand something, ask questions (especially “WHY?”).  “There’s no such thing as a dumb question.”

7 A Simple Model of a Computer

8 The 6 Parts

Random Access Memory (RAM, or just memory) Volatile storage  Each card can store up to a few gigabytes of data  Storage only lasts while computer has power Organization: Matrix  Some number of columns, either 32 or 64  Each cell stores a binary integer (bit): a 1 or a 0  Each row has an address, or row number RowBit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 Bit 7 …Bit … 2110… 3………… …

Central Processing Unit (CPU) Little chip, big deal: it does all the computing Think of it as a place where some instructions are stored, and carried out 1 by 1 Instructions can do basic math, and copy data and move it around (and that’s pretty much it) Copy 1 to 7*Start* Add 4 and 7, store in 8 Multiply 1 and 8 … … … …

Hard Disk (Disk, Hard Drive) Permanent (more or less) storage  Like memory, stores binary data  Unlike memory, it doesn’t forget anything when power is turned off. Organization: files, blocks, and cylinders  Complicated, we won’t get into it  The important point for us: It’s slow! (compared to memory)

12 Basic Java programs

13 Your first Java program! Java is a programming language. public class Hello { public static void main(String[] args) { System.out.println("Hello, world!"); } What does this code output (print to the user) when you run (execute) it?

Java code and machine code Notice: Java instructions don’t look like CPU instructions! CPU instructions (aka, machine code)  Written in binary  Easy and fast for machines to work with  Hard for programmers to work with Java code  Written in Java, a “high-level” (English-like) programming language  We use the Java compiler and virtual machine to translate from Java to machine code

15 Compiling a program Before you run a program, you must compile it. compiler: Translates a computer program written in one language (i.e., Java) to another language (i.e., byte code)‏ Compile (javac)Execute (java) outputsource code ( Hello.java )‏ byte code ( Hello.class )‏

The Java Virtual Machine (JVM, or VM) The Java Virtual Machine executes byte code  Use the “java” command to execute it  It only understands byte code (“.class” files) The VM makes Java a bit different from older programming languages (C, C++)  It’s an extra step; compilers for other languages directly produce machine code  It’s slower  But it allows the same byte code to run on any machine with a VM

17 Program execution The output is printed to the console. Some editors pop up the console as another window.

18 Another Java program public class Hello2 { public static void main(String[] args) { System.out.println("Hello, world!"); System.out.println(); System.out.println("This program produces"); System.out.println("four lines of output"); }

19 Writing your own Java programs public class { public static void main(String[] args) { ; … ; } Every executable Java program consists of a class  that contains a method called main that contains the statements (commands) to be executed

20 Syntax syntax: The set of legal structures and commands that can be used. Examples:  Every basic statement ends with a semi-colon.  The contents of a class occur between curly braces.

21 Syntax Errors syntax error: A problem in the structure of a program. 1public class Hello { 2 pooblic static void main(String[] args) { 3 System.owt.println("Hello, world!") 4 } 5} 2 errors found: File: Hello.java [line: 2] Error: Hello.java:2: expected File: Hello.java [line: 3] Error: Hello.java:3: ';' expected compiler output:

22 Finding syntax errors Error messages do not always help us understand what is wrong: File: Hello.java [line: 2] Error: Hello.java:2: expected pooblic static void main(String[] args) { Why can’t the computer just say “You misspelled ‘public’”?

23 First lesson in computer science Computers are stupid. Computers can’t read minds. Computers don’t make mistakes. If the computer is not doing what you want, it’s because YOU made a mistake.

24 More on syntax errors Java is case-sensitive  Hello and hello are not the same 1 Public class Hello { 2 public static void main(String[] args) { 3 System.out.println("Hello, world!"); 4 } 5 } 1 error found: File: Hello.java [line: 1] Error: Hello.java:1: class, interface, or enum expected compiler output:

25 System.out.println System.out.println : A statement to print a line of output to the console.  pronounced “print-linn” Two ways to use System.out.println : System.out.println(" ");  Prints the given message as a line of text to the console. System.out.println();  Prints a blank line to the console.

26 Strings string: A sequence of text characters.  Start and end with quotation mark characters Examples: "hello" "This is a string" "This, too, is a string. It can be very long!"

27 Details about strings A string may not span across multiple lines. "This is not a legal string." A string may not contain a “ character.  The ‘ character is okay. "This is not a "legal" string either." "This is 'okay' though." This begs the question…

28 Escape sequences A string can represent certain special characters by preceding them with a backslash \ (this is called an escape sequence).  \t tab character  \n newline character  \" quotation mark character Example: System.out.println("Hello!\nHow are \"you\"?"); Output: Hello! How are "you"? This begs another question…

29 Questions What is the output of each of the following println statements? System.out.println("\ta\tb\tc"); System.out.println("\\\\"); System.out.println("'"); System.out.println("\"\"\""); System.out.println("C:\nin\the downward spiral"); Write a println statement to produce the following line of output: / \ // \\ /// \\\

30 Questions What println statements will generate the following output? This program prints a quote from the Gettysburg Address. "Four score and seven years ago, our 'fore fathers' brought forth on this continent a new nation." What println statements will generate the following output? A "quoted" String is 'much' better if you learn the rules of "escape sequences." Also, "" represents an empty String. Don't forget to use \" instead of " ! '' is not the same as "

31 Comments comment: A note written in the source code to make the code easier to understand.  Comments are not executed when your program runs.  Most Java editors show your comments with a special color. Comment, general syntax: /* */ or, // Examples: /* A comment goes here. */ /* It can even span multiple lines. */ // This is a one-line comment.

32 Comments: Where do you go? … at the top of each file (also called a "comment header"), naming the author and explaining what the program does … at the start of every method, describing its behavior … inside methods, to explain complex pieces of code

33 Comments: Why? Comments provide important documentation. Later programs will span hundreds or thousands of lines, split into many classes and methods. Comments provide a simple description of what each class, method, etc. is doing. When multiple programmers work together, comments help one programmer understand the other's code.

34 That thing called style… What is style?  Indentation  Capitalization  Formatting / spacing  Structured code  No redundancy …… Why is it important?