lecture3 - Introduction Introduction Computer program: an...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Introduction Introduction Computer program: an ordered sequence of statements whose objective is to accomplish a task. statements Programming: process of planning and creating a program program Programming Language: a set of symbols, special words, and rules for using those symbols and special words to create statements to implement the ordered sequence of instructions to accomplish a task sequence The Basics of a Java Program The Java program: collection of classes There is a main method in every Java There application program application Token: smallest individual unit of a program Word symbols or reserved words Identifiers or names for things in the program Special symbols (operators …) Reserved words in Java Reserved A reserved word is a part of the computer reserved language we are using. In is a special word that gives the compiler a specific instruction it can understand understand Abstract, boolean, break, byte, case, catch, char, class, const, continue, default, do, double, else, extends, const, false, final, finally, float, for, goto, if, import, int, implements, instanceof, interface, long, native, new, implements, null, package, private, protected, public, return, short, static, strictfp, super, switch, synchronize, this, throw, throws, translate, true, try, void, volatile, while Java Identifiers I Java Names of things Must contain only: Letters (upper and lower case) Digits (0-9) The underscore character (_) The dollar sign ($) Java Identifiers II Java Must not begin with a number Cannot be a reserved word Identifiers beginning with an underscore Identifiers are used for specific purposes and should be avoided in general use be Java is case sensitive. The identifier Toy Java is not the same as the identifier toy is Illegal Identifiers Illegal Which Are Legal Java Identifiers? Which cycle A!star int Score Y-Z Trial#2 This_One$ while_$__zero $MyProgram FOR 3constant_values “MaxScores” unsigned _External_Prog Mary’s StarChart Binary Arithmetic Operators in Java Binary A Binary Operator operates on two arguments arguments + * / % addition addition subtraction subtraction multiplication multiplication division division modulus or remainder modulus Unary Arithmetic Operators in Java Unary A Unary Operator operates on one argument argument + ++ ++ --- addition addition subtraction increment increment decrement decrement Binary Relational Operators in Java Binary < <= <= > >= >= less than less than or equal to greater than greater greater than or equal to greater Binary Equality Operators in Java == == != != equal to equal not equal to Binary Logical Operators Binary & | ^ && && ||| | AND OR Exclusive OR Short Circuit AND Short Circuit OR Unary Logical Operators ! Not Bitwise Operators in Java Bitwise & | ^ << << >> >> >>> >>> AND AND Inclusive OR Exclusive OR Left Shift Right shift (sign extension) Right shift (zero extension) Compares integer values bit by bit Evaluated right to left Assignment Statements Assignment Basic statement used to perform Basic calculations calculations Form: result = expression; Form: result expression Example: X = X + X * Y; Assignment operators Assignment A=B assign value of expression B to variable A, store result in A A += B add the value of expression B to += variable A, store result in A A -= B subtract the value of expression B -= from variable A, store result in A A *= B multiply the value of expression B *= by variable A, store result in A A /= B divide the value of expression B /= by variable A, store result in A Precedence of operators in Java Precedence ( ) . ++ -- (pre) + - ! (unary) ++ */% +<< >> >>> < <= > >= == != & ^ | && || = += -= *= /= %= innermost first innermost (right to left) Data Types Data Data Type A set of values plus a set of operations on those set values values A crucial concept on modern programming Data Type of a variable determines how its Data memory cells are interpreted memory Data Type of a variable indicates the size of Data the memory cell allocated for the variable Primitive Data Types Primitive Primitive Data Types Primitive Floating-Point Data Types Floating-Point Float: single precision = 6 or 7 digits 38 range -3.4*1038 to 3.4*1038 to Double: double precision = 15 digits 308 range -1.7*10308 to 1.7*10308 to Arithmetic and relational operators Boolean Data Types: Boolean two values TRUE and FALSE Logical operators Integral Data Types Integral Values and Memory Allocation for Integral Data Types Integral ...
View Full Document

This note was uploaded on 01/16/2010 for the course CMPT 101 taught by Professor Various during the Spring '03 term at Simon Fraser.

Ask a homework question - tutors are online