Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 COS 260 DAY 2 Tony Gauvin. 2 Agenda Questions? Class roll call Blackboard Web Resources Objects and classes 1 st Mini quiz on chap1 terms and concepts.

Similar presentations


Presentation on theme: "1 COS 260 DAY 2 Tony Gauvin. 2 Agenda Questions? Class roll call Blackboard Web Resources Objects and classes 1 st Mini quiz on chap1 terms and concepts."— Presentation transcript:

1 1 COS 260 DAY 2 Tony Gauvin

2 2 Agenda Questions? Class roll call Blackboard Web Resources Objects and classes 1 st Mini quiz on chap1 terms and concepts –September 10 –30 min., M/C and short answer, open book, open notes, open computer Assignment 1 posted in Blackboard –Chap1 & 2 –Due September 17 prior to class

3 3 Getting what you need 1.Java JDK –http://www.oracle.com/technetwork/java/j avase/downloads/jdk8-downloads- 2133151.htmlhttp://www.oracle.com/technetwork/java/j avase/downloads/jdk8-downloads- 2133151.html –Pick the Kit for your OS 2.BlueJ –http://www.bluej.org/http://www.bluej.org/ –Download BlueJ installer for your OS 3.Projects for Class (and other resources) –http://www.bluej.org/objects-first/http://www.bluej.org/objects-first/ Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

4 5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling

5 5 Objects and classes objects –represent ‘things’ from the real world, or from some problem domain (example: “the red car down there in the car park”) classes –represent all objects of a kind (example: “car”) Object Oriented Programmers write class code and invoke objects Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

6 6 Objects and Classes http://courses.oreillyschool.com/java1/ja vaOne06.html http://courses.oreillyschool.com/java1/ja vaOne06.html Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

7 7 Class Object

8 8 Methods and parameters Objects have operations which can be invoked (Java calls them methods). Methods may have parameters to pass additional information needed to execute. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

9 9 Other observations Many instances can be created from a single class. An object has attributes: values stored in fields. Attributes describe the object’s “state” The class defines what fields an object has, but each object stores its own set of values (the state of the object). Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

10 10 State Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

11 11 Two circle objects Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

12 12 Java Data Types Integers  int, byte, short and long –2, 25879412547, -56, 111 Real numbers  float and double –58.45, 3.14159265 Logic  boolean –true, false Character  char –‘A’, ‘a’, ‘&’, ‘=‘, ‘@’, ‘1’, Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

13 13 Source code Each class has source code (Java code) associated with it that defines its details (fields and methods). Code is stored in a “*.java” file where * is the name of the class Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

14 14 Java Code Person person1 = new person(); person1.makevisible(); person1.moveright(); person1.moveHorizontal(50); Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

15 15 Methods Method signature Return_Value method_name(parameter_type para meter_name); void moveHorizontal(int distance); Method Invocation object_name.method_name(parameters); circle1.moveHorizontal(40); Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

16 16 Return values All the methods in the figures project have void return types; but … … methods may return a result via a return value. Such methods have a non- void return type. More on this in the next chapter. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

17 17 Make this picture Use figures project (hint: use terminal window with record methods options to see java code being implemented Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

18 18 Make this animation Use moveSlowHorizontal & and moveSlowVertical to make the child walk up the hill to stand beside the parent Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

19 19 Learning Java Code Instead of using the right mouse clicks on object bar we can use BlueJ Code pad to type in Java code directly Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Code Pad

20 20 Writing Java Code Using editor Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

21 21 Modifying Code Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Using editor modify code for picture to add a chimney in house project

22 22 Creating A database Open lab-classes project Create students using visual controls and code pad Using object bench and code pad and monitor terminal window –getName() –getCredits() Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

23 23 Objects AS Parameters Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Student br = new Student( "Barney", "YYY"); labClass1.enrollStudent(br); Do exercise 1.27, 1.28 & 1.29 on page 16

24 24 Terms for Today (and for mini-quiz) Object Class Instance Method Signature parameter Type State Source code Return value Compiler Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling


Download ppt "1 COS 260 DAY 2 Tony Gauvin. 2 Agenda Questions? Class roll call Blackboard Web Resources Objects and classes 1 st Mini quiz on chap1 terms and concepts."

Similar presentations


Ads by Google