Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CSC 201: Computer Programming I B. S. Afolabi. Introduction  3 unit course  2 hours of lecture/week Thursdays 4.00pm – 6.00pm Mondays 4.00pm – 6.00pm.

Similar presentations


Presentation on theme: "1 CSC 201: Computer Programming I B. S. Afolabi. Introduction  3 unit course  2 hours of lecture/week Thursdays 4.00pm – 6.00pm Mondays 4.00pm – 6.00pm."— Presentation transcript:

1 1 CSC 201: Computer Programming I B. S. Afolabi

2 Introduction  3 unit course  2 hours of lecture/week Thursdays 4.00pm – 6.00pm Mondays 4.00pm – 6.00pm  3 hours of practical/week To be determined next week Course Lecturers: 2 Dr. A. O. Ajayi Dr. F. O. Asaiah Mrs. H. O. Odukoya Dr. B. S. Afolabi (Coordinator) Dr. P. A. Idowu Dr. A. R. Iyanda Mr. I. P. Gambo Mr. Okegbile Miss Lawal

3 Textbooks  No textbook is required  For programming beginners: Java Software Solutions: Foundations of Program Design, John Lewis and William Loftus, Publisher: Addison Wesley, 2002  For experienced programmers: — Learning the Java TM Language at http://docs.oracle.com/javase/tutorial/ /http://docs.oracle.com/javase/tutorial/ / — Thinking in Java, Bruce Eckel, Prentice Hall

4 Software is required  Download Java onto your home machine  http://www.oracle.com/technetwork/java/javase/downloads /index.html http://www.oracle.com/technetwork/java/javase/downloads /index.html  Follow the instructions to install it  Then, follow the instructions to install Eclipse  https://eclipse.org/downloads/ https://eclipse.org/downloads/

5 Functional versus imperative languages  Functional languages are ideal for expressing the functional (the problem to be solved) component of any problem however...  at least 50% of all programs deal with input/output rather than a problem and functional languages aren’t very good at input/output.  Think of the programs you use now: editor mail language translator() web browser  Functional programming should have taught you to appreciate concise elegant programs.

6 The Computer Central Processing Unit (CPU) Memory Input / Output Devices

7 CPU Instructions z = x + y Read location x Read location y AddWrite to location z

8 Programming Languages  Easier to understand than CPU instructions  Needs to be translated for the CPU to understand it

9 JAVA  “Most popular” language  Runs on a “virtual machine” (JVM)  More complex than some (eg. Python)  Simpler than others (eg. C++)

10 Compiling Java Source Code (.javac ) javac Byte Code (.class) java

11 First Program class Hello { public static void main(String[] arguments){ //Program execution begins here System.out.println("Hello world."); }

12 Program Structure class CLASSNAME public static void main(String[] arguments){ STATEMENTS }

13 Output System.out.println(some String) outputs to the console Example: System.out.println(“output”);

14 Second Program class Hello2 { public static void main(String[] arguments){ //Program execution begins here System.out.println("Hello world."); //Print once System.out.println(“Line number 2."); // Again }

15 Types Kinds of values that can be stored and manipulated. boolean: Truth value (true or false). int: Integer (0, 1, -47). double: Real number (3.14, 1.0, -2.1). String: Text (“hello”, “example”).

16 Variables Named location that stores a value of one particular type. Form: TYPE NAME; Example: String foo;

17 Assignment Use “=“ to give variables a value. Example: String foo; foo = “IAP 6.092”;

18 Assignment Can be combined with a variable declaration. Example: double badPi = 3.14; boolean isJanuary = true;

19 class Hello3 { public static void main(String[] arguments){String foo = "IAP 6.092"; System.out.println(foo);foo = "Something else"; System.out.println(foo); }

20 Operators Symbols that perform simple computations Assignment: = Addition: + Subtraction: - Multiplication: * Division: /

21 Order of Operations Follows standard math rules: Parentheses Multiplication and division Addition and subtraction

22 class DoMath { public static void main(String[] Arguments){ double score = 1.0 + 2.0 * 3.0; System.out.println(score); score = score / 2.0; System.out.println(score); }

23 class DoMath { public static void main(String[] Arguments){ double score = 1.0 + 2.0 * 3.0; System.out.println(score); double copy = score; copy =copy/ 2.0; System.out.println(copy); System.out.println(score); }

24 String Concatenation (+) String text = "hello" + " world"; text = text + " number " + 5; // text = "hello world number 5"

25 Examples 1 class Comment { // This is a one-line comment; it extends to the end of the line /* This is a delimited comment, extending over several lines */ int /* A delimited comment, extending over part of a line */ x = 117; } 25

26 Examples 2 class Layout { // Class declaration int a; Layout(int a) { this.a = a; } // One-line constructor body int sum(int b) { // Multi-line method body if (a > 0) // If statement return a + b; // Single statement else if (a < 0) { // Nested if-else, block statement int res = -a + b; return res * 117; } else { // a == 0 // Terminal else, block statement int sum = 0; for (int i=0; i<10; i++) // For loop sum += (b - i) * (b - i); return sum; } 26

27 …Examples 2 static boolean checkdate(int mth, int day) { int length; switch (mth) { // Switch statement case 2: // Single case length = 28; break; case 4: case 6: case 9: case 11: // Multiple case length = 30; break; case 1: case 3: case 5: case 7: case 8: case 10: case 12: length = 31; break; default: return false; } return (day >= 1) && (day <= length); } 27

28 Example 4 class Scope {... // void m1(int x) { // declaration of parameter x (#1)... // x #1 in scope } //... // void m2(int v2) { //... // x #5 in scope } //... // void m3(int v3) { //... // x #5 in scope int x; // declaration of variable x (#2)... // x #2 in scope } //... // 28

29 …Example 4 void m4(int v4) { //... // x #5 in scope { // int x; // declaration of variable x (#3)... // x #3 in scope } //... // x #5 in scope { // int x; // declaration of variable x (#4)... // x #4 in scope } //... // x #5 in scope } //... // int x; // declaration of field x (#5)... // x #5 in scope } 29

30 30


Download ppt "1 CSC 201: Computer Programming I B. S. Afolabi. Introduction  3 unit course  2 hours of lecture/week Thursdays 4.00pm – 6.00pm Mondays 4.00pm – 6.00pm."

Similar presentations


Ads by Google