Académique Documents
Professionnel Documents
Culture Documents
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;
-
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
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
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.
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.
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
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?
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.
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.
Q8. Explain the effect of the code in Q7. (DO NOT DESCRIBE THE CODE!!)
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?