Presentation is loading. Please wait.

Presentation is loading. Please wait.

02/14/2005 Introduction to Programming with Java, for Beginners Midterm 1 Review.

Similar presentations


Presentation on theme: "02/14/2005 Introduction to Programming with Java, for Beginners Midterm 1 Review."— Presentation transcript:

1 02/14/2005 Introduction to Programming with Java, for Beginners Midterm 1 Review

2 02/14/2005CSE 1101 Overview A Java program is a collection of cooperating objects An object is an instance of a class All Java code exists within a class Top Down Design Analyze the problem/simulation/game Decide what classes to use to model it Bottom Up Programming Write code for a class/method a little at a time

3 02/14/2005CSE 1102 Object “state” and “behavior” An object has “state” Instance variables that hold its data An object has “behavior” Methods that perform actions like computations, reporting information about state (“getters”), changing state (“setters”)

4 02/14/2005CSE 1103 Protecting an Object’s State A software designer wants his/her objects to behave: Consistently and reliably According to “spec” (specification) True to its documentation (javadocs) This is accomplished in part by: Making instance variables private Providing public methods that access the state appropriately

5 02/14/2005CSE 1104 Object Creation An object is an instance of a class A class has one or more constructors A constructor: Is a piece of code with the same name as the class Is executed when an object is created with the “new” operator When the “new” operator is used, Java finds the right class and then runs the constructor that has right number, order, and types of parameters

6 02/14/2005CSE 1105 Variables Variable Types Primitive Reference Variable Scope Instance Variable (a.k.a. “dynamic” variable, field) Method/constructor Parameters Local Variables

7 02/14/2005CSE 1106 Expressions An expression has a value. Some examples: Arithmetic 3 + 5 X * 2 Relational >, >=, <, <=, ==, != Boolean true, false, &&, ||, ! Assignment (value is the value assigned) Method call (value is the value returned by method)

8 02/14/2005CSE 1107 Statements A statement causes an action. Statements end with a semicolon or a {block} Unlike an expression, a statement does not have a value Some examples: Variable declaration Assignment Method call if while for

9 02/14/2005CSE 1108 Arrays A way to easily declare many variables of the same type An array is an object Whenever you see [ ] in a Java/C/C++/C# program, that means array Provide random access Legal indices: 0 through (length - 1) If attempt to access via an illegal index: ArrayOutOfBoundsException


Download ppt "02/14/2005 Introduction to Programming with Java, for Beginners Midterm 1 Review."

Similar presentations


Ads by Google