00-ICS102-Review.pptx - Review of ICS 102 Lecture Objectives To review the major topics covered in ICS 102 course Refresh the memory and get ready for

00-ICS102-Review.pptx - Review of ICS 102 Lecture...

This preview shows page 1 - 11 out of 36 pages.

Review of ICS 102
Image of page 1
Lecture Objectives To review the major topics covered in ICS 102 course Refresh the memory and get ready for the new adventure of ICS 201!
Image of page 2
Quick Review of ICS 102 Primitive and Reference Types Initializing Class Variables Defining Constructors How to Create a String How to Perform Operations on Strings Arrays
Image of page 3
primitive integral floating point byte char short int long float double boolean Java Primitive Data Types
Image of page 4
Primitive types
Image of page 5
Simple Initialization of Instance Variables Instance variables can be initialized at declaration. Initialization happens at object creation. More complex initialization should be placed in a constructor. public class Course{ private String title; private String dept = "ICS"; private int credit = 4; }
Image of page 6
Defining Constructors public class Course{ private String title; private String dept = "ICS"; private int credit = 4; public Course() { title = "Intro. To Computing"; } public Course(String newTitle) { title = newTitle; } } Course course1 = new Course(); Course course2 = new Course("C Prog."); Course course3 = new Course("Comp. Networks"); The Course class now provides two constructors.
Image of page 7
The this Reference Instance methods receive an argument called this , which refers to the current object. public class Course{ private String title, dept; public void setDept(String dept) { this.dept = dept; } void anyMethod() { Course course1 = new Course(); Course course2 = new Course(); course1.setDept(“ICS"); … title: null dept: null course2 course1 title : null dept: “ICS"
Image of page 8
Sharing Code Between Constructors public class Course { private String title; private String dept; public Course() { this(“ICS"); } public Course(String newDept) { dept = newDept; } } A constructor can call another constructor by using this(). Course course2 = new Course(); What happens here?
Image of page 9
title dept Class Variables Class variables belong to a class and are common to all instances of that class.
Image of page 10
Image of page 11

You've reached the end of your free preview.

Want to read all 36 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture