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