Words. Characters and Strings Character –A single character inside of single quotes char letter = 'A' ; char digit = '0' ; – Strings Zero or more character.

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

Code Elements and Processing Coordinate System. Code elements: pages Comments: are documentation notes that are ignored by the computer but are.
Variables and Operators
Text David Meredith Aalborg University.
Chapter 2: Using Objects Part 1. To learn about variables To understand the concepts of classes and objects To be able to call methods To learn about.
IAT 334 Lab 2 Computer Graphics: Rocket, PImage. June 4, 2010IAT 3342 Outline  Programming concepts –Programming Computer Graphics –Transformations –Methods.
Introduction to Programming with Java, for Beginners Primitive Types Expressions Statements Variables Strings.
Shlomo Hershkop1 Introduction to java Class 1 Fall 2003 Shlomo Hershkop.
IAT 800 Lab 1: Loops, Animation, and Simple User Interaction.
1 Data types, operations, and expressions Overview l Format of a Java Application l Primitive Data Types l Variable Declaration l Arithmetic Operations.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Lecture 3 IAT 800. Sept 15, Fall 2006IAT 8002 Suggestions on learning to program  Spend a lot of time fiddling around with code –Programming is something.
Review Blocks of code {.. A bunch of ‘statements’; } Structured programming Learning Processing: Slides by Don Smith 1.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
1 k Jarek Rossignac,  2008 Processing  Install Processing  Learn how to edit, run, save, export, post programs  Understand.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Java Data Types. Primitive Data Types Java has 8 primitive data types: – char: used to store a single character eg. G – boolean: used to store true or.
The Java Programming Language
Keyboard and Events. What about the keyboard? Keyboard inputs can be used in many ways---not just for text The boolean variable keyPressed is true if.
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
Chapter 2: Java Fundamentals
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
Chapter 2 Using Objects. Types A type defines a set of values and the operations that can be carried out on the values Examples: 13 has type int "Hello,
 Character set is a set of valid characters that a language can recognise.  A character represents any letter, digit or any other sign  Java uses the.
B. RAMAMURTHY Simulating Motion and Implementing Animation.
Assignment An assignment statement changes the value of a variable The assignment operator is the = sign total = 55; Copyright © 2012 Pearson Education,
Review Spatial Filters – Smooth – Blur – Low Pass Filter – Sharpen – High Pass Filter – Edge detection – Erosion – Dilation Other Pixel Filters – Thresholding.
CIS 3.5 Lecture 2.2 More programming with "Processing"
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Lesson Two: Everything You Need to Know
Variables Art &Technology, 3rd Semester Aalborg University Programming David Meredith
Objects. The Heart of the Matter - The "Black Box" Object-oriented software is all about objects. An object is a "black box" which receives and sends.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Computer Science I Recap: variables & functions. Images. Pseudo-random processing.
Aside: Running Supplied *.java Programs Just double clicking on a *.java file may not be too useful! 1.In Eclipse, create a project for this program or.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
 CSC111 Quick Revision. Problem Write a java code that read a string, then show a list of options to the user to select from them, where:  L to print.
Review Expressions and operators Iteration – while-loop – for-loop.
Test Review. General Info. All tests will be comprehensive. You will be tested more on your understanding of code as opposed to your ability to write.
1 SIC / CoC / Georgia Tech MAGIC Lab Rossignac Processing  Install Processing  Learn how to edit, run, save, export,
IAT 265 Images in Processing PImage. Jun 27, 2014IAT 2652 Outline  Programming concepts –Classes –PImage –PFont.
A data type in a programming language is a set of data with values having predefined characteristics.data The language usually specifies:  the range.
Review Random numbers mouseX, mouseY setup() & draw() frameRate(), loop(), noLoop() Mouse and Keyboard interaction Arcs, curves, bézier curves, custom.
IAT 800 Lecture 8 PImage and PFont. Oct 13, Fall 2009IAT 8002 Outline  Programming concepts –PImage –PFont.
What is Binary Code? Computers use a special code of their own to express the digital information they process. It's called the binary code because it.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
Variables. Something to mention… void setup(){ size(200, 200); background(255); smooth(); } void draw() { stroke(0); strokeWeight(abs(mouseX-pmouseX));
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Topics introduced today (these topics would be covered in more detail in later classes) – Primitive Data types Variables Methods “for” loop “if-else” statement.
Some of Chap 17.
Chapter 2 Basic Computation
IAT 265 PImage and PFont.
Java Variables and Types
Computer Science 3 Hobart College
Lesson Two: Everything You Need to Know
Introduction to Programming in Java
IDENTIFIERS CSC 111.
Computers & Programming Languages
Introduction to Java Programming
More programming with "Processing"
Recap Week 2 and 3.
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
In this class, we will cover:
Presentation transcript:

Words

Characters and Strings Character –A single character inside of single quotes char letter = 'A' ; char digit = '0' ; – Strings Zero or more character in double quotes String word = "hello" ; String robot = "r2d2" ; String nothing = "" ;

Why not string ? String is a class –Classes define data types –Names of classes start with capital letters A convention, not a rule Primitive types –Simplest data types of Java – int, boolean, char, double –Names start with small letters

Odd things to do println('A' + 5) ; println("A" + 5) ; String s = "" ; for (char c = '0'; c < 'Z'; c++) { s = s + c ; } println(s) ;

'5' vs 5 vs "5" '5' is a character encoded as a number –But given from the ASCII standardASCII –That is, '5' is 35 (in Hexadecimal) 5 is the numbers of fingers on one hand "5" is a String –With the single character '5'

'v' vs v 'v' is a character –You cannot do the following 'v' = 30 ; v is a variable name –If appropriately declared int v ; –You can v = 30 ;

Conversion methods boolean –Converts zero to false –Converts non-zero to true byte char int float str –Converts to String

Conversion example println(boolean(5)) ; println(float(5)) ; println(str(5)) ; println(int(5.7)) ; println(str(5.7)) ; println(int('5')) ; println(int('#')) ;

UnicodeUnicode and cut-and-paste char rquote = '‘' ; char lquote = '’' ; char singleQuote = '\''; String dquotes = "“”" ; char oe = 'œ' ; println(int(rquote)) ; println(int(oe)) ;

class and method In object-oriented programming –Classes have methods ≈ functions The operations for that data type –Retrieve information from objects –Modify objects –Methods (and fields) use “dot” operator obj.method(arg1, arg2) –≈ method(obj, arg1, arg2)

Useful methods for s, a String s.length() –Number of characters of s s.charAt(5) –5 th character of s (“first” is 0 th ) s.substring(2, 3) –Characters 2 to 4 of s And many more

Printing on the screen Create a font in Processing environment – Tools » Create Font…. Load font in Processing code – Pfont font = loadFont("……") ; Set font – textFont(font, size) ; Write with font – text("……", x, y) ;

Displaying Text // Step 1: Create the font using the Tool menu option // Step 2: Declare PFont variable PFont f; void setup() { size(200,200); // Step 3: Load Font f = loadFont("Albany-48.vlw“, 40); background(255); textFont(f, 16); // Step 4: Specify font fill(0); // Step 5: Specify font color // Step 6: Display Text text("Mmmmm... Strings...", 10, 100); }

You try it! // Step 1: Create the font using the Tool menu option // Step 2: Declare PFont variable PFont f; void setup() { size(200, 200); // Step 3: Load Font f = loadFont( “you fill this in" ); background(255); textFont(f, “you fill this in”); // Step 4: Specify font fill(0); // Step 5: Specify font color // Step 6: Display Text String message = “you fill this in" ; text (message, 10, 100); }

Useful text functions textWidth("……") –Returns width in pixels of string when printed textAlign(LEFT) textAlign(RIGHT) textAlign(CENTER) –Aligns a text string textSize( n ) –Sets size of font

Try It Again PFont f; void setup() { size(200,200); f = loadFont("Arial-BoldMT-40.vlw"); textFont(f); fill(200); } void draw() { background(255); if(mousePressed && mouseButton == LEFT) { textAlign(LEFT); text ("LEFT", 5, height/2, width, height); } else if(mousePressed && mouseButton == RIGHT) { textAlign(RIGHT); text ("RIGHT", 5, height/2, width, height); }

Lab Load an image of a dog and font into your project Write a Processing program to display the dog along with its name If you have time, animate your dog