Download presentation
Presentation is loading. Please wait.
1
Names of variables, functions, classes
Identifiers: Names of variables, functions, classes (all user defined objects), Examples: if else while int float double main ... Can’t be used as identifiers They are reserved word a b gcd GCD A COSC1373 TAX Tax_Rate Tax Rate No special chars $ “ ; , ... Two identifiers, Tax and Rate 1 123 No numbers 5/6/2019 ITK 168
2
A name of a location in memory to hold value
A variable: A name of a location in memory to hold value A value of what? int a; String A; 245 the name the type the value 5/6/2019 ITK 168
3
Text String Binary: Text T e l : 2 8 7 4 9 EBCDIC E3 85 93 7A 40 F2 F8
ASCII 54 65 6C 2A 20 32 38 37 34 39 Binary: 5/6/2019 ITK 168
4
ASCII American National Standard Code for Information Interchange
American National Standard Code for Information Interchange 7-bit code Arabic ASCII Binary Hex 20 1 21 2 22 3 23 4 24 5 25 6 26 7 27 8 28 9 29 Char ASCII Binary Hex a 61 b 62 c 63 … ……… A 41 B 42 C 43 …. ……. : 3A # 23 5/6/2019 ITK 168
5
Numbers inside Computers
Bits Minimum Maximum Integers Short Signed 8 -128 127 Unsigned 255 Integer 16 -32,768 32,767 65,535 Long 32 -2,147,483,648 2,147,483,647 4,294,967,295 Range Floating Points Single -3.410-38 3.41038 Double 64 -1.710-308 1.710308 Java’s Types short int long float double 5/6/2019 ITK 168
6
8 primitive data types in Java
short i,j; int no; long sum; float total; double tax; char grade; byte b; boolean yes_or_no; i = 3; j = 3.14; tax = 8.25/100; grade = ‘A’; grage = ‘B’; grade = 97; yes_or_no = true; yes_or_no = false; Every variable has to be declared before we use it. 5/6/2019 ITK 168
7
Variables and Assignments
Everything that can receive a value L-value = R-value Everything that can give a value Assignment operator variable function expression literal variable The data types in both sides have to be consistent. If not, type-casting must be done. 5/6/2019 ITK 168
8
illegal Assignment examples L-value = R-value i = (3+7)*2-4-2*5; i =
3/2-0.5; illegal 3 = j; gcd(24,18) = 2+3; i+1 = j+3; i = 3/ ; i = i+2; total = i+j; average = total/2; sum = average*10*tax_rate; i = gcd(24,18); i = Integer.parseInt( ); JOptionPane.showInputDialog("Input y") 5/6/2019 ITK 168
9
More on Assignments L-value = R-value L-value = R-value L-value =
This operation itself will give a value L-value = R-value L-value = R-value L-value = L-value = a = b = c = i+j+3+gcd(15,6); illegal: a = b+1 = c = i+j+3+gcd(15,6); 5/6/2019 ITK 168
10
Parameter Passing How are parameters passed? Looks simple enough…
formal parameters int plus (int a, int b) { return a+b; } int x = plus(1,2); function body actual parameters (arguments) function call How are parameters passed? Looks simple enough… There are some techniques 5/6/2019 ITK 168
11
Parameter Correspondence
Which actual parameters go to which formal parameters? Most common case: positional parameters Correspondence determined by positions nth formal parameter matched with nth actual 5/6/2019 ITK 168
12
Parameter Passing function call 1 a 2 b int minus (int a, int b) {
return a - b; } int x = minus(1, 2); function call 1 a 2 b 5/6/2019 ITK 168
13
Local variables int minus (int a, int b) { int x = a – b; return x; }
public static void main(String[] args) { .... int a = 3; int b = 2; int d = 0; int x = a+b; d = minus(b,a); ..... } 5/6/2019 ITK 168
14
Arithmetic operators in Java
+ - * / % (x % y) is the remainder of x divided by y + - * / % (x % y) is the remainder of x divided by y Relational and logical operators in Java Resulting true or false < <= > >= == != && || ! & | ^ (20 < y) && (x <= i) 5/6/2019 ITK 168
15
Logical Operators || && ! Assume x = 10 true false true true false
|| && ! Assume x = 10 (1 || 0) ((18 <= x) && (x <= 50)) ((18 <= x) || (x <= 50)) !(x < 5) is same as (x >= 5) (((x % 2) == 0) && ((x % 3) == 0)) true false true true false 5/6/2019 ITK 168
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.