Chapter 2 Create a Chapter 2 Workspace Create a Project called Notes

Slides:



Advertisements
Similar presentations
Basic Syntax: Data & Expressions
Advertisements

Lecture 3: Strings, Screen Output, and Debugging Yoni Fridman 7/2/01 7/2/01.
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.
Lab session 3 and 4 Topics to be covered Escape sequences Escape sequences Variables /identifiers Variables /identifiers Constants Constants assignment.
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.
1 Character Strings and Variables Character Strings Variables, Initialization, and Assignment Reading for this class: L&L,
String Escape Sequences
© 2004 Pearson Addison-Wesley. All rights reserved1-1 Intermediate Java Programming Lory Al Moakar.
2.2 Information on Program Appearance and Printing.
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.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
The string data type String. String (in general) A string is a sequence of characters enclosed between the double quotes "..." Example: Each character.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
CSC 1051 – Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
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.
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,
Chapter 2: Java Fundamentals
CSC 1051 – Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Can we talk?. In Hello World we already saw how to do Standard Output. You simply use the command line System.out.println(“text”); There are different.
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
Getting Started.
Chapter 3 Introduction To Java. OBJECTIVES Packages & Libraries Statements Comments Bytecode, compiler, interpreter Outputting print() & println() Formatting.
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.
Chapter 2 Data and Expressions Java Software Solutions Foundations of Program Design 1.
Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,
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.
Data and Expressions Let's explore some other fundamental programming concepts Chapter 2 focuses on: –character strings –primitive data –the declaration.
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.
CSCI 1100/1202 January 14, Abstraction An abstraction hides (or ignores) the right details at the right time An object is abstract in that we don't.
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.
17-Mar-16 Characters and Strings. 2 Characters In Java, a char is a primitive type that can hold one single character A character can be: A letter or.
© 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
Introduction to Java Programming
Web Programming Chapter 1 : Introduction to Java Programming
Intermediate Java Programming
Chapter 2 Data and Expressions
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
CSC 1051 – Data Structures and Algorithms I
Multiple variables can be created in one declaration
Chapter 2 Data and Expressions
Escape Sequences What if we wanted to print the quote character?
Data and Expressions Part One
Introduction to Primitive Data types
Escape sequences escape sequence: A special sequence of characters used to represent certain special characters in a string. \t Inserts a tab in the.
Module 2 - Part 1 Variables, Assignment, and Data Types
Module 2 Variables, Assignment, and Data Types
Module 2 - Part 1 Variables, Assignment, and Data Types
Review of Previous Lesson
CSC 1051 – Data Structures and Algorithms I
Module 2 - Part 1 Variables, Assignment, and Data Types
Instructor: Alexander Stoytchev
Java Programming Presented by Dr. K. SATISH KUMAR,
© A+ Computer Science - Basic Java © A+ Computer Science -
Introduction to Primitive Data types
Module 2 - Part 1 Variables, Assignment, and Data Types
Presentation transcript:

Chapter 2 Create a Chapter 2 Workspace Create a Project called Notes Use your Purple Paper!

What did we do in our programs from Chapter 1? System.out.println ( “ “); Lets try System.out.print The print method is similar to the println method, except that it does not advance to the next line Therefore anything printed after a print statement will appear on the same line

// Countdown.java // // Demonstrates the difference between print and println. public class Countdown { public static void main (String[] args) { System.out.print ("Three... "); System.out.print ("Two... "); System.out.print ("One... "); System.out.print ("Zero... "); System.out.println ("Liftoff!"); // appears on first output line System.out.println ("Houston, we have a problem."); } What is the output for this program?

Output… Three…Two…One…Zero…Liftoff! Houston, we have a problem.

2.2 – Character Strings A string literal is always placed inside double quotation marks. The string concatenation operator (+) is used to join one string to the end of another It can also be used to place a number in a string

System.out.println (“A dozen is equal to 12");

What’s the different between these two? System.out.println (“A dozen is equal to “ + 10 + 2); System.out.println ("A dozen is equal to “ + (10 + 2)); The first line is concatenated. The second line is added.

2.2 - Escape Sequences What if we wanted to print a double quote character? System.out.println (“She said “hello” to me.”); That line would confuse the compiler because it would interpret the second quote as the end of the string We need to use an escape sequence. An escape sequence begins with a backslash character (\), which indicates that the character(s) that follow should be treated in a special way

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

public static void main (String[] args) { public class Roses { public static void main (String[] args) { System.out.println ("Roses are red,\n\tViolets are blue,\n" + "Sugar is sweet,\n\tBut I have \"commitment issues\",\n\t" + "So I'd rather just be friends\n\tAt this point in our " + "relationship."); } What is the output?

Now you try… Create a file called EscapeSequences in the Notes Project.

Assignment Textbook Assignment M.C. (1, 3) T/F (1 – 3) S.A. (2 – 5)