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,

Slides:



Advertisements
Similar presentations
This is Java Jeopardy.
Advertisements

IT151: Introduction to Programming
© 2007 Lawrenceville Press Slide 1 Chapter 3 Classes and Objects.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
CMT Programming Software Applications
 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.
1 Character Strings and Variables Character Strings Variables, Initialization, and Assignment Reading for this class: L&L,
String Escape Sequences
Copyright 2013 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
Copyright 2008 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading: self-check: #1-14.
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:
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()
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.)
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
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.
Output in Java Hello World!. Structure of a Java Program  All Java files in ICS3U1 have the following structure: class HelloWorld { }  Notice the open.
CSC 1051 – Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
© 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 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.
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.
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.
© 2007 Lawrenceville Press Slide 1 Chapter 3 Classes and Objects 1. How is a class different from an object?
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.
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: 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.
SUMMARY OF CHAPTER 2: JAVA FUNDAMENTS STARTING OUT WITH JAVA: OBJECTS Parts of a Java Program.
Copyright 2010 by Pearson Education APCS Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Chapter 2 Variables.
Chapter 2, Part I Introduction to C Programming
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
CSE 190D, Winter 2013 Building Java Programs Chapter 1
CSC 1051 – Data Structures and Algorithms I
Java Programming: From Problem Analysis to Program Design, 4e
OUTPUT STATEMENTS GC 201.
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
Module 2 - Part 1 Variables, Assignment, and Data Types
Introduction to Java Applications
CSE 142, Spring 2012 Building Java Programs Chapter 1
Output Manipulation.
Chapter 2 Variables.
CSC 1051 – Data Structures and Algorithms I
Instructor: Alexander Stoytchev
Java Programming Presented by Dr. K. SATISH KUMAR,
Introduction to Primitive Data types
Presentation transcript:

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, new line

Identifier Words used when writing a program (Identifiers) 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.

What is the difference between 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…. Go……. 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…. Go……

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: 7 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

// Demonstrates the difference between print and println. //******************************************************************** public class Countdown { // // Prints two lines of output representing a rocket 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."); }

escape characters public class Escape { public static void main(String[]args) { System.out.println("A slash n \n is used to go to a new line\n"); System.out.println("A slash quotation mark \"will\" print a double quote"); System.out.println("double slash \\ will print one backslash."); System.out.println("A slash t \t will tab."); System.out.println("A slash one quotation \'will\' produce single quote."); }