Week 21 Introduction to Programming Ms. Knudtzon C Period Lecture 3.

Slides:



Advertisements
Similar presentations
Chapter 1: Computer Systems
Advertisements

Programming with Java. Problem Solving The purpose of writing a program is to solve a problem The general steps in problem solving are: –Understand the.
Written by: Dr. JJ Shepherd
1 Java Programming Basics SE-1011 Dr. Mark L. Hornick.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Outline Java program structure Basic program elements
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:
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Java: Chapter 1 Computer Systems Computer Programming II Aug
3.1 Documentation & Java Language Elements Purpose of documentation Assist the programmer with developing the program Assist other programers who.
Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R# address: Group Addresses Post message:
University of Limerick1 Work with API’s. University of Limerick2 Learning OO programming u Learning a programming language can be broadly split into two.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Java: Chapter 1 Computer Systems Computer Programming II.
Java Language and SW Dev’t
System development with Java Lecture 2. Rina Errors A program can have three types of errors: Syntax and semantic errors – called.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
CSC204 – Programming I Lecture 4 August 28, 2002.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
C Derived Languages C is the base upon which many build C++ conventions also influence others *SmallTalk is where most OOP comes Java and Javascript have.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Chapter 1 Object Orientation: Objects and Classes.
Chapter 2: Java Fundamentals
Java The Java programming language was created by Sun Microsystems, Inc. It was introduced in 1995 and it's popularity has grown quickly since A programming.
SE-1010 Dr. Mark L. Hornick 1 Variables & Datatypes.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Copyright Curt Hill Variables What are they? Why do we need them?
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Written by: Dr. JJ Shepherd
1.1: Objects and Classes msklug.weebly.com. Agenda: Attendance Let’s get started What is Java? Work Time.
Week51 APCS-A: Java Assignments & Syntax October 3, 2005.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Chapter 1 Object Orientation: Objects and Classes.
Introduction to Java Programming by Laurie Murphy Revised 09/08/2016.
Copyright 2010 by Pearson Education APCS Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
Eastside Robotics Alliance / Newport Robotics Group 1 T/Th, 6:30 – 8:30 PM Big Picture School Day 3 · 10/9/2014.
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
JAVA MULTIPLE CHOICE QUESTION.
Working with Java.
Content Programming Overview The JVM A brief look at Structure
Lecture 2: Data Types, Variables, Operators, and Expressions
CSE 190D, Winter 2013 Building Java Programs Chapter 1
CS180 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
University of Central Florida COP 3330 Object Oriented Programming
Chapter 3 Assignment Statement
Starting JavaProgramming
null, true, and false are also reserved.
Introduction to Java Programming
CS-0401 INTERMEDIATE PROGRAMMING USING JAVA
An overview of Java, Data types and variables
Instructor: Alexander Stoytchev
Chapter 1: Computer Systems
Units with – James tedder
Units with – James tedder
JavaScript Reserved Words
Instructor: Alexander Stoytchev
Focus of the Course Object-Oriented Software Development
Module 2 - Part 1 Variables, Assignment, and Data Types
CSE 142, Spring 2012 Building Java Programs Chapter 1
Instructor: Alexander Stoytchev
Zorah Fung University of Washington, Spring 2015
Chap 2. Identifiers, Keywords, and Types
CSE 142, Winter 2014 Building Java Programs Chapter 1
Agenda Types and identifiers Practice Assignment Keywords in Java
CS 1054: Lecture 2, Chapter 1 Objects and Classes.
Zorah Fung University of Washington, Winter 2016
Presentation transcript:

Week 21 Introduction to Programming Ms. Knudtzon C Period Lecture 3

Week 22 Notes and Questions Pixar talk at UMD on September 30, 3:00 pm –Any interest in going? Note from syllabus: Quiz on Friday AP Java Docs – subset of Java API – Any questions on reading –Chapter 1, Deitel and Deitel

Week 23 What do these words mean in OO programming? Classes Objects/Instances Methods Statements Let’s explore…

Week 24 OO Programming as Modeling The parts of the model are objects in the problem domain What are the properties of objects? –Objects can be organized into categories –Objects do things –Objects know things

Week 25 Classes A class describes (abstractly) a category of objects –Think of a class as a blueprint for an object – it describes the boundaries of what an object can know or can do How would we model/program a dog?

Week 26 Programming a Dog How would you describe a dog? Would a dog be a class or an object? –Dogs in general –A bulldog named Bully Image from: custfab_main.html Image from: gundogs/golden.htm

Week 27 public class Dog{ // This is a comment, used to describe code } Creating a Dog class in Java So everyone can access it Tell java that this is a class Name the class Curly brace starts the class This indicates the start of a one-line comment Curly brace to end the class CODE GOES HERE

Week 28 Object/Instance A specific description, an instance of a class –A specific dog that we are modeling An object knows things and does things –In D&D book, called attributes and behaviors Things an object knows are variables –Data that is unique for an object of a given type Things an object does are methods Notice that the variables and methods are defined as part of the class –Variable values are set only for a specific instance

Week 29 Dog Class public class Dog{ String breed; //this is a variable String name; int size; // in pounds void bark(); }

Week 210 My Dog Instance Breed: Bulldog Name: Bully Size: 24 Color: Purple This dog can bark (invoke the method)

Week 211 What’s a Method? Things an object does void bark() { System.out.println(“Ruff! Ruff”); } The method doesn’t return anything The name of the method The empty parenthesis means there are no parameters in the method Brackets again! This is a statement; this tells the computer what you want to do in this method

Week 212 What can methods do? When we experimented with JavaEyes, we altered the code to change the program’s behavior –But we had to recompile each time Methods allow you to change what an object does or knows without recompiling

Week 213 What if you want to teach your dog to bark differently? Make the dog say “Grrruffff”, “Bow-wow”, or “Ruff Ruff” –Could change the Dog program each time and recompile like we did Friday –Or we could have the method take a parameter (a String of the sound we want the Dog to make)

Week 214 What’s a Statement? A line of code that gives a specific instruction Must end with a semicolon int x; /* a declaration is a type of statement */ x = 5; // an assignment statement System.out.println(“Ruff! Ruff”); /* a print statement */

Week 215 Your Turn to Explain… What’s a class? What’s an object? What’s an instance? What’s a method?

Week 216 For tomorrow Homework Worksheet Lab Day Also, individual discussion of goals for course with me

Week 217 Lab Day: Tuesday Sep 14 Picture and Shapes BlueJ Lab

Week 218 Introduction to Programming: Ms. Knudtzon C Period Thursday Sep 16 - Lecture 4

Week 219 Shapes Lab and Car Homework Any questions about shapes and picture lab? Any questions about Homework?

Week 220 Car Homework Discussion of what I saw in this assignment Good job exploring language –Students working ahead and teaching themselves things we haven’t even discussed yet.

Week 221 Programming Mistakes What happens if you forget a semi-colon? Forget parenthesis? Forget opening or closing brackets? Don’t use the “right” capitalization? Programming languages are very picky! –Why do you think that is?

Week 222 Understanding an Object’s State Look at variables (and their values) in BlueJ Look at the Inspect function in the object popup menu –Show the object’s data types and their values (aka the state of the object of the object’s variables) –What happened in to the state of the object when you call circle  moveLeft ? –What happens when you set a variable in a method?

Week 223 Elements of a method Signature of the method –public void changeColor(String newColor) –Public/private/protected is optional –The return type –The name of the method Good programming practice: Make it descriptive –Parameter declarations (if any) Body Comment –Good Programming Practice: Place comments before methods that describe what the method does

Week 224 Methods Two special kinds of methods Accessor methods get the value of a variable –getName() Mutatormethods change or set the value of a variable –setName (String newName) –changeName(String newName)

Week 225 Variables Variables need a data type and a name. Think of a variable as a cup. A container. It holds something. –The type tells Java the size of the container. –The name is so you know which container is yours. –(Maybe at a party you have a big red cup of soda – if you put your name on it, you can find it if you put it down)

Week 226 Primitive Data Types What is an int ? (Think back to math…) What might other data types be? –What other kinds of information might an object need to know? True or False values ( boolean ) Decimal numbers ( double ) Character ( char ) A variable's data type determines the values that the variable can contain and the operations that can be performed on it Primitive Data Types are built-in data types (8 of them) – boolean, char, byte, short, int, long, float, double

Week 227 Pre-Defined Data Types Pre-defined data types are just objects that Java has provided you that store information What is a String ? –Stores a section of text –Always in double quotes (what happens if you forget those?) Java has several other data structures to store data in useful ways –We will be learning many of them this semester and next

Week 228 Naming Practices in Programming Class names start with a capital letter Method names don’t, but use capital letters for subsequent words –Like changeMyOil Instance variables start with a lower-case letter Constant variables (that’s an oxymoron…) –In ALL_CAPS, like MAX_INT_SIZE

Week 229 Variable Names Can be almost anything But not Java reserved words… –abstract do if package synchronized boolean double implements private this break else import protected throw byte extends instanceof public throws case false int return transient catch final interface short true char finally long static try class float native strictfp void const for new super volatile continue goto null switch while default Luckily, BlueJ colors these words a different color so you will know there is something special about them before you know what they all mean