C Derived Languages C is the base upon which many build C++ conventions also influence others *SmallTalk is where most OOP comes Java and Javascript have.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Chapter 1: Computer Systems
Programming with Java. Problem Solving The purpose of writing a program is to solve a problem The general steps in problem solving are: –Understand the.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
The Java Programming Language
Outline Java program structure Basic program elements
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
JavaScript, Fourth Edition
JavaScript, Third Edition
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R# address: Group Addresses Post message:
COMPUTER PROGRAMMING. Data Types “Hello world” program Does it do a useful work? Writing several lines of code. Compiling the program. Executing the program.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Java: Chapter 1 Computer Systems Computer Programming II.
Java Language and SW Dev’t
General Features of Java Programming Language Variables and Data Types Operators Expressions Control Flow Statements.
2440: 211 Interactive Web Programming Expressions & Operators.
Tutorial 2 Variables and Objects. Working with Variables and Objects Variables (or identifiers) –Values stored in computer memory locations –Value can.
System development with Java Lecture 2. Rina Errors A program can have three types of errors: Syntax and semantic errors – called.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
CSC204 – Programming I Lecture 4 August 28, 2002.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
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.
Chapter 2: Java Fundamentals
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (there is an audio component to this eLesson) © Dr.
Java The Java programming language was created by Sun Microsystems, Inc. It was introduced in 1995 and it's popularity has grown quickly since A programming.
CS346 Javascript -3 Module 3 JavaScript Variables.
SE-1010 Dr. Mark L. Hornick 1 Variables & Datatypes.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Copyright Curt Hill Variables What are they? Why do we need them?
White Space Spaces, blank lines, and tabs are collectively called white space and are used to separate words and symbols in a program Extra white space.
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fluency with Information Technology Third Edition by Lawrence Snyder Chapter.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Introduction to Java Programming by Laurie Murphy Revised 09/08/2016.
Copyright 2010 by Pearson Education APCS Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
>> Introduction to JavaScript
A variable is a name for a value stored in memory.
CHAPTER 4 CLIENT SIDE SCRIPTING PART 1 OF 3
Working with Java.
Chapter 4 Assignment Statement
Lecture 2: Data Types, Variables, Operators, and Expressions
CS180 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Variables and Arithmetic Operators in JavaScript
University of Central Florida COP 3330 Object Oriented Programming
JavaScript Syntax and Semantics
Chapter 3 Assignment Statement
Statements, Comments & Simple Arithmetic
Starting JavaProgramming
null, true, and false are also reserved.
Variables and Arithmetic Operators in JavaScript
Introduction to Java Programming
An overview of Java, Data types and variables
Chapter 1: Computer Systems
Units with – James tedder
Units with – James tedder
JavaScript Reserved Words
Focus of the Course Object-Oriented Software Development
Module 2 - Part 1 Variables, Assignment, and Data Types
Chap 2. Identifiers, Keywords, and Types
Agenda Types and identifiers Practice Assignment Keywords in Java
Presentation transcript:

C Derived Languages C is the base upon which many build C++ conventions also influence others *SmallTalk is where most OOP comes Java and Javascript have nothing in common except their “parents”

Variables (or identifiers) Values stored in computer memory Value can vary over time Reserved Words and Keywords part of the JavaScript language-- Variable Example: employeeName

JavaScript Variables Two ways to create: Use var to declare the variable var employeeName; Use the assignment operator to assign the variable a value employeeName = “Ric”;

Variable name syntax rules (like C:Java,etc.) Cannot use reserved words & spaces Must begin with one of the following: Uppercase or lowercase ASCII letter Dollar sign ($) or underscore (_) Variables are case-sensitive Can use numbers, but not as first character

Variable Naming Conventions Use underscore or capitalization to separate words of an identifier employee_first_name employeeFirstName

legalIllegal my_variable $my_variable __my_variable my_variable2 myVariable $ my%_variable 2my_variable my_#variable ~my_variable my+variable

abstract boolean break byte case catch char class const continue debugger default delete do double else enum export extends false final finally float for function goto if implements import in instanceof int interface long native new null package private protected public return short static super switch synchronized this throw throws transient true try typeof var void volatile while with

C++ / Java Comments DOCUMENT your code + use it for testing Line comments // ignore all text to the end of the line Block comments /* ignore all text between these symbols */

/* commented out code*/ code //line comment code //########## separator ########## /*____________________________________ __ Section comment ______________________________________ */

a clever trick: /* */ code // */ /* *x/ commented out code // */

C Statements; Statements are ALWAYS terminated with ; New lines mean nothing; are ignored. Extra ; are harmless but it is parsed javascript and downloaded… so it has a cost Browsers tolerate missing ; but don’t push your luck with bad habits!

Strings String Literals contained in quotes “ ” or single quotes ‘ ’ Strings can be: Used as “literal” values Assigned to a variable empty “”

Using HTML tags in strings Use HTML tags to format strings Tag must be contained inside string quotes var newString = ‘ ’; 2 kinds of quotes saves you from having to escape quotes \”

Escape Characters Escape Squence Character \\Backslash (\) \nNew Line (unix-use this one) \tTab \’ Single quotation mark / Apostrophe \”Double quotation mark There are others

Concatenating strings Concatenation operator: + var oneString = “one”; var anotherString = oneString + “, two, three, …”; Assignment operator: += var oneString = “one”; oneString += “, two, three, …”;

Numbers Number Literals just type a number Abstract - no int, float, or small size limits Math Object contains a function library from random to trig functions

Assignment Operators Syntax very similar to C/Java, but: var x = 'dog'; var y = 'dog'; x= 5; y= my_function();

OperatorDescription =Assigns value of right to left +=Adds right value to left -=Subtracts right value to left *=Multiplies right value to left /=Divides right value into left %= Divides right value into left returns remainder

var x = 4; var y = 5; x += y; // x becomes 9 var a = "Hello"; var b = " World!"; a += b; // a becomes "Hello World!"

! is it null, undefined, 0, false, “” ()? ( test )? if true this : if false this like if statement but compact, faster + - * / % && || same as java Other operators

Ternary conditional var x = ( true ) ? ‘hello world’ : 47 ; data types can be mixed Technically, it is just ? : but everybody uses the ()

Decision Making if ( condition statement ) { statement(s); if( condition statement ) { statement(s); } else {statement(s);} }

conditionals only want false DOES NOT RUN next code block: if( false ){} if( 0 ){} if( “” ){} if( null ){} var x; if( x ){}

Comparison Operators Used to compare two operands for equality and if one numeric value is greater than another Can mix types! Auto type conversion is possible. Compare that to Java!

OperatorDescription ==true if equal !=not equal >greater than <less than >=greater or equal to <=less or equal to

Common Typoo = is not == if( x = 5 ){} y= ( x = 5 ) true : false; valid code; but not expected result

Custom Functions Function is similar to Java method Individual statements grouped together to form a specific procedure Allows you to treat the group of statements as a single unit

Defining Functions 1. function + name (identifier) 2. Parameter list in parentheses () variables live within the function block Zero or more order matters 3. Code block defined by braces { }

function printC(company1, company2, company3) { document.writeln(company1); document.writeln(company2); document.writeln(company3); }

Calling Functions “function invocation” or “function call” f() f( parameter1, 2, 3, 4 ) Used in a statement ; denotes the end of a statement many javascript interpreters handle ; mistakes - it does not mean you’re correct

Returning a value A function could return nothing return; var returnValue = square(x); return x*x;

function square(x){ return x*x; } var result= square(4); alert(result); // displays 16 alert( square(4) ); //also displays 16

Loops quick review - C derived

for Like Java, C, C++, Objective-C, C#... for( initialize; test; last ) initialize is run first, only once test is evaluated EACH time Runs before the loop-- if false we stop last is run at the END of EACH loop

var i; for( i=0; i< 50; ++i) { document.writeln(”this is #” + i); }

while while( test ) loops until test is false as basic as it gets

var i = 0; while( i< 50) { document.writeln(”this is #” + i); ++i; }

do while do {code} while( test ) loops until test is false runs code at least 1 time created just to make life easier

var i = 0; do { document.writeln(”this is #” + i); ++i; }while( i< 50);

continue & break continue; Halts a looping statement and restarts the loop with the next iteration could be called “skip” or “blowrev” break; jumps out of loop or switch

Review Initialization statements setup loop Evaluate conditional statement: 0, false,””, null, undefined → stop inside loop: run statement(s) which impact conditional statement for( x=1; x; x+1) {alert(‘infinite loop’);}