Study Solutions
A java application always contains a single method, what is the method name and give the signature of this
method. ANS public static void main(Strings[] args){....}
How is data given to its parameter? ANS Through a command line interface.
Example: javac Assignment5.java
java Assignment5.java <input1.txt> myout1.txt
in Java identifiers can only begin with? ANS Identifiers can only begin with letters, underscores( _ ), or
dollar signs ($).
Is Java a Functional Language, Procedural Language, Object-Oriented Language, or Logic Language? ANS
Object-Oriented Language
What does API stand for? ANS Application Programming Interface
What package needs to be imported to use the scanner class? ANS import java.util.Scanner;
What is Encapsulation? ANS The hiding of design decisions in a computer program that are most likely to
change, thus protecting other parts of the program from change if the design decision is changed. The variables
contained in an object should be modified only within the object.
What are the three visibility modifiers, and what is their scope? ANS PUBLIC: can be accessed from
anywhere
PRIVATE: can only be accessed from inside the class
PROTECTED: the member can only be accessed within its own package (as with package-private) and, in
addition, by a subclass of its class in another package.
What is the purpose of toString()? ANS toString() is used to provide human users with a readable
representation of the object.
,What is an accessor method? ANS (GETTER) an accessor method is a method that accesses or gets the
value of a property of an object.
What is a mutator method? ANS (SETTER) a mutator method is a method that sets the value of a property
of an object.
What is a constructor? ANS A constructor is a special method that is used to create an object out of a class
definition and is used to initialize variables.
Define a constructor with two parameters int x, y for a class Point. A point object has an x and y coordinate.
ANS public Point(int x, int y){
this.x = x;
this.y = y;
}
Which method signatures would give an error if all methods were defined in a same (single) class?
public int calc(int num1, int num2){ ... }
public double calc(int num1, int num2){ ...}
public int calc(double num1, int num2){ ... }
public int calc(int num3, int num4){ ... }
public int calc(int num1, int num2, int num3){ ... } ANS public int calc(int num1, int num2){ ... }
public double calc(int num1, int num2){ ...}
public int calc(int num3, int num4){ ... }
These all have the same method signatures when calling the constructor, this is also known as Method
Overloading.
What is the difference between an instance variable, and a local variable. ANS INSTANCE: are GLOBAL
to all instance methods of the class
LOCAL: are only visible to the method scope in which it's defined.
The _________reference refers to the instance of the object. ANS this
, What is the keyword that associates a variable or method with the class rather than the object? ANS Static
Do all classes need a main method? ANS No, only one class should have a main method which is the entry
point to your program.
What is Software Engineering? ANS An attempt to produce a repeatable process for the development and
management of software projects. The quality of the software is a direct result of the process we follow to
create it.
Explain the relationship between development and maintenance effort. ANS Small increases in
development effort can reduce maintenance effort.
Which development method takes an object-oriented approach? Briefly describe this methods' steps. ANS
Evolutionary Development
Establish Requirements - What are the inputs expected by the applicationand what outputs are to be returned.
Architectural Design - Decide what kind of Algorithms and Data Structuresare needed to store and access the
data, and how are the objects going tointeract.Establish Refinement Scope - Phases of developmentIdentify
Classes & Objects -Identify RelationshipsDetailed DesignImplementationUnit TestingSystem Test Release
A very bad method for programming is called the Build-and-Fix approach. Why is this such a bad method?
ANS The build-and-fix approach is bad because no specifications are ever established which leads to
piecemeal code. Only immediate problems are corrected larger architectural problems are never identified or
fixed. Leads to an inability to maintain an application.
Suppose you have a program that takes as its input an integer from 0 to 423. Using the black box method of
testing list 9 test integers that you would use to adequately test the program. ANS -1, 0, 1
422, 423, 424
-100, 250, 550
What is a code walkthrough? ANS A meeting in which several people carefully review a design/ sections
of code to see if
the design satisfies requirement or the implementation represent the design.