1/149
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
what is the difference between method overloading and method overriding in Java?
one means having the same method name but different parameters, while the other means a subclass changes a method that it inherits from its superclass
what is the purpose of the final keyword in Java?
means that a variable’s value, a method’s behaviour, and a class’ inheritance cannot be changed
what is the difference between a checked exception and an unchecked exception
one must be caught with try-catch or declared in the method, but the other happens during the program and don’t have to be handled explicitly
what is the difference between a constructor and a method in Java?
one initializes a new object, while the other performs actions on an object
what does the this keyword do in a constructor or method?
refers to the current instance of the class
what is the purpose of the super keyword in java?
refers to the superclass and is used to call parent class methods or constructors
explain the difference between == and equals() in Java
one checks if two objects are the exact same thing in memory, while the other checks if their contents or values are the same
what is the difference between a static method and a non-static method
one belongs to the class while the other belongs to an instance of the class
what is a final variable, and how is it different from a regular variable?
one cannot be changed once assigned, whereas a the other one can
how does the try-catch block work in exception handling?
one contains code that might throw an exception, and the other handles the exception if it occurs
what is the purpose of throw and throws keywords in Java exceptions?
one is used to cause an exception right away, while the other tells that a method might cause an exception
what is the difference between String and StringBuilder in Java?
one is immutable while the other is not
what is polymorphism and how is it used in Java?
it lets different kinds of objects be used like they are the same type, usually by replacing methods with new versions
what is an abstract class in Java?
is a class you can’t make objects from, but other classes can inherit from it
what is the difference between an interface and an abstract class in Java?
one is a list of method names without code that any class can use, and the other can have methods with or without code and other classes can extend it
what is a constructor overloading in Java?
occurs when multiple constructors with different parameters are defined in a class
what does instanceof operator do in Java?
checks if an object is of a certain type, it verifies the object’s class when the program is being ran
what is the purpose of the private access modifier in Java?
restricts access to a field or method to within the same class only
what is the null keyword in Java?
represents the absence of a value or reference for a variable
what is the purpose of the continue statement in Java?
skips the current iteration of a loop and moves to the next iteration
what is the difference between ArrayList and LinkedList?
one stores items in a growable array and lets you quickly get any item, while the other stores items in a chain and lets you add or remove items faster
what does the default keyword do in an interface?
lets a method in an interface have a default code that classes can use or override
what is method chaining?
lets you call methods one after another on the same object in one line, because each method returns the object itself
what is the difference between ArrayList and HashSet?
one lets you use store methods in an ordered list, because it keeps insertion order, while the other stores unique elements in no order because it does not allow duplicates
what is the purpose of the static keyword?
lets you use methods or variables without creating an object, because it belongs to the class itself
what is the difference between a method signature and a method declaration?
method signature includes the name and parameters, because it identifies the method while the method declaration includes the return type an access modifiers, because it defines the method
what is the purpose of the default constructor?
creates an object without setting any values because it is automatically provided if no constructor is given
what is the difference between Thread.sleep() and wait()?
one pauses the thread for a certain time, while the other pauses it until another is told to continue
what does super() do in a constructor?
calls the parent class constructor, because it ensures the parent class is properly set up
what is the purpose of the final keyword in method parameters?
lets you make sure a parameter’s value cannot be changed, prevents reassignment
what does the this keyword do in a constructor?
refers to the current object, because it helps distinguish instance variables from parameters
what is a hashcode?
uniquely identifies objects because it helps quickly locate and compare objects in hash-based collections
the major difference between stack memory and heap memory is that the stack is used to store the order of method execution and local variables while the heap memory stores the objects and it uses dynamic memory allocation and deallocation
true or false
true
in java, the default value for a class variable of type int
is -1.
true or false
false
instance variables are used to represent an object’s state
true or false
true
subclasses can access private instance variables of the superclass
true or false
false
when writing regression tests, it is ok to directly interact with private variables
true or false
false
a uml use case diagram is considered a behavioural diagram, as opposed to a structural diagram
true or false
true
in Java, the toString() method automatically collects a class’ attributes and generates a formatted Strinag representation of the class
true or false
false
you need to provide the size of an arrayList when you are creatin the arrayList
true or false
false
polymorphism can be used with both inherit super types and implemented supertypes
true or falsea
false
which of the following is not a class found in java’s collection framework
arraylist
hashmap
hashset
dictionary
dictionary
which of the following are not important for a regression test program?
constructing objects are calling methods
displaying the results of the method calls
displaying the values that you expect to get
reading input from the user
reading input from the user
suppose the class coffee extends the class drink. which one of the following assignments is legal?
drink x = new drink();
coffee y = new coffee();
a) y = x;
b) x = y;
c) y = new drink();
d) new drink() = new coffee();
x = y;
suppose you are to design an inheritance hierarchy with the following classes: mouse, cat, mammal, and tiger. which of these is the superclass?
a) tiger
b) mammal
c) mouse
d) cat
mammal
which programming technique should be used if you want a method to have different behaviour depending on the class of the object that is invoking it?
polymorphism
the instaceof operator
an if-else statement
the getclass method
polymorphism
which of the following java
snippets would be used to declare a hashmap
that contains items of type exam
and is accessed by a key of type string
?
a. hashmap<exam> exams = new hashmap<string>();
b. hashmap<t> exams = new hashmap<t>();
c. map<exam, string> exams = new hashmap<exam, string>();
d. map<string, exam> exams = new hashmap<string, exam>();
d. map<string, exam> exams = new hashmap<string, exam>();
when should you delete your testing code from a class?'
a) if it is a simple class you don’t need to write proper regression tests
b) when all tests are passed and you know the class wont be changing
c) your regression tests should never be deleted
d) after several months without errors it makes sense to delete your tests to make your code easier to read
c) your regression tests should never be deleted
consider the following code fragment:
Object obj = “CMPT 270”;
System.out.println(ob.length());
which of the following statements are true?
the code compiles are runs without issue
the code will not compile because the Object class does not have a method called length()
the code will not compile because a String object cannot be assigned to something of type object
d) the code will compile but throw an exception
the code will not compile because the Object class does not have a method called length()
instance variables are used to model the attributes of an object
true or false
true
if your code contains an error, there will always be atleast one corresponding fault
true or false
false
Software development is all about learning a programming language.
False
Object Oriented Programming
A program consisting of classes and objects organized to manage the complexity of large-scale systems
Procedural Programming
A program consisting of methods/functions calling each other
Method
Implements behaviours relevant to the purpose of the system
Field or Attribute
Stores data relevant to the purpose of the system
Entity Object
Model of a real-world thing in an application
Control object
organize computation or flow of the program
Interface Object
Facilitates communication between the system and the outside world
Container Object
Data structure to store entities
A UML Class Diagram is a type of behavioural diagram
False
What does a toString() method do in Java?
It allows a programmer to define a String representation of their class
The tree class does not have a ‘chopDown’ method. What describes it’s behaviour?
a) Set height to 0
b) Mark isDead = true
c) Free memory
d) Set tree to null
The tree variable is set to null
Why doesn’t the Tree class have a height setter?
a) height is public
b) height never changes
c) grow() is the setter
d) getHeight() sets it
it has one, the method grow() acts as a mutator
which class acts as the main/client program?
a) inventory
b) forest
c) tree
d) TreePlanter
TreePlanter
which step was ommited from the lecture development process?
a) documentation
b) unit testing
c) uml
d) stub methods
unit testing
what was the final step in the development process followed in the lecture?
uml
unit testing
documentation
coding methods
implementing/coding methods
which of the following types could be stored in a container of WaterMonster?
a) Squiiirtle
b) Starfishy
c) Peekatu
d) Monster
e) ElectricMonster
f) WaterMonster
squirtle, starfishy, watermonster
effective use of polymorphism is good because it increases coupling in a software system
false
which keyword is used to indicate inheritance in java?
extends
polymorphism can be used with both inherited super types and implemented interface types
true or false
true
which of the following methods are inherited from the Object class?
a) getClass()
b) equals()
c) scanner.readInt(),
d) System.out.println()
e) attack()
f) toString()
getClass, equals(), toString()
the downside to polymorphism is that you cannot convert an object back to its original type
false
which of the following are a benefit of polymorphism?
a) Reduces coupling
b) Reduces code
c) Simplifies code
d) Increases flexibility
all of the above
which keyword defines a class uses an interface in Java?
a) inherits
b) implements
c) instanceof
d) extends
implements
which of the following data structures in Java can store primitive types?
a) TreeMap
b) ArrayList
c) Array
d) HashSet
Array
An ArrayList uses an Array to store its data, and therefore an ArrayList has a fixed size that must be specified upon creation
false
An Array can only store primitive data types.
false
Both TreeMap and HashMap implement the same Map interface, and can therefore be used interchangeably
true or false
true
Imagine you are creating a role-playing game and need to store all of your inventory items in a collection. You want to be able to look up an item by name, and frequently get a list of all of the item names sorted alphabetically. Which of the following collections would you use?
a) TreeSet
b) TreeMap
c) Hashmap
d) LinkedList
TreeMap
Imagine you are in need of a collection that stores items in a linear structure and will be frequently inserting and deleting from the middle of the collection. Which collection would be the best option?
HashMap
TreeSet
ArrayList
LinkedList
LinkedList
The collections classes, such as LinkedList and TreeMap, are defined using Generic typing.
true or false
true
Generic typing is reserved for classes provided by Java, such as ArrayList. We cannot implement generic typing in custom classes.
False
It is possible to restrict a generic type to a particular supertype, such as a class or an interface type.
true or false
true
The Comparable interface allows different instances of the same class to be comparable using the '<' and '>' operators.
false
By implementing the Comparable interface, Java will automatically generate the rules by which to compare that object.
false
After an exception is caught, the program continues execution where the exception was originally thrown.
false
Which of the following scenarios describe a situation when an exception should be thrown?
a) a user enters bad/incorrect data
b) a test regression fails
c) a bug detected in the program
d) a parameter violates a stated precondition
a user enters bad data, a parameter violates a stated precondition
Where is the best place to catch and handle an exception?
a) the main program
b) the method that has enough information to most effectively handle the exception
c) immediately, the place where the method that threw the exception is originally called
the method that has enough information to most effectively handle the exception
A try-catch statement can catch multiple different types of exceptions from the same try block.
true or false
true
When using the Scanner class' nextInt() method, which of the following exceptions are most likely to be thrown if the user enters something that isn't a number?
a) ArithmeticException
b) InputMismatchException
c) NullPointerException
d) InputMismatchException
InputMismatchException
Which of the following statements about exceptions is true?
a) A checked exception is named because it indicates a bug that should have been checked over by the programmer
b) Unchecked exceptions are things like IOException and FileNotFoundException
c) Your code will not compile if you don't try to catch a potential checked exception
d) Your code will not compile if you don't try to catch a potential unchecked exception
Your code will not compile if you don't try to catch a potential unchecked exception
Which of the following will create a pop-up dialogue box, prompting the user to enter some text into the program?
a) JOptionPane.showMessageDialogue()
b) JOptionPane.showOptionDialogue()
c) JOptionPane.showConfirmDialogue()
d) JOptionPane.showInputDialogue()
JOptionPane.showInputDialogue()
Which of the following classes in Java Swing represents the application's window?
a) JWindow
b) JFrame
c) JPanel
d) JLabel
b) JFrame
Which of the following is not a JComponent?
JFrame
JPanel
JButton
JLabel
JFrame
Which of the following is a container widget/component?
JButton
JPanel
JLabel
JTextField
JPanel
When creating a graphical user interface, the interface is automatically made visible when the JFrame object is created.
false
JFrame is a Java class, which means we can create a custom window/frame by creating our own custom class which inherits from JFrame.
true or false
true
In the event delegation model, which of the following is a JButton?
Event Source
Event Handler
Event
Listener
Event Source
Assume you want to respond to a button click. Which of the following describes the process?
You create a class that inherits from ActionListener
You create a class that implements the ActionListener interface
You directly bind a method to the button using the 'addMethodBinding()' method
You write a method called 'actionPerformed()' which is automatically bound to the button
You create a class that implements the ActionListener interface