Docsity

Final Exam Study Guide - Introduction to Programming in Java | CS 1054, Study notes of Java Programming

Toggle sidebar
bg1
CS1054 Final Exam Study Guide
Chapter 8
What is cohesion?
All interface features should be closely related to the single concept that the class represent.
What is coupling?
The amount in which classes are linked together.
What is an immutable class?
Is a class that has been designed to have only accessor methods and no mutator methods. Ex: String class
What is a side effect?
Is any kind of modification of data this is observable outside of the method. Mutator methods have a side
effect, namely the modification of the implicit parameter.
What is a precondition?
Is a requirement that the caller of a method must meet. If a method is called in violation of a precondition,
the method is not responsible for computing the correct result.
What is a postcondition?
A different kind of promise the method makes, there are 2 kinds:
The return value is computed correctly.
The object is in a certain state after the method call is completed.
If a method has been called in accordance with its preconditions, then it must ensure that its postcondtions
are valid.
What is a static method?
A method that is not evoked on an object, this is also called a class method. Ex: sqrt, when you call sqrt
you don’t supply any implicit parameter.
How do you call a static method?
You supply the name of the class containing the method so that the compiler will find it.
Example: double tax = Financial.percentOf(tax, total)
What is a static field?
Used to store values outside any particular object. It belongs to the class, not to any object of the class.
Also is called a class field.
What is the scope of a variable?
Is the region of a program in which the variable can be accessed.
How is the scope of a field different than the scope of a parameter or local variable?
The scope of a local variable can never contain the definition of another local variable with the same
name.
The scope of a field and methods are collectively called members of the class.
Private members have class scope, to use a public field outside of its method you must qualify the name,
you do this by specifying the class name, Ex: Math.sqrt or Math.PI
pf3

Partial preview of the text

Download Final Exam Study Guide - Introduction to Programming in Java | CS 1054 and more Study notes Java Programming in PDF only on Docsity!

CS1054 Final Exam Study Guide

Chapter 8 What is cohesion? All interface features should be closely related to the single concept that the class represent. What is coupling? The amount in which classes are linked together. What is an immutable class? Is a class that has been designed to have only accessor methods and no mutator methods. Ex: String class What is a side effect? Is any kind of modification of data this is observable outside of the method. Mutator methods have a side effect, namely the modification of the implicit parameter. What is a precondition? Is a requirement that the caller of a method must meet. If a method is called in violation of a precondition, the method is not responsible for computing the correct result. What is a postcondition? A different kind of promise the method makes, there are 2 kinds: The return value is computed correctly. The object is in a certain state after the method call is completed. If a method has been called in accordance with its preconditions, then it must ensure that its postcondtions are valid. What is a static method? A method that is not evoked on an object, this is also called a class method. Ex: sqrt, when you call sqrt you don’t supply any implicit parameter. How do you call a static method? You supply the name of the class containing the method so that the compiler will find it. Example: double tax = Financial.percentOf(tax, total) What is a static field? Used to store values outside any particular object. It belongs to the class, not to any object of the class. Also is called a class field. What is the scope of a variable? Is the region of a program in which the variable can be accessed. How is the scope of a field different than the scope of a parameter or local variable? The scope of a local variable can never contain the definition of another local variable with the same name. The scope of a field and methods are collectively called members of the class. Private members have class scope, to use a public field outside of its method you must qualify the name, you do this by specifying the class name, Ex: Math.sqrt or Math.PI

Chapter 9 What is a Java interface? They are used to make code more reusable, they do this by focusing on the essential operations carried out. A java interface type declares a set of methods and their signatures. How does an interface differ from a class? Unlike a class, an interface type provides no implementation. How do you indicate that a class is going to implement an interface? Use the implements keyword to indicate that a class implements an interface type. A class implements an interface type if it declares the interface in an implement clause. Then it should implement the method or methods that the interface requires. Interfaces can reduce the coupling between classes. Example: Class ClassName implements Measurable { Public double getMeasure() { Implementation } Additional methods and fields } Note: the class must declare the method as public, all methods in an interface are public. What is polymorphism? It denotes the principle that behavior can vary depending on the actual type of an object. In greek means “many shapes”. In java all instance methods are polymorphic. Chapter 10 What is inheritance? Is a mechanism for extending existing classes by adding methods and fields. It is used for enhancing existing classes. What keyword is used when a class extends a base class? It is called a subclass. What is a superclass? It is the more general class. What is a subclass? It is the more specialized class that inherits from the superclass. How does a subclass call a superclass's constructor? You denote the inheritance by a solid arrow with a hollow triangle. How does inheritance differ from implementing an interface? -An interface is not a class, it has no state and no behavior, and it merely tells you what methods you should implement. How does a subclass call a superclass's method? The new method and instance field must be defined in the subclass. Example: public class SavingsAccount extends BankAccount