Announcements & Review

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

Written by: Dr. JJ Shepherd
Lecture 19: Reading Input from Files Announcements & Review Lab 6 Due Thursday arrays of objects more flight reservations Last time: static methods vs.
Expressions ► An expression can be a single variable, or can include a series of variables. If an expression includes multiple variables they are combined.
Introduction to Computers and Programming Lecture 7:
COMP 14 Introduction to Programming Mr. Joshua Stough February 2, 2005 Monday/Wednesday 11:00-12:15 Peabody Hall 218.
Introduction to Computers and Programming Strings Professor: Evan Korth New York University.
CS 225 Java Review. Java Applications A java application consists of one or more classes –Each class is in a separate file –Use the main class to start.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Console Input Using the Scanner Class Starting with version 5.0, Java includes a class for doing.
Using Objects CS 101-E Aaron Bloomfield. Announcements Midterm 1 is a week from this Wednesday Midterm 1 is a week from this Wednesday TESTS ARE IN CHM.
1 Using Objects Chapter 3 Fall 2005 CS 101 Aaron Bloomfield.
1 Chapter 2 JAVA FUNDAMENTALS CONT’D. 2 PRIMITIVE DATA TYPES Computer programs operate on data values. Values in Java are classified according to their.
1 Course Lectures Available on line:
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
Java Basics. Java High-level language  More readable for humans  Need to be translated to machine language for execution Compilers  CPU-independent.
1 Using Objects Chapter 2 (part 2 of 2) Spring 2007 CS 101 Aaron Bloomfield.
The basics of the array data structure. Storing information Computer programs (and humans) cannot operate without information. Example: The array data.
Java Arrays …………. Java Arrays …………. * arrays are objects in Java * arrays are objects in Java * an array variable is a reference * an array variable is.
Math class services (functions) Primitive vs reference data types Scanner class Math class services (functions) Primitive vs reference data types Scanner.
COMP String and Console I/O Yi Hong May 18, 2015.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Java basics. Task  Display the supposed forecast I think there is a world market for maybe five computers. Thomas Watson, IBM, 1943.
1 Using Objects Chapter 3 Fall 2006 CS 101 Aaron Bloomfield.
Lecture 7: Whiles - Indefinite Loops Input and while loops Katie Coons CS 305J February 2, 2007.
Introduction to Programming
CMSC 202 Java Console I/O. July 25, Introduction Displaying text to the user and allowing the user to enter text are fundamental operations performed.
1 CSC 201: Computer Programming I Lecture 2 B. S. Afolabi.
Java 1.5 The New Java Mike Orsega Central Carolina CC.
Objects. Getting classy Your current job –Gain experience creating and manipulating objects from the standard Java types Why –Prepares you for defining.
Lecture 8: Bits and Pieces Tami Meredith. Roadmap Today's lecture has a bit of everything. Going back over previous chapters and pulling out little bits.
Week 3 - Friday.  What did we talk about last time?  Operations on boolean values  !, &&, ||  Operations on char values  +, -  Operations on String.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 3.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
1 Using Objects Chapter 3 Spring 2006 CS 101 Aaron Bloomfield.
By Mr. Muhammad Pervez Akhtar
Java – Variables and Constants By: Dan Lunney. Declaring Variables All variables must be declared before they can be used A declaration takes the form:
Written by: Dr. JJ Shepherd
Chapter 2 Console Input and Output Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Java Scanner Class Keyboard Class. User Interaction So far when we created a program there was no human interaction Our programs just simply showed one.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Files A collection of related data treated as a unit. Two types Text
 Data Type is a basic classification which identifies different types of data.  Data Types helps in: › Determining the possible values of a variable.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
Introduction to programming in java Lecture 21 Arrays – Part 1.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
COMP Review of Chapter 1 & 2
Chapter 3 Spring 2005 CS 101 Aaron Bloomfield
Input/Output.
CSC1401 Input and Output (and we’ll do a bit more on class creation)
Objects.
Elementary Programming
Yanal Alahmad Java Workshop Yanal Alahmad
JavaScript, continued.
Lecture Note Set 1 Thursday 12-May-05
Data types, Expressions and assignment, Input from User
Java Programming: From Problem Analysis to Program Design, 4e
AP Java Unit 3 Strings & Arrays.
Computers & Programming Languages
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
Chapter 2: Basic Elements of Java
Java Basics.
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
Chapter 3 Spring 2006 CS 101 Aaron Bloomfield
Announcements & Review
CS Week 2 Jim Williams, PhD.
Math class services (functions)
Objects.
More on iterations using
Presentation transcript:

Announcements & Review Last Time: int, boolean some operations boolean logic if-then-else! Announcements Friday I’m away, Katie Coons will teach Lab 1 Due Thursday 10pm Use turnin 1 file per pair Lecture 6: String Objects and Input

Lecture 6: String Objects and Input Today Clairfy float verses double Finish if-then-else example More basic program elements Objects versus values Strings & their operators Input Using the Scanner class Lecture 6: String Objects and Input

Lecture 6: String Objects and Input Values versus objects Numbers Have values but they do not have behaviors Objects Have attributes and behaviors System.out - References an OutputStream Attribute: monitor Behaviors: printing System.in: References an InputStream Attribute: keyboard Behaviors: reading Java treats object variables differently. Although an object variable is the symbolic name for a memory location being used by the program, the memory location for an object variable does not store a value of that object type. Instead the value in the memory location tells the program where to find a value (object) of that type. We say that an object variable references or points to an object of the object type. Thus, a String variable references a memory location that holds a value of type String. Similarly, a BufferedReader variable references a memory location holding a BufferedReader value. Lecture 6: String Objects and Input

Lecture 6: String Objects and Input Consider String a = "excellence"; String b = a; What is the representation? Lecture 6: String Objects and Input

Lecture 6: String Objects and Input Examples Consider String a = "excellence"; String b = a; What is the representation? a "excellence" b Lecture 6: String Objects and Input

Uninitialized versus null Consider String dayOfWeek; Scanner inStream; What is the representation? Lecture 6: String Objects and Input

Uninitialized versus null Consider String dayOfWeek; Scanner inStream; What is the representation? dayOfWeek - inStream - Lecture 6: String Objects and Input

Uninitialized versus null Consider String fontName = null; Scanner fileStream = null; What is the representation? Lecture 6: String Objects and Input

Uninitialized versus null Consider String fontName = null; Scanner fileStream = null; What is the representation? fontName null fileStream null Lecture 6: String Objects and Input

Lecture 6: String Objects and Input Assignment Consider String word1 = "luminous"; String word2 = "graceful"; -> word1 = word2; Representation at -> word1 "luminous" word2 "graceful" Lecture 6: String Objects and Input

Lecture 6: String Objects and Input Assignment Consider String word1 = "luminous"; String word2 = "graceful"; word1 = word2; -> After assignment word1 word2 "graceful" Lecture 6: String Objects and Input

String representation Consider String alphabet = "abcdefghijklmnopqrstuvwxyz"; Standard shorthand representation Truer representation alphabet "abcdefghijklmnopqrstuvwxyz" Another useful String member method is charAt(). This method expects a single index as its parameter and returns the value of the character at that position in its String. While such behavior seems relatively natural given the method name and its parameter, what is not natural is that in Java, as in several other programming languages, the first character of a String is located at index 0. alphabet a b c d e f g h i j k l m n o p q r s t u v w y z Lecture 6: String Objects and Input

Lecture 6: String Objects and Input Some String Methods // a string objects String alphabet = "abcdefghijklmnopqrstuvwxyz"; // operations on string objects char c1 = alphabet.charAt(9); int position = alphabet.indexOf(“e”); String ab = alphabet.substring(0, 2); String moreLetters = ab.concat(alphabet); boolean sameStr = moreLetters.equals(ab); …. lots more … see pgs 877--882 in Cohoon & Davidson or Javadoc (google it!) Lecture 6: String Objects and Input

Lecture 6: String Objects and Input Example String Method String alphabet = "abcdefghijklmnopqrstuvwxyz"; char c1 = alphabet.charAt(9); char c2 = alphabet.charAt(2); int i1 = alphabet.indexOf(“de”); What are the values of c1, c2, and c3? Why? Lecture 6: String Objects and Input

Lecture 6: String Objects and Input BlueJ Examples Lecture 6: String Objects and Input

Reading Input Features // Scanner is an “extra” Java class, so we // need to tell the compiler where to find it import java.util.* // allocates an object of class Scanner Scanner stdin = new Scanner(System.in); String name = stdin.next(); int age = stdin.nextInt(); double commuteDistance = stdin.nextDouble(); boolean parent = stdin.nextBoolean(); // peeking to make sure the format is right // -- we will use these in Lecture 8 boolean isString = stdin.hasNext(); boolean isInt = stdin.hasNextInt(); boolean isDouble = stdin.hasNextDouble(); boolean isBoolean = stdin.hasNextBoolean(); Lecture 6: String Objects and Input

Lecture 6: String Objects and Input Reading Input Example // Scanner is an “extra” Java class, so we // need to tell the compiler where to find it import java.util.* // allocates an object of class Scanner Scanner stdin = new Scanner(System.in); System.out.print("Enter a word: "); String word = stdin.next(); int wordLength = word.length(); System.out.println("Word " + word + " has length ” + wordLength + "."); Lecture 6: String Objects and Input

Lecture 6: String Objects and Input BlueJ Examples Lecture 6: String Objects and Input

Lecture 6: String Objects and Input More Questions? Lecture 6: String Objects and Input