L06 - Computer Science 1 1 SS C Lecture 6 Contents"...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS101 Lecture 6 1 Computer Science 1 1 SS C Lecture 6 Contents Objects String objects String instance methods Coursebook: §6 2 Java - supports object oriented programming The world is made up of real world objects e.g. students, dogs, cars, cats, books. Each object has: Objects are the things our programs deal with. data - stores the current state of the object. code - which operates on the object's data i.e what can be done with that object type. and 3 Objects – Example Consider a system managing university students. A student object has: id, data code which operates on the data e.g. name,age,address, faculty, contact number, completed courses,grades, ... current courses, add a new course, add grade for a course, … change address, set faculty, update contact number, stage, 4 Visualising objects (instances) Each object (also called instance) consists of two things: data code data code data code data code data code data (the current state of the object) code ( which operates on the data) 5 Student instance Student instance Student instance Student instance Student instance Class and instances of the class Each kind of object (instance) is represented by a Java class, which is stored as a Java source file. public class Student { .... data . .. .... .... code . .. .... } Student.java Jane . . code Ella … code Yu … code Ying … code Sam … code 6 Primitive and Object types All data in Java is either: inFnitely many. there are exactly 8 a primitive type or an object type or
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS101 Lecture 6 2 7 Declaring object variables Just as before, we must specify the type of the variable (which will be the name of a class) and give it a name : variable name (identifier) type of the variable (class name) Classname identifier; String name ; For example: Chocolate yum1 ; Student sam ; 8 Initialising objects Remember that to initialise a primitive variable, we assign some literal value to the variable: identifier = new Classname(); String welcome = new String ("Hello World"); For example: Rectangle box; box = new Rectangle (10, 20, 30, 40);
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/01/2012 for the course COMPSCI 101 taught by Professor Adrianaferraro during the Summer '12 term at Auckland.

Page1 / 5

L06 - Computer Science 1 1 SS C Lecture 6 Contents"...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online