You are on page 1of 4

CHAPTER 6 What are the three test phases? 1. Test user interface 2.

Test application with valid data 3. Try to make app fail with every combo of invalid/valid data What are the three types of errors that can occur? 1.Syntax: voilate the rules for how statements must be written 2.Runtime: throw exceptions that stop of the execution of the app 3.Logic: statements that produce wrong results Distinguish between testing and debugging? - testing: Try to make app fail with every combo of invalid/valid data - debugging: solve errors CHAPTER 7 Describe the architecture commonly used for object-oriented programs. - three-tiered architecture, an application is separated into three laye rs. The presentation layer consists of the user interface. The database laye r consists of the database and the database classes that work with it. And the middle layer provides an interface between the presentation laye r and the database layer. Its classes are often referred to as business cl asses. Describe the concept of encapsulation and explain its importance to object-orien ted programming. Encapsulation lets you control which fields and methods within a class a re exposed to other classes. When fields are encapsulated within a class, it s called data hiding. It allows methods of a class to be modified or improved without changing how other classes use it. Differentiate between an object s identity and its state. -identity: unique address -state:value it holds Describe the basic components of a class. - instance variable - constructor - set/get methods Explain what an instance variable is. - An instance variable may be a primitive data type, and object created from a Java class or user defined class. Public class Product

{ //you can code instance variable anywhere outside of methods+con . private double price; private Product p; //set/get methods } Explain when a default constructor is used and what it does. A default constuctor does not accept any parameters and intializes all instance variables to null, zero, or false. public Product() //must always be public { code = " "; } Describe a signature of a constructor or method, and explain what overloading means. Constructor: The signiture is made up of the class name + num of parameters + dt for ea par Method: parameter name + num parameters, dt List four ways you can use the this keyword within a class definition. 1. 2. 3. 4. refer to instance variable call methods of current object pass current object to another method call another constructor of current class

What is the syntax for using the this keyword? - this.variableName //refers to instance variable of current object public Product ( String code) { this.code=code; } - this(argumentList) // calls another constructor public Product() { this ("","",0); } - this.methodName(argumentList) //call method of current object\ public String getFormat() { NumberFormat current = NumberFormat.getCurrencyInstance(); return current.format(this.getPrice); // isnt necessary as its i mplicit } - objectName.methodName(this) // passes current object to method public void print() { System.out.print(this); }

- Classname.methodName(this) // passes current object to static method public void save() { ProductDB.saveProduct(this); } How do you code a method? public|private returnType methodName(parameterList) {} //set and get accessors public void setPrice (int p) { price = p; } public int getPrice () { return price; } How do you overload a method? you code 2+ methods with the same name, but atleast 1 parameter must hav e dif dt Explain the difference between how primitive types and reference types are passe d to a method. - When a primitive type is passed to a method, the method recieves the v alue of the variable. Method can't change valyue directly - must return dt - when a reference type(object) is passed to a method, the method recive s the value of the variable. Because obj variable contained pointer, the method can change value directly - no return type needed Explain how static fields and static methods differ from instance variables and regular methods. Static fields and methods belong to the class, not object created from c lass. Explain what a static initialization block is and when it s executed. When it takes more than 1 statement to initialize a static field, you ca n use a static block to intialize a field. CHAPTER 8 In general, explain how inheritance works. Inheritance allows you to create a class that is based on another class. When inheritance is used, a subclass inherits the fields, constructors, and m ethods of the superclass.

Explain what it means for a subclass to extend a superclass. The subclass can extend the superclass by adding its own fields and meth ods, and it can override a method with a new version of the method. Explain how inheritance is used within the Java API classes. Java API uses inheritance extensively..in fact there are many inheritanc e heirachies Explain why methods such as toString and equals are available to all objects and when you might override these methods. Every class automatically inherits these methods. You can override them so they work appropiately for that class. Describe two ways that you can use inheritance in your applications. 1. Generic superclasses 2. Classes from Java API CONTINUED IN HAND Describe the accessibility that s provided by the access modifiers you can use for the members of a class. Explain what polymorphism is and how it works. Describe two ways that you can get information about an object s type. Explain when it s necessary to use explicit casting when working with objects created from derived classes. Explain how abstract classes and methods work. Explain how final classes, methods, and parameters work.

You might also like