Chapter 00 revision

397 views

Published on

not 100% wrote by the author.just to share.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Chapter 00 revision

  1. 1. Object Oriented Programming 1LECTURER: NURHANNA AZIZROOM: 3206EMAIL: NURHANNA@KUIS.EDU.MYHP: 0192223454
  2. 2. Prerequisites 2Must have taken “Introduction to Programming” /“Fundamental of Programming” subjectBasic understanding of programming (variables,control flow, branch condition, simple array etc)Student must be able to write a simple program
  3. 3. Recommended Books 3Deitel & Deitel Java How to Program. 2007. Pearson International Edition.Dennis Liang Java Object Oriented Programming. 2009. Thompson LearningC. Thomas Wu. An introduction to Object Oriented Programming with Java. 2004. McGrawHill.
  4. 4. Syllabus 4Object Oriented ProgrammingMethodEncapsulationInheritancePolymorphismExceptionsJava AppletBuilding Java GUIsGUI Event HandlingGUI-based applications
  5. 5. Course Evaluation 5Mid term Test 20%Project 20%Lab Assessments 15%Attendance 5%Final Exam 40%
  6. 6. Teaching Outcomes 6By the end of this module, student should be : Familiar with programming concept within JAVA Able to carry out design and development of complex element such as user interfaces
  7. 7. Learning Outcomes 7An appreciation of the complexities of largeprograms, and the use of classes and inheritance tomanage this complexity The ability to design a collection of classes toimplement a large program An appreciation of good programming style (clarity,elegance)
  8. 8. How to pass the subject? 8Continuous Assessment (Coursework)60%Final Exam 40%For DTCO 3023 – 50% overall to passFor DTCO 3103 & DTCO 3113 – 40%overall to passAttend the lecturesDo assignment, exerciseDo all the practical(lab) as best as you can.Project Presentation
  9. 9. Attendance 9Student will be bared from sitting for final exam if Not attend for lectures & lab – 3 times continuously; or Have 30% and more absent record
  10. 10. Revision 10
  11. 11. Sample of Java Application Program 11 VIEW SOURCE RUN PROGRAM CODE
  12. 12. Source Code 12 Name of the class / programs The “main” method
  13. 13. Why Java? 13“Write once, Run Anywhere”SecurityNetwork-centric ProgrammingDynamic, Extensible ProgramInternationalizationPerformanceProgrammer efficiency and time-to-Market
  14. 14. Java: Names & Reserved Names 14 Legal name (variables, method, fields, parameter,class, interface or package) Start with: Letter/dollar sign($)/ underscore (_)/ digits(0-9) Reserved namesabstract char else goto long publicassert class extends if native returnboolean const false implements new shortbreak continue final import null staticbyte default finally instanceof package strictfpcase do float int private supercatch double for interface protected switch
  15. 15. Java Naming Conventions 15Names of variables, fields, methods: Begin with lowercase letter shape, myShapeName of classes and interfaces: Begin with UPPERCASE letter Cube, ColorCube
  16. 16. 16Named constants: Written fully in UPPERCASE Separated by underscore (_) CENTER, MAX_VALUE, MIN_VALUEIf name is composed of several words: First word begins with lowercase, first letter of second word begins with UPPERCASE, the rest back to lowercase setLayout,addPatientName
  17. 17. Comments 17Have no effect on the execution of the program2 forms: one-line comments E.g. Class Comment { // This is one-line comment, its extends to the end of line } delimited comments E.g. Class Comment { /* This is a delimited comment, extending over several lines */
  18. 18. Types 18Primitive type E.g. boolean,char,byte,short, int, long,float,doubleReference type Class type defined/ interface type definedArray type In form [ ]
  19. 19. Variables 19Syntax <Variable-modifier>< type>< variables_name>;E.g. public static void main (String[] args){ int a, b,c; int x=1, y=2,z=3; int myDivide=z/x; double PI=3.1415; boolean isFound=false; }
  20. 20. Declaring Variables 20int x; // Declare x to be an // integer variable;double radius; // Declare radius to // be a double variable;char a; // Declare a to be a // character variable;
  21. 21. Assignment Statements 21x = 1; // Assign 1 to x;radius = 1.0; // Assign 1.0 toa = A; // Assign A to a;
  22. 22. Declaring and Initializing in One Step 22 int x = 1; double d = 1.4;
  23. 23. Constants 23final datatype CONSTANTNAME = VALUE;final double PI = 3.14159;final int SIZE = 3;
  24. 24. The String Type 24 E.g.: String message = "Welcome to Java";String Concatenation // Three strings are concatenated String message = "Welcome " + "to " + "Java"; // String Chapter is concatenated with number 2 String s = "Chapter" + 2; // s becomes Chapter2 // String Supplement is concatenated with character B String s1 = "Supplement" + B; // s1 becomes SupplementB
  25. 25. Programming Errors 25Syntax Errors Detected by the compilerRuntime Errors Causes the program to abortLogic Errors Produces incorrect result
  26. 26. Converting Strings to Integers 26 use the static parseInt method in the Integer classas follows: int intValue = Integer.parseInt(intString);where intString is a numeric string such as “123”.
  27. 27. Converting Strings to Doubles 27 use the static parseDouble method in the Doubleclass as follows:double doubleValue=Double.parseDouble(doubleString);where doubleString is a numeric string such as“123.45”.
  28. 28. 28 The Two-way if Statementif (boolean-expression) { statement(s)-for-the-true-case;}else { statement(s)-for-the-false-case;} true false Boolean Expression Statement(s) for the true case Statement(s) for the false case
  29. 29. if...else Example 29if (radius >= 0) { area = radius * radius * 3.14159; System.out.println("The area for the “ + “circle of radius " + radius + " is " + area);}else { System.out.println("Negative input");}
  30. 30. Common Errors 30 Adding a semicolon at the end of an if clause is a commonmistake. if (radius >= 0); { area = radius*radius*PI; System.out.println( "The area for the circle of radius " + radius + " is " + area); }
  31. 31. switch Statementsswitch (status) { 31 case 0: compute taxes for single filers; break; case 1: compute taxes for married file jointly; break; case 2: compute taxes for married file separately; break; case 3: compute taxes for head of household; break; default: System.out.println("Errors: invalid status"); System.exit(0);}
  32. 32. 32 while Loopsint count = 0;while (count < 100) { System.out.println("Welcome to Java"); count++;}
  33. 33. while Loop Flow Chart 33 int count = 0;while (loop-continuation-condition) { while (count < 100) { // loop-body; System.out.println("Welcome to Java!"); count++; Statement(s); }} count = 0; Loop false false Continuation (count < 100)? Condition? true true Statement(s) System.out.println("Welcome to Java!"); (loop body) count++; (A) (B)
  34. 34. do-while Loop 34 Statement(s) (loop body) true Loop Continuationdo { Condition? // Loop body; false Statement(s);} while (loop-continuation-condition);
  35. 35. for Loops 35 int i;for (initial-action; loop-continuation- for (i = 0; i < 100; condition; action- i++) { after-each-iteration) { System.out.println( // loop body; "Welcome to Statement(s);} Java!"); } Initial-Action i=0 Loop false false Continuation (i < 100)? Condition? true true Statement(s) System.out.println( (loop body) "Welcome to Java"); Action-After-Each-Iteration i++ (A) (B)
  36. 36. Review Questions 36Problems: 1. Wahid just bought himself a set of home theatre. Declare a variables of TV of type String, speakers of type int, price of type double and goodCondition of type boolean. 2. Amir had 5 history books. Declare an array of book he had.

×