Chapter 2 print / println String Literals Escape Characters Variables / data types.

Slides:



Advertisements
Similar presentations
This is Java Jeopardy.
Advertisements

CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
CMT Programming Software Applications
Lecture 3: Strings, Screen Output, and Debugging Yoni Fridman 7/2/01 7/2/01.
 2003 Prentice Hall, Inc. All rights reserved. Customized by Sana Odeh for the use of this class. 1 Introduction to Computers and Programming in JAVA.
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
1 Character Strings and Variables Character Strings Variables, Initialization, and Assignment Reading for this class: L&L,
String Escape Sequences
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
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: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
2440: 211 Interactive Web Programming Expressions & Operators.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Program Statements Primitive Data Types and Strings.
Java 2 More Java Then Starbucks ;-). Important Terms Primitive Data – Basic, built-in values (characters & numbers) Data Type – Used to talk about values.
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
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
CSC 1051 – Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
CHAPTER 4 GC 101 Data types. DATA TYPES  For all data, assign a name (identifier) and a data type  Data type tells compiler:  How much memory to allocate.
Primitive Data Types. Identifiers What word does it sound like?
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
Chapter 3 Introduction To Java. OBJECTIVES Packages & Libraries Statements Comments Bytecode, compiler, interpreter Outputting print() & println() Formatting.
Chapter 2 Variables.
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.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Chapter 2: Data and Expressions String and String Concatenation Escape Sequences Variables Primitive Date Types Expressions Interactive Programs.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
Strings See Chapter 2 u Review constants u Strings, concatenation and repetition 1.
COMP 110: Spring Announcements Lab 1 due Wednesday at Noon Assignment 1 available on website Online drop date is today.
© 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.
CS 106 Introduction to Computer Science I 09 / 10 / 2007 Instructor: Michael Eckmann.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
CSC 110 – Intro to Computing - Programming
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.
Chapter 3 Introducing Java. Objectives and Goals 1. Define terminology associated with object- oriented programming. 2. Explain why Java is a widely used.
Data and Expressions. Let's explore some other fundamental programming concepts Chapter 2 focuses on: Character Strings Primitive Data The Declaration.
© 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.
C++ First Steps.
Chapter 2 Variables.
Chapter 2 Basic Computation
Console Output, Variables, Literals, and Introduction to Type
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Java Programming: From Problem Analysis to Program Design, 4e
Escape Sequences What if we wanted to print the quote character?
Introduction to Primitive Data types
String Concatenation Objectives
Chapter 2 Create a Chapter 2 Workspace Create a Project called Notes
Escape sequences escape sequence: A special sequence of characters used to represent certain special characters in a string. \t Inserts a tab in the.
Output Manipulation.
Chapter 2 Variables.
Just Enough Java 17-May-19.
Instructor: Alexander Stoytchev
Introduction to Primitive Data types
Presentation transcript:

Chapter 2 print / println String Literals Escape Characters Variables / data types

Identifier Words used when writing a program Class Name Variables Reserved words that java uses: these start with a lower case (page 28 for list) Identifier Rules: –Start with either an _ or a letter. Java prefers letter –Can only contain letters, numbers, _ or $ –Must be one word –Class Names start with a capital letter, variables for primitive data types and objects lower case.

print and println print System.out.print will print the following statement on the same line. System.out.print(“Three…. “); System.out.println(“Four…. “); System.out.println(“Go……”); print: Three…. Four…. println System.out.println will move to a new line to print the next statement. System.out.println(“Three… “); System.out.println(“Four…. “); Print: Three… Four…

String A String is a group of characters (words) –String Literal is a group of characters (words) strung together: –string of characters inside quotation marks. System.out.println(“This is a String Literal”);

Concatenation Join together String concatenation is joining one String to another. (“This is a String “ + “ joined to this one.”); This is a String joined to this one. (You must leave a space so the words will have a space between them.

Open Concatenation program Seven Rules for String concatenation 1.The Strings being added are called operands. 2.Strings are read from left to right by the compiler.

String concatenation 3. If both operands are Strings, the result is a String. Example: (“This is a String “ + “ joined to this one.”); 4. If the first operand is a String and the second or third is a number, all will be considered a string. The numbers will be treated as a String not a number. Example: (“This is a String “ ); Print: This is a String 25

String concatenation 5.If the first operand is a number and the second is a String the first operand will be a number and the second is a String. Numbers only become Strings if they come after a String. Example: ( “ is 2 + 5”); print: 10 is Reverse it: ( “Is “ ); print: Is

String Concatenation 6.If both are numerals it will use the + sign as addition and add Example: System.out.print(2 + 2); print 4 7.If there are parentheses around the numbers, it will perform it first even if it is last. Example: (“Does = “ + (2 + 2)); print: Does = 4

Escape Sequences Page 60 Java has several escape sequences to represent special characters so they can be printed. \n newline ( “First line \n second line”) \” double quote \”Hello\” “Hello” \\ will print backslash \\ \ \t tab (“First column \t Second column”) \’ single quotation \’Hello\’ ‘Hello’

Programs Open the following programs to observe CountDown.java Escape.java Concatenation.java