1322 Programming 2 Flashcards
(272 cards)
What does a class define?
The properties and methods of an object
Is Java an interpretted or compiled language?
Compiled
How many main methods can I have per class?
1
What are the naming principles of Java?
Constants and classes should begin with a capital
Variables and methods should not start with numbers or capitals
Avoiding keywords.
What are primatives?
Variables that store simple pieces of information
How is an object stored in a variable?
As a reference to that object in the heap.
What is scope?
Member variables can be accessed anywhere in the class while local variables can be accessed only from the method in which they are defined
How can we prevent variable shadowing?
Using the keyword this which always refers to the member variable.
Also by naming your variables properly.
What is the difference between print and println?
println adds a newline character after your text
T/F Multiple returns from a method is possible in Java
False
What is overloading?
When two methods share the same name but have different parameters and implementation
In the JVM, how is a method recognised?
By it’s signature (its name, parameters and their order)
Note this doesn’t include return type.
What is encapsulation of classes?
The bundling of data, with the methods that operate on that data
Why do we define attributes as private?
To protect encapsulation by preventing direct access from external classes
What is an array for?
Grouping things together
What can an array hold?
Objects or primitives
What is the difference between an array and arrayList?
Arrays are fixed size and require knowing the index while arrayList are unbounded size and don’t require knowing the index.
Why can I add an int to an arrayList?
They can only hold objects so we need to wrap an int in an Integer
Why would you use an iterator?
As they decouple the loop from the collection, so we can pass the iterator without the function knowing about the collection
What do iterators do?
Track progress through a collection
T/F We use == to compare objects in Java
False.
We use the .equals method instead
Why do we use inheritance?
Because duplication is bad, so we want to write a common template
What is a superclass?
Any class that is inherited from
What does a subclass inherit from a superclass?
All it’s protected and above properties and methods.