CSCI 1100/1202 January 14, 2002. Abstraction An abstraction hides (or ignores) the right details at the right time An object is abstract in that we don't.

Slides:



Advertisements
Similar presentations
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Advertisements

©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
ECE122 L2: Program Development February 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 2 Program Development.
The Class String. String Constants and Variables  There is no primitive type for strings in Java.  There is a class called String that can be used to.
Characters and Strings. Characters In Java, a char is a primitive type that can hold one single character A character can be: –A letter or digit –A punctuation.
JavaScript, Third Edition
CSci 142 Data and Expressions. 2  Topics  Strings  Primitive data types  Using variables and constants  Expressions and operator precedence  Data.
1 Character Strings and Variables Character Strings Variables, Initialization, and Assignment Reading for this class: L&L,
String Escape Sequences
Chapter 2: Objects and Primitive Data Copyright 2002, Matthew Evett. These slides are based on slides copyrighted by John Lewis and William Loftus, 2002.
1 Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class:
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
Chapter 2 Data and Expressions. © 2004 Pearson Addison-Wesley. All rights reserved2-2 Data and Expressions Let's explore some other fundamental programming.
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
The string data type String. String (in general) A string is a sequence of characters enclosed between the double quotes "..." Example: Each character.
Outline Questions / Review Predefined Objects Variables Primitive Data Arithmetic Expressions Interactive Programs Decision Making Assignments.
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
Program Statements Primitive Data Types and Strings.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-WesleyCopyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Input, Output, and Processing
1 The String Class Every character string is an object in Java, defined by the String class Every string literal, delimited by double quotation marks,
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
CSC 1051 – Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 2: Objects and Primitive Data Presentation slides for Java Software Solutions for AP* Computer.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
Chapter 2 Data and Expressions Part One. © 2004 Pearson Addison-Wesley. All rights reserved2-2/29 Data and Expressions Let's explore some other fundamental.
Chapter 2 topics Concept # on Java Subset Required for AP Exam print and println10. Testing of output is restricted to System.out.print and System.out.println.
1 Lecture 2 b declaration and use of variables b expressions and operator precedence b introduction to objects b class libraries b flow of control b decision-making.
Chapter 2: Data and Expressions String and String Concatenation Escape Sequences Variables Primitive Date Types Expressions Interactive Programs.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
Chapter 2 print / println String Literals Escape Characters Variables / data types.
© 2007 Pearson Addison-Wesley. All rights reserved2-1 Character Strings A string of characters can be represented as a string literal by putting double.
1 Data and Expressions Chapter 2 In PowerPoint, click on the speaker icon then the “play” button to hear audio narration.
Chapter 2 1.What is the difference between print / println 2.What are String Literals 3.What are the Escape Characters for backslash, double quotataions,
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.
Chapter 2: Objects and Primitive Data Lian Yu Department of Computer Science and Engineering Arizona State University Tempe, AZ
Data and Expressions. Let's explore some other fundamental programming concepts Chapter 2 focuses on: Character Strings Primitive Data The Declaration.
Mr. Crone.  Use print() to print to the terminal window  print() is equivalent to println() in Java Example) print(“Hello1”) print(“Hello2”) # Prints:
© 2006 Pearson Education Chapter 2: Objects and Primitive Data Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition by.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Object Oriented Programming Idea Computer program may be seen as comprising a collection of objects Object Fundamental entity in a JAVA program Used to.
Lecture 4 – Scanner & Style
Topics Designing a Program Input, Processing, and Output
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Objects and Classes A class An object (the concept) (the realization)
CSC 1051 – Data Structures and Algorithms I
Section 3.2c Strings and Method Signatures
Escape Sequences What if we wanted to print the quote character?
Data and Expressions Part One
Introduction to C++ Programming
Escape Sequences Some Java escape sequences: See Roses.java (page 68)
Objects and Primitive Data
“If you can’t write it down in English, you can’t code it.”
String Concatenation Objectives
Chapter 2 Create a Chapter 2 Workspace Create a Project called Notes
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Chapter 2: Objects and Primitive Data
CSC 1051 – Data Structures and Algorithms I
Instructor: Alexander Stoytchev
Chapter 2: Objects and Primitive Data
Presentation transcript:

CSCI 1100/1202 January 14, 2002

Abstraction An abstraction hides (or ignores) the right details at the right time An object is abstract in that we don't really have to think about its internal details in order to use it We don't have to know how the println method works in order to invoke it We can write complex software by organizing it carefully into classes and objects

The String Class Every character string is an object in Java, defined by the String class Every string literal, delimited by double quotation marks (“string”), represents a String object The string concatenation operator (+) is used to append one string to the end of another It can also be used to append a number to a string A string literal cannot be broken across two lines in a program See Facts.java (page 56)Facts.java

Plus Operator (+) Also used for arithmetic addition The function that the + operator performs depends on the type of the information on which it operates If both operands are strings, or if one is a string and one is a number, it performs string concatenation If both operands are numeric, it adds them The + operator is evaluated left to right Parentheses can be used to force the operation order See Addition.java (page 58)Addition.java

What will it print? System.out.print( ): –“hello” + “world” – “dogs +” “cats” –“dogs = “ “\ncats = “ + ( ) –“ ” + “dogs\n” + “ “ cats” What if we want: “79 dogs + 79 cats”?

Escape Sequences What if we wanted to print a double quote character? The following line would confuse the compiler because it would interpret the second quote as the end of the string: System.out.println ("I said "Hello" to you."); An escape sequence is a series of characters that represents a special character An escape sequence begins with a backslash character ( \ ), which indicates that the character(s) that follow should be treated in a special way System.out.println ("I said \"Hello\" to you.");

Escape Sequences Some Java escape sequences: See Roses.java (page 59)Roses.java Escape Sequence \b \t \n \r \" \' \\ Meaning backspace tab newline carriage return double quote single quote backslash

Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than once. To simplify steps in a piece of code. To help prevent code duplication. Once assigned a value, the variable name can be used in any expression. When evaluated, the current value of the variable is substituted for that variable name.