BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)

Slides:



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

University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner Objects, Methods, Parameters, Input Lecture 5, Thu Jan
Chapter 5 Part 1 COSI 11a Prepared by Ross Shaull.
Chapter Day 5. © 2007 Pearson Addison-Wesley. All rights reserved2-2 Agenda Day 5 Questions from last Class?? Problem set 1 Posted  Introduction on developing.
CS102 Data Types in Java CS 102 Java’s Central Casting.
Chapter 2 storing numbers and creating objects Pages in Horstmann.
References, Aliases, Garbage Collection and Packages Packages and Importing Classes Reading for this Lecture: L&L, Familiarize yourself with.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
COP 3275 COMPUTER PROGRAMMING USING C Instructor: Diego Rivera-Gutierrez
Georgia Institute of Technology Introduction to Java part 2 Barb Ericson Georgia Institute of Technology May 2006.
The preprocessor and the compilation process COP3275 – PROGRAMMING USING C DIEGO J. RIVERA-GUTIERREZ.
1 Spidering the Web in Python CSC 161: The Art of Programming Prof. Henry Kautz 11/23/2009.
An Introduction to Textual Programming
Java Programming, 3e Concepts and Techniques Chapter 2 - Part 2 Creating a Java Application and Applet.
Files COP3275 – PROGRAMMING USING C DIEGO J. RIVERA-GUTIERREZ.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #002 (January 17, 2015)
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
The Scala API Application Programmer’s Interface.
Client Side Programming with JavaScript Why use client side programming? Web sides built on CGI programs can rapidly become overly complicated to maintain,
Lecture 2: Classes and Objects, using Scanner and String.
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 15: More-Advanced Concepts.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
CS 206 Introduction to Computer Science II 09 / 10 / 2009 Instructor: Michael Eckmann.
Comments in Java. When you create a New Project in NetBeans, you'll notice that some text is greyed out, with lots of slashes and asterisks:
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.
CS 106 Introduction to Computer Science I 01 / 31 / 2007 Instructor: Michael Eckmann.
10-Nov-15 Java Object Oriented Programming What is it?
Variables, Primitives, and Objects A Visual Learner’s Guide.
Introduction to Programming Writing Java Beginning Java Programs.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
VARIABLES Programmes work by manipulating data placed in memory. The data can be numbers, text, objects, pointers to other memory areas, and more besides.
Strings and Text File I/O (and Exception Handling) Corresponds with Chapters 8 and 17.
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
Application Programming Interfaces. Java comes with a bunch of classes that are already written. Java comes with a bunch of classes that are already written.
CIS 234: Java Methods Dr. Ralph D. Westfall April, 2010.
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
CRE Programming Club - Class 2 Robert Eckstein and Robert Heard.
BIT116: Scripting Associative Arrays. Today AngularJS Q + A for the exam 2.
1 Class 1 Lecture Topic Concepts, Definitions and Examples.
Review of Previous Classes Declaring Variables - var myVar:DataType = value Data Types – Number, uint, String, Boolean Functions – parameters, return.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
1.1: Objects and Classes msklug.weebly.com. Agenda: Attendance Let’s get started What is Java? Work Time.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Coding – Week 2 Functions, Arrays, and Objects. Functions  Functions are not a new concept – you’ve been using them already.  void setup() {} and void.
Today Javadoc. Packages and static import. Viewing API source code. Upcoming Topics: –protected access modifier –Using the debugger in Eclipse –JUnit testing.
Coming up Implementation vs. Interface The Truth about variables Comparing strings HashMaps.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana Pronounced Bah-bah Co-fee Way-ou-see-jah-nah Call him “Baba” or “Dr. Weusijana”
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana Pronounced Bah-bah Co-fee Way-ou-see-jah-nah Call him “Baba” or “Dr. Weusijana”
Quiz 1 A sample quiz 1 is linked to the grading page on the course web site. Everything up to and including this Friday’s lecture except that conditionals.
3-July-2002cse142-D2-Methods © 2002 University of Washington1 Methods CSE 142, Summer 2002 Computer Programming 1
April 13, 1998CS102-02Lecture 3-1 Data Types in Java CS Lecture 3-1 Java’s Central Casting.
JavaScript Part 1 Introduction to scripting The ‘alert’ function.
JavaScript: Conditionals contd.
Introduction to Java part 2
Introduction to Computer Science / Procedural – 67130
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Cookies BIS1523 – Lecture 23.
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Number and String Operations
Introduction to Java part 2
Introduction to Java part 2
Java Programming Language
Java’s Central Casting
Presentation transcript:

BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)

BIT 115: Introduction To Programming 2 Quiz hington.edu/webq/survey /babaw/ hington.edu/webq/survey /babaw/

BIT 115: Introduction To Programming Today Ch 7.2, , –Numeric Types –Non-Numeric Types –Strings & toString()

BIT 115: Introduction To Programming Next Lecture Wednesday (6/4): –Ch 8.2 (Reference Variables) –A4 and J5 will be due BEFORE CLASS

BIT 115: Introduction To Programming 5 String Objects This class seeks to model stuff that you can write down. Text: Words, usually, but also numbers, punctuation, random symbols This is done with objects of a class called java.lang.String String is basically short for: a string of characters –example: the letter ‘a’ is a character

BIT 115: Introduction To Programming 6 Java API Included with the Java language is a library of classes that seek to model common programming things (like strings) The public classes and methods you can use are called the Java API (Application Programming Interface) –It's got so much stuff, that it tries to group related stuff together. So everything that belongs in the language goes under java.lang –E.g., java.lang.String 6

BIT 115: Introduction To Programming 7 Packages in Java API java.lang is called a package –The java.lang package is automatically available to your programs –Everything else has to be imported To tell the Java compiler what you're going to use You include a package using the import keyword/command – import java.applet.AudioClip; // To use just the "AudioClip" class in the java.applet package – import java.applet.*; // To use anything in the java.applet package 7

BIT 115: Introduction To Programming 8 JavaDocs of Java API Immediate implication: –You'll need to look for documentation under java.lang.String –Use the link to the online HTML JavaDocs called “API/JavaDoc of Java 5 (JDK 1.5)” on the course websiteAPI/JavaDoc of Java 5 (JDK 1.5) –You should be able to get to the doc.zip file version on Sun's java.sun.com site 8

BIT 115: Introduction To Programming 9 String seeks to model an immutable (unchanging) string java.lang.String class contains a number of methods (behaviors) that are common to all strings. Yet each individual String has attributes which are unique to it – most importantly, the characters in it's string. 9

BIT 115: Introduction To Programming 10 2 ways to create an instance of the String class String s = new String("Baba"); I like this way, because it's clear that you're actually creating a new instance (instantiating a new object) of the String class. This does the same thing: String s = "Baba"; Whenever you write a literal like "some text" in your code, at compilation time, the Java compiler changes this to be a reference to a String object that it creates for you So the above two lines are semantically identical 10

BIT 115: Introduction To Programming 11 4 Important Points You can't leave out the semi-colon at the end!! ; is required You have to first list the type ( String ), then the name of the variable (like s ). –Java is strongly typed, meaning that it (mostly) won't convert from, say, a String to an integer. JavaScript is loosely typed, meaning that it will attempt to convert from, say, a String to an integer. Optionally, you can immediately assign a value to the new variable (initialize it) s is a reference variable – it doesn't actually contain the entire string inside it, but instead it is a reference to the object that actually does, that’s why it’s immutable (can’t change) –You can give it new values: s = “Dr.”; 11

BIT 115: Introduction To Programming 12 Calling methods on a String Let's say that you want to see your name, in all caps. –The point of providing an API to a library is that it'll do work for you; you don't have to figure out all the details –It just so happens that the String class can do this for you, using the toUpperCase method –So, we'd like to send a message to the String object referred to by the reference variable s, telling the object to produce an upper-case version of itself: s.toUpperCase(); 12

BIT 115: Introduction To Programming 13 However, Strings are immutable, meaning that they can't change. –Thus, the object that s refers to will be exactly the same after the method call is finished. –Instead of changing the object that s refers to, toUpperCase actually produces a brand-new String object, who's value is a copy of s 's, except that the new String is in all uppercase. –If we don't do anything with it, then we'll lose it. In order to keep track of it, we'll need a reference: String s2; s2 = s.toUpperCase(); System.out.println(s2); 13

BIT 115: Introduction To Programming 14 Vocabulary review We're using a single class ( String ), but we've got 2 instances of the String class (2 objects). We refer to these objects using references – the variables s, and s2. We created s2 by sending a message to s (a.k.a. "calling a method on s "). Even though both objects are of the same class, each object has different attributes – in this case, the characters(letters) that it contains –yes, upper & lower case letters are different You can think of the String class as being a cookie-cutter for individual objects. 14

BIT 115: Introduction To Programming 15 Composing a Message – String s2; – s2 = s.toUpperCase(); – System.out.println(s2); Notice that we never actually use s2 again, so we can avoid using an s2 with: – System.out.println(s.toUpperCase()); This is sometimes called composing a message - the result of the first message ( toUpperCase ) is used as an argument to the second message. Note that there is an implicit order here – you can't print the string until you've first changed it to uppercase, so the toUpperCase happens first. 15

BIT 115: Introduction To Programming 16 Working with user input Strings This will get a String from the user TextInput in = new TextInput(); String input = ""; input = in.readLine(); Then you can compare it to other Strings if(input.equals(s)) {// do something} if(input.equalsIgnoreCase(“jim”)) {// do something} DON’T use == or != 16

BIT 115: Introduction To Programming 17 ICE 17 17