MidTerm Exam Preparation - PowerPoint PPT Presentation

1 / 28
About This Presentation
Title:

MidTerm Exam Preparation

Description:

Creating new projects. Packages. Building/compiling and running. import ... 'no arg' constructor for a class if you don't write any constructors of your own ... – PowerPoint PPT presentation

Number of Views:54
Avg rating:3.0/5.0
Slides: 29
Provided by: calpoly
Category:

less

Transcript and Presenter's Notes

Title: MidTerm Exam Preparation


1
Mid-Term Exam Preparation
2
Sources of Info
  • Relevant Gittleman text chapters
  • Powerpoint Slides
  • Java Example Programs
  • Java Mutual Support List
  • Your Assignments and Projects

3
Basic Object Concepts
  • What is an object
  • Objects contain both behavior and data
  • Benefits of the use of the object model

4
Classes and objects
  • A class as a "template"
  • An object as an instance of a class (represents
    one "real" object)

5
Object Oriented Programming Definitions
  • Object
  • Encapsulation
  • Inheritance
  • Polymorphism
  • Clients and servers
  • Class hierarchy
  • class, subclass and superclass
  • class Object at top of hierarchy

6
Planning Your Logic
  • Pseudocode
  • No rigid rules
  • Sometimes called structured English
  • Flowcharts
  • More visual
  • Use of special symbols (rectangle, diamond, oval,
    parallelogram)
  • Flowcharts of selection
  • Flowcharts of iteration
  • test-before loops
  • test-after loops

7
Java Language Fundamentals
  • Literals, variables, classes
  • Conventions on naming variables and classes
  • Structure of a Java expression
  • receiving object, method, argument(s)
  • Assignment statements

8
Data Types and Objects
  • What are basic data types?
  • What are examples of objects?
  • How do you work with data types? (i.e., you
    manipulate them in other ways, but you do not
    send them messages)
  • How do you work with objects? (i.e., you send
    them messages)

9
Java Fundamentals
  • Source code, object or bytecode
  • Pre-written classes and use of the Java API
  • Creating new projects
  • Packages
  • Building/compiling and running
  • import statement

10
Java Naming Conventions
  • Class names
  • Variable names
  • Method names

11
Java statements
  • Assignment statements and the assignment operator
  • Structure of an assignment statement
  • Precedence
  • Short cut notations ( and , etc.)
  • Punctuation in java statements
  • Simple statements and compound statements (i.E.,
    Blocks)
  • Some java statements are assignment statements
    and some are not. For example
  • totalTax oldTax newTax
  • myCar.setWeight(3000)

12
Control Structures
  • Sequence
  • Selection
  • Iteration
  • Implementation of these in java

13
Classes
  • The App class
  • Has a main method
  • Constructs instances of worker or support
    class(es)
  • Does most of the input and output
  • Drives the worker/support class through a set of
    steps
  • Support or worker classes
  • Maintains info in instance variables
  • Contains methods which describe most of the
    application logic
  • Methods return values to the main method, or
    change instance variables, or are used by other
    methods of the worker class

14
Writing classes
  • Structure of a class
  • Heading line
  • How you designate instance variables
  • Instance variables should normally be private
  • How where you designate constants
  • Where the methods are written in the class

15
Writing Methods
  • Header line
  • Access modifier
  • Return value
  • Method name
  • Arguments
  • Declaring their type
  • Naming them
  • Writing the logic
  • Remembering that local variables are discarded
    when the method ends
  • Remembering to return what is expected
  • Method does one task
  • Method name descriptive of that task
  • Method returns zero or one value
  • Can not return more than one

16
Using Instance Methods
  • Requesting an object to carry out some behavior
    (i.e., execute a method) is how the work of a
    Java program is completed
  • Structure objectName.methodName(arguments)
  • Example taxTotal carRental.calcTax(totSale)
  • Example myPerson.setDateOfBirth(11/07/1984)
  • When you write a Java statement, when do you make
    it an assignment statement and when not ???

17
Class Methods
  • Asking the class itself to carry out some
    behavior
  • Example
  • ageStr JOptionPane.showInputDialog(Enter Age
    )

18
Constructors
  • Writing a constructor method for a worker or
    support class
  • The no arg constructor
  • The fully-populating constructor
  • Java gives you automatically a no arg
    constructor for a class if you dont write any
    constructors of your own
  • Using a constructor (for example in the main
    method) to construct an object
  • Example Person myPerson new Person()
  • Example Person myPerson new Person(Louise,
    5.3)
  • Example Date today new Date()

19
Getters and Setters
  • Getters to retrieve data from the instance
    variables of an object
  • Example String carColor myCar.getColor()
  • Setters to store data into the instance variables
    of an object
  • Example myCar.setColor(red)
  • Naming conventions for getters and setters
  • Use of a fully-populating constructor as an
    alternative to using setters to give values to
    instance variables

20
Conditional Statements
  • Boolean expressions
  • Structure of an "if" statement
  • How an "if" statement works
  • Precedence

21
Boolean expressions
  • Always evaluate to a boolean value True or False
  • Relational operators (, lt, gt, !, etc.)
  • REMBEMBER only works on data types
  • Messages/methods that return a boolean
    (custname.Startswith("sa"))
  • Compound expressions involving more than one
    boolean value
  • !

22
Formatting Conditional Statements
  • if (boolean-expression-1)
  • statement-1
  • if (a b)
  • statement-1

23
Formatting Conditional Statements
  • if (tapeType.startsWith("Fi"))
  • statement-1
  • else
  • statement-2

24
Nested if Statements
  • How they are formatted
  • Understanding how they are executed (i.e., under
    what conditions do you get to point xx, and after
    that is executed what happens next)

25
Formatting "else if" Statements
  • if (tapeType.equalsIgnoreCase("Classic"))
  • statement-1
  • else if (tapeType.equalsIgnoreCase("First Run")
  • statement-2
  • else if (tapeType.equalsIgnoreCase("Adult")
  • statement-3
  • else
  • statement-4

26
Iteration
  • Logic
  • Test before and test after loops
  • for, while and do while loops
  • Use of blocks

27
for, while and do while loops
  • Structure of each
  • Formatting of each
  • When you choose each
  • Using each to solve a problem

28
Specific Classes
  • Know the methods we have used for the following
    classes
  • String class
  • JOptionPane class
  • Date class
Write a Comment
User Comments (0)
About PowerShow.com