Download
cs121 review n.
Skip this Video
Loading SlideShow in 5 Seconds..
CS121 Review PowerPoint Presentation
Download Presentation
CS121 Review

CS121 Review

96 Vues Download Presentation
Télécharger la présentation

CS121 Review

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. CS121 Review Mason Vail

  2. Class • A data type definition – “blueprint for objects” • Includes properties and/or methods • “instance” data / methods – specific to one object (instance) of the class • “static” or “class” data / methods – belongs to the class itself, shared by all objects of the type

  3. Object • One instance of a data type • Looks and acts like other objects of the same type, but has its own identity and state independent of other objects

  4. Encapsulation • One of the central pillars of object-oriented design • Idea that each object is in control of its own state (instance data) and outsiders are required to interact with the object through its limited public interface (set of methods)

  5. Encapsulation - Visibility • Visibility regulates the exposure of data and methods • “public” – accessible to any outside entity with a reference to the object • “protected” – default visibility – accessible to child objects or any other entity defined in the same package • “private” – accessible only within the class/object • All data / methods should be private until a good reason is given to relax visibility

  6. Method • A named set of statements within a class that carry out a specific task • Public methods make up the public interface of an object • Protected/private methods generally serve as supporting utility methods for carrying out intermediate tasks for the object

  7. Driver Class • The class containing the main() method, where a program begins • The class invoked by name when launching the Java Runtime Environment (JRE)

  8. Array • The most basic linear data structure for storing multiple values of the same type • In some languages, they are a primitive data type, but in Java arrays are objects, though they have special syntax that makes them look a little different than other objects

  9. Array • As objects, arrays must be instantiated with a constructor call before they can be used • int[] a = new int[10];//creates an array with room for 10 ints • The size of an array, once instantiated, is immutable

  10. Array • Arrays can be multidimensional – each dimension can be of a different size • 2D arrays (“tables”) are common • The first dimension of a 2D array is commonly considered to be the row reference • The second dimension of a 2D array is commonly considered to be the column

  11. Array • Any multidimensional array can be thought of as an “array of arrays” until the last dimension is accessed and an individual value of the array type is reached • int[][] someArray = new int[5][10]; • someArray is an array of int[]s of length 5 • someArray[0] is in int[] of length 10

  12. Primitive Variablesvs Object References • A primitive variable is a named memory location containing a value of the primitive type • An object reference variable contains the address of an object somewhere else in memory

  13. Primitive Variablesvs Object References • Making a copy of a primitive variable duplicates the value, after which the two variables have no effect on the other • Making a copy of an object reference creates an alias – a duplicate reference to the same object – so changes can be made to the object via any of its aliased references • Copying an object requires instantiating a new, independent object and explicitly duplicating the state of the original object in the new object

  14. Interface • A collection of bodiless, abstract method signatures defined in a .java file • May be implemented by one or more classes • Not a class – may not be instantiated

  15. Accessor and Mutator Methods • Accessor (“getter”) methods – methods with the special purpose of returning object information without violating encapsulation • Returned values are typically already known – the method only needs to return an independent copy of instance data • Mutator (“setter”) methods – methods with the special purpose of updating object state without violating encapsulation • Changing data takes the form of a request, rather than a demand – the object has the opportunity to validate input and enforce its own rules about updating its state