180 likes | 194 Views
This course aims to develop programming skills in Java, focusing on writing multiclass applications. It covers topics such as UML, OOP, and API, and includes examples of calculating rectangle area and volume. The course also covers algebraic laws and explains compile-time errors.
E N D
CSE 1020: Introduction to Computer Science I Mark Shtern
Course Objective • Developing development skills • Writing Java Multiclass application • Introducing the software engineering concern • Study UML, OOP, API
Example 01 Write application that calculates rectangle area
Example 02 Write application that calculates volume of rectangle couboid
Math & Computers • Algebraic laws • (a*b) /c is equal to a * (b/c) • (a + b) – c is equal to a + (b -c)
Ex 1.16 • What is program output? char grade= ‘B’; System.out.print(grade); { System.out.print(grade); { grade = ‘C’; System.out.print(grade); } } System.out.println(grade);
Ex 1.17 Explain the compile-time error long speed = 1; int size = 7; { boolean even = false; long speed = 5; size = 2; } int even = 3; System.out.println(speed); System.out.println(size); System.out.println(even);
Ex 1.17 What is output? long speed = 1; int size = 7; { boolean even = false; size = 2; } int even = 3; System.out.println(speed); System.out.println(size); System.out.println(even);
Summary • Types • Declaration • Arithmetic Operations +,-,/,* ,% (remainder) • Casting • Scope
Shortcuts a++ a=a+1 a-- a=a-1 a+=6 a=a+6 a*=6 a=a*6
Literal • Real • 7D or 7d 7 is double • 2.5E 3 2.5*10^3 or 2500.0 • Boolean • true or false • Character • ‘\t’ , ‘\n’, \’, ‘\\’,’\”’
Program Execution Edit Compile Run
Java Program Byte code javac Compile-time Errors VM CPU Byte code java instruction
Ex 1.18 Is it true that expression a * b * c/d (1) is evaluated as ((a * b) * (c /d)) (2)
Ex 1.21 int i = 6; long l = 4; double d = 12; l = i + i; d = i + i; i = l + l; l = d + d; Explain the compile-time error
Ex 1.22 int x = 3; int y = 14; double pie = x + y / 100.0; int z = (5 % 4) + 6 / 8; System.out.println (pie); System.out.println(z); Explain the compile-time error or predict its output
Math & Computer sqrt(x^2) vs (sqrt(x))^2 (1/x) * x vs x * 1/x
Char Type • What is output? char letter = ‘D’; letter = (char) (letter +1); System.out.println(letter); ------------------------------------------ char letter = ‘D’; char letter2 = ‘A’; System.out.println(letter2 - letter);