Vous êtes sur la page 1sur 15

2081 Quiz Questions

Week 2
Q1. Of the three types of mobile apps which type(s) has (have) the
potential to write once then distribute to many platforms?
Hybrid Apps
Mobile apps
Q2. What factors and improving technologies are powering the recent
rapid rise of mobile web apps?
Implementation of HTL5 (look and feel) and WebAPI (access to device)
Q3. In what context can a mobile browser be seen as a thin (?) native
client? Why?
A mobile browser can be seen as thin as these browsers need little
memory to run in, and significantly reduce over-the-air traffic, making
them very suited to be run on low-powered devices when mobile
connectivity is bad or expensive or both.
Q4.
a) Why does syntax need to be exact? Whats the consequence of invalid
syntax?
Syntax needs to be exact so that the code can be correctly executed, thus
if it isnt then the code will not be executed.
b) Of the three types of programming error which do you think is the
hardest to debug. Why?
The hardest error to detect would be logic error; this is because neither
the complier or run time system signal an error. Its all down to the quality
of the testing.
Q5. Boolean b ;
b = true ;
Whats the problem, fix it 2 ways.
Solution 1 (need to remove quotation marks from true)
boolean b;
b = true;
Solution 2 (not sure if correct)
boolean b = true;

Q6.
a) Declare a variable to hold the value of total year-to-date enrolment. You
need correct data type, a good variable name, correct syntax and good
style.
String YearToDateEnrol;
b) Declare a constant to hold the value of the conversion factor from
kilometres to miles. You need correct data type, a good variable name,
correct syntax and good style.
Final double Conversion_Km_To_Miles;
Q7.
K = k + 1;
-

Describe in detail the effect of this java statement

The value of K will store the total value of k + 1; Thus is k needs


to be contently changed, then the value of K will store that value.
(Notice one of the Ks is upper case and the other one is lower
case, makes a difference)
K + 1 = K;
-

Whats wrong with this?


The problem with this is that you cannot have the function
happen before it can be stored. ??????

Q8.
a) What is a data type?
A data type is for example integer or string, usually used to state
what kind of data needs to be collected/stored.
b) Whats the point of making a language strongly typed?
Some languages (such as java) insist a variable can contain one and only
one data type(not value) during its lifetime. This allows there to be no
problems at run-time.
Q9. What is a compile error?
A compile time error is an error that is detected by the compiler. Common

causes for compile time errors include:


Syntax errors such as missing semi-colon or use of a reserved keyword
(such as 'class').
When you try and access a variable that is not in scope.
When you declare multiple objects with the same name.

Q10. Using the string object dogcat twice write java code to output the
string cat and dog to the console.

String dogcat;
dogcat = cat and dog;
System.out.println(dogcat);

Week 3
Q1. What are the three steps required to use any API class that has a
public constructor?
i.e. classes like Scanner not like Math
STEP 1:
Tell the compiler where to find the class in the API library
STEP 2:
Create an object of the class (AKA instantiating an object)
STEP 3:
Apply the classs methods to the object to get it to do what you want it to
do

Q2.
a) What does the import statement import? Explain your answer
The import statement in Java allows us to refer to classes, which are
declared in other packages to be accessed without referring to the full
package name. You do not need any import statement if you are willing to
always refer to java.util.List by its full name, and so on for all other
classes. But if you want to refer to it as List, you need to import it, so that
the compiler knows which List you are referring to. (???)
b) What API classes do not need to be imported?
java.lang
Q3. Scanner myScanner = new Scanner(System.in)
a) Explain the syntax of this statement by explaining the syntax not the
semantic (meaning) role of each token (word).
Scanner The name of the class
myScanner the variable name
new finds enough memory for a new scanner object and returns the
start address of this memory
System.in means that there will be an input stored
-b) Explain the semantics of this statement?
The meaning of this statement is that the user will asked to input data,
which will be stored under myScanner ???
Q4. When are ++i and i++ equivalent?
I++ and ++I are equivalent only if they are a standalone statement.
b) What will be output by the following statements?
System.out.println (18 / 4);
System.out.println ( (double) 18 / 4 );
System.out.println ( (double) (18 / 4) );

Q5.
a) What is the semantics (meaning) of the = operator?
Simple assignment operator, Assigns values from right side
operands to left side operand. E.g. C = A + B

b) What is the semantics (meaning) of the == operator?


Checks if the values of two operands are equal or not, if yes then
condition becomes true e.g. (A == B) is not true.
c) You can assume myBoolean has been declared as a Boolean
variable and has been assigned either true or false. Rewrite the
following eliminating its syntactic redundancy.
if (myBoolean == false)
Q6.
a) What is an expression?
An expression evaluates to a value
b) What is a Boolean expression?
Boolean expressions evaluate to either of the two boolean values
true or false
c) What is the most common use of Boolean expressions?
if (booleanExp)
codeBlock
[else
codeBlock]
??????
Q7. The conditions in an if elseif else decision structure are not
mutually exclusive.
a) Is this a complie, run-time or logic error or just bad style?
b) Whichever of these you choose explain your answer.
????

Q8.
a) If (year != 2014 || year != 2015)
System.out.println(Year is not in range 2014..2015);
Whats wrong? Why?
??????

b) If (response != Quit)
System.out.println(Non-quitting response is + response);
Whats wrong? Why?
??????

Q9.
a) What is a counter controlled loop?
A counter-controlled loop is a condition-controlled loop with
predictable number of iterations. The loop starts at some number
(usually the topmost number or zero), then counts down until it
reaches the limit (usually zero or the topmost number), at which
point it exits the loop. The other common type starts at zero or one,
and increments until it reaches a destination number.
b) What repetition structure should be used for a counter controlled
loop?
Loop condition appears at beginning of pretest loop
c) How can it become an infinite loop?
Must contain a statement that makes the expression true
d) What is a Sentinel Controlled loop?
In a Sentinel-Controlled loop, a special value called a sentinel value
is used to change the loop control expression from true to false.
e) What repetition structure should be used for a Sentinel Controlled
loop?
??????
f) How can it become an infinite loop?
??????

Week 4
Q1.
a) When an exception is encountered in the code in a try block what
statement executes next assuming the exception is caught in this
try catchfinally block?
- Enclose the statement(s) that could cause the exception in a try
block
- Deal with the exception (including doing nothing) in a catch block
that catches the exception
- Optionally enclose any subsequent code that must be performed
regardless of whether an exception occurred or not in a finally
block

b) What is the relationship between exception handling and the call stack?
c) Why do we bother to catch exceptions?

Q2.
a) How many return statements can a method have if its header includes
the keyword Void?
b) How many return statements can a method have if its header does not
include the keyword Void?
c) What does good coding style have to say about the number of return
statements a method should have? Why?
Q3.
a) A method call includes actual parameters. Syntactically what can an
actual parameter be?
b) A method definition includes formal parameters. Syntactically what can
a formal parameter be?
c) What is the syntactical requirement between a methods actual and
formal parameters?
d) At time of call describe exactly what occurs with respect to a methods
parameters?
e) If a formal parameter and its matching actual parameter are both
variables is it significant whether their names match or not?
Q5.
a) What is the scope of a local variable?
b) What is the scope of a formal parameter?
c) What is the scope of a variable declared outside of all methods?
d) What is the lifetime of a local variable?
e) How many lifetimes can a local variable have?
f) What is the relationship between these lifetimes?
g) What is the lifetime of a formal parameter?

Q6.
a) Java arrays have a fixed size but this can be viewed as a maximum size.
How?
b) Explain how to insert an element into a java array. Is anything lost in
this process?
c) Explain how to delete an element from a java array.
Q7.

Describe what the following code does. DONT DESCRIBE ANY ASPECT OF
THE CODE.

Q8.
a) When a debugger halts at a breakpoint what line of code will execute
next?
b) When you step over a method call in the debugger is that method
completely executed?
c) Why use Step over?
d) If you accidently Step into a method how can you recover?
e) Identify three ways of finding out a variables values when stopped at a
breakpoint.

Q9. After the following code has successfully executed:


a) What is the value stored at int1?
b) What is the value stored at a1 [1]?
c) What is the value stored at a1 [2]?

Q10.
After the following code has successfully executed:
a) What is the value of i?
b) What is the value of p.age?
c) What is the value of s?

Week 5
Q1.
a) What is a class?
b) How many objects can be instantiated from a class and what is the data
type of these objects?
c) What is the state of an object?
d) What do objects of a class share?
e) What is NOT shared by objects of a class?

Q2.

a) Explain how java can prevent access to instance variables by code


outside their class?
b) Explain how java coders can provide controlled access to the instance
variables of a class?
Q3. What are the benefits of encapsulating data and the only code that
can directly manipulate that data?
Q4.
a) What is the scope of a local variable?
b) What is the scope of an instance variable?
c) What is the lifetime of a local variable?
d) What is the lifetime of an instance variable?
e) How can a method connect its lifetimes?
Q5.
a) What is the identifier: something most likely to be syntactically?
b) What is the identifier: Something most likely to be syntactically?
c) What is the identifier: something () most likely to be syntactically?
d) What is the identifier: Something () most likely to be syntactically?

Q6.
a) How does a constructor differ from a normal method in its declaration?
b) How does a constructor differ from a normal method in its invocation?
c) How many constructors can a class have?
d) How many constructors should a class have?
e) Why are constructors public?

Q7. The following questions are about code written with good style.
a) Should a driver class contain instance variables? Why?
b) What methods should appear in a driver class?
c) Should a thing/concept class contain instance variables? Why?
d) What types of method can appear in a thing/concept class?
- Hint accessors and mutators both fall into the same type here

Q8. Code an accessor for an instance variable called weightInKgs, which


has the data type double.
Q9. Code a mutator for an instance variable called birthYear. The allowed
range is 1900 to 2015 inclusive. Report to driver codes the success or
failure of the mutation.
Q10. Why should constructors with parameters contain mutator calls?

Week 6
Q1.
a) What do objects of a class share (4 things)?
b) What do objects of a class not share (1 thing)?
c) What is the lifetime and scope of a local variable?
d) What is the lifetime and scope of an instance variable?

Q2. The questions below assume good coding style specifically


thing/concept classes should not contain their own driver code!
a) Can a static method of a class contain references to instance variables
of the same class? Explain answer briefly.
b) Can a non-static method of a class contain references to static, class
level variables of the same class? Explain answer briefly.
c) Why should a class level constant be declared static?
d) Exactly what constitutes (makes up) the interface of a class.
Q3.
a) Describe the inheritance scenario that requires an abstract class?
What are the super class and sub class implementation details?
b) What are the benefits of using inheritance in this scenario?
Q4.
a) Describe the inheritance scenario that does not require an abstract
class?
What are the super class and sub class implementation details?
b) What are the benefits of using inheritance in this scenario?
Q5.

a) Code the class header liner for the class Bread that inherits from the
class Food.
b) How many classes can a class inherit?
Q6.
a) How can code in a subclass access public variables in a super class?
b) How can code in a subclass access private variables in a super class?
c) How can code in a subclass execute public methods in a super class?
d) How can code in a subclass execute private methods in a super class?
e) How can you add to a super class data items and functionality in a
subclass?
f) How can you modify super class functionality in a subclass?

Q7. The keyword super can be used in two syntax contexts. What are
they and what is their semantics (meaning) and motivation (why are they
used)?
Q8.
a) What is the syntax rule and runtime system behaviour that makes
polymorphism possible?
b) Why do you think Java allows objects of a class to be referenced by
variables of the class ancestors?
c) Why do you think java does not allow objects of a class to be referenced
by variables of the class subclasses?
d) Why would you need to downcast?
Q9.
a) How does polymorphism reduce code?
b) How does polymorphism future proof an existing code processing
framework?
Q10.
a) What is an interface?
b) Code the class header line for the class Bread that promises to code a
method for each of the method headers in the interface
HouseholdBudgetItem.
- The class ElectricityBill also promises to code a method for each of the
methods headers in this interface.

c) How many interface promises can a class make?


d) How do interfaces support polymorphism? ( Its a similar way to the
way inheritance does it)

Week 7
Q1.
a) Why doesnt Android use Swing/AWT? Give an Example
b) With respect to swing/AWT what do heavyweight and lightweight mean?
c) Why, when java GUI interface becomes unresponsive is the window its
in not necessarily unresponsive?
d) Does swing completely replace AWT? Explain your answer.
Q2.
a) How many listener classes can react to the same event object?
b) How many different even object types can a listener class react to?
c) How many responses can a listener class have to any given event
objects?
Q3.
a) What type of class are event handlers coded in? What does the code
they contain do?
b) Why are sequencing dependencies between event handling methods a
problem in GUI/event driven code?
c) Can you think of a way around the sequencing dependency problem
when it cannot be avoided? Think about your own experience with
GUI/Event driven interfaces. (HINT: what happens if you try to leave word
without saving it?)
Q4. How are event handlers, that we code, callable from API code?
Q5.
a) When does an instantiated JFrame instance die?
b) When you close the JFrame instance, firstWindow (see below) what
happens? What doesnt happen?
c) So why is the following problematic in a single window application?

FirstWindow. setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE) ;
Q6. Our first attempt at a GUI/event driven program was written using just
two custom classes. This was quickly rewritten using three custom
classes. Briefly describe the role of each of these 3 classes.

Q7. With respect to the following code:


endButton.addActionListener(new ActionListener () {
public void actionPerformed (ActionEvent e) {
System.exit(0) ; // exit normally
}
});

a) What syntactically entity does the trailing ; terminate?


b) What syntactically entity does the trailing ) terminate?
c) What syntactically entity does the trailing } terminate?

Q8. Explain the effect of the code in Q7. (DO NOT DESCRIBE THE CODE!!)

Q9. Rewrite the code in Q7 to use a named listener class


(EndButtonClickListener) that is instantiated in situ (in place)?

Q10.
a) How does threading stimulate parallel processing?
b) Why do you think threading is important in GUI/event driven
programming?
c) Describe how to create and run a new thread.
d) What is the code you want to run in the new thread requires inheritance
from some other class?

Vous aimerez peut-être aussi