End of the beginning Let’s wrap up some details and be sure we are all on the same page Good way to make friends and be popular.

Slides:



Advertisements
Similar presentations
© 2007 Lawrenceville Press Slide 1 Assignment Statement An assignment statement gives a value to a variable. Assignment can take several forms: x = 5;
Advertisements

Chapter 3 Syntax, Errors, and Debugging
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
CS16 Week 2 Part 2 Kyle Dewey. Overview Type coercion and casting More on assignment Pre/post increment/decrement scanf Constants Math library Errors.
Introduction to Programming with Java, for Beginners Primitive Types Expressions Statements Variables Strings.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
JavaScript, Fourth Edition
JavaScript, Third Edition
String Escape Sequences
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Chapter 2 Primitive Data Types and Operations F Introduce Programming with an Example  The MyInput class F Identifiers, Variables, and Constants F Primitive.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
© 2006 Pearson Education 1 Obj: cont 1.3 and 1.4, to become familiar with identifiers and to understand how programming languages work HW: p.51 #1.8 –
Input, Output, and Processing
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Java Programming: From Problem Analysis to Program Design, 5e Chapter 2 Basic Elements of Java.
CompSci 100E 2.1 Java Basics - Expressions  Literals  A literal is a constant value also called a self-defining term  Possibilities: o Object: null,
SE-1010 Dr. Mark L. Hornick 1 Variables & Datatypes.
The College of Saint Rose CIS 433 – Programming Languages David Goldschmidt, Ph.D. from Concepts of Programming Languages, 9th edition by Robert W. Sebesta,
CPS 506 Comparative Programming Languages Syntax Specification.
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 3 Syntax, Errors, and Debugging Fundamentals of Java.
Data Types Declarations Expressions Data storage C++ Basics.
Chapter 2 Variables.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Debugging, Escape Command, More Math. It’s your birthday!  Write a program that asks the user for their name and their age.  Figure out what their birth.
By Mr. Muhammad Pervez Akhtar
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
Announcements You will receive your scores back for Assignment 2 this week. You will have an opportunity to correct your code and resubmit it for partial.
Python Basics  Values, Types, Variables, Expressions  Assignments  I/O  Control Structures.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Variables and Constants Chapter 4 Review. Declaring Variables A variable is a name for a value stored in memory. Variables and constants are used in programs.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
Windows Programming Lecture 03. Pointers and Arrays.
1 Sections 3.1 – 3.2a Basic Syntax and Semantics Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Java Programming: Guided Learning with Early Objects Chapter 1 Basic Elements of Java.
Chapter 4 Assignment Statement
Chapter 3 Syntax, Errors, and Debugging
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
2.5 Another Java Application: Adding Integers
Multiple variables can be created in one declaration
Java Programming: From Problem Analysis to Program Design, 4e
Building Java Programs Chapter 2
Introduction to C++ Programming
Chapter 2: Basic Elements of Java
Lecture3.
Data Types and Expressions
Chapter 2 Primitive Data Types and Operations
Instructor: Alexander Stoytchev
Problem 1 Given n, calculate 2n
Presentation transcript:

End of the beginning Let’s wrap up some details and be sure we are all on the same page Good way to make friends and be popular.

Programming and natural languages share three elements. Vocabulary: Words and symbols Syntax: Rules for combining statements Think: grammar Semantics: Rules for interpreting well-formed statements Think: meaning Order of precedence Think: PEMDAS on steroids Resolve ambiguity: “Jack jumped and Sally laughed or Jill skipped” ((Jack jumped and Sally laughed) or Jill skipped) (Jack jumped and (Sally laughed or Jill skipped))

Vocabulary (AKA Lexicon) Also: for, if, while, do, et cetera.

Reserved words

Syntax Mechanical rules that define which sentences are well-formed (i.e., acceptable.) For example, the rule for building sentences with ‘+’ is roughly: – If int is a well-formed expression that evaluates to an integer, double is a well-formed expression that evaluates to a double, and string is a well-formed expression that evaluates to a string, then: – int + int is well-formed – double + double is well-formed – string + string is well-formed Note: we still don’t know what these expressions mean, we just know whether they’re syntactically correct (i.e., well-formed) ‘Colorless green ideas sleep furiously’ is grammatically (i.e., syntactically) correct English, but it’s still gibberish

Or is it? By the way, I didn’t make this example up; a linguist named Noam Chomsky did. Also, someone else made this beautiful art someone else

The compiler complains if you write syntactically incorrect code

All wrong in different ways

Semantics Say what well-formed sentences mean Int + Int means add the two integers. So, 5+3 evaluates to 8. String + String means concatenate the two strings. So, “abc” + “def” evaluates to “abcdef” When your program runs, the actual commands that are executed depend on semantics.

Some operators (and precedence)

Casting The casting operator is a unary operator, like the negative sign. (Addition, multiplication, division, etc. are binary operators) Changes the type E.g., (double) 4 (int) “4” ??? – Integer.parseInt(“4”);

Mixed-mode arithmetic = ?7? 7.0? 3 / 2.0 = ?1? 1.5? Very common source of bugs Might lead to division by zero, or other such catastrophe

Data types Primitive Defined by a class (instantiated as an object) Syntax for data types: Primitive: combined using operator (+, -, etc) e.g., 3+4 Objects: send messages. (Exception: Strings) e.g., Integer four = new Integer(); four.add(3);

Literals: express value – primitive data types and Strings Variables – Must be declared (can be declared and initialized at same time) Int age Instantiation (objects) – new ( ) Constants – Final = ;

Strings Literals Assigned to variables Concatenated using assignment operator Have methods – The Length =.length(); Send messages **some special characters: \ For example: \”, \’, \\ ‘\’ is called the “escape character” \n this is for new line \t this is for tab

Programming errors Syntax (we just saw a few. Doesn’t compile) Run-time (compiles, but fails when you try to run. E.g., bad input, running off the end of an array. – More syntax errors= fewer runtime errors. One idea behind “strongly typed” languages, like Java Logic (Compiles, but doesn’t do what you think it does. Like, if you calculated Nautical miles wrong) Source: XKCD (web comic)