Final Exam Review Flashcards
Why Java?
- well documented and standardised across platforms
- OOP concepts have simple and easy to understand behaviour
- great libraries for handling basic collections
- easy to manage multiple threads
- garbage collector (no delete)
Java references
all object variables, refer to data in memory (pointers in C++)
Classes consist of…
member variables, constructors, methods
What is an object?
an instance of some class
extends
Java keyword to express one class is a child of another class (inherits member variables and methods)
method overriding
if a child class has identical method signature as parent class, child class method overrides parent class method
super
keyword used to access resources from parent class
structure of a method signature
access-modifier return-type name input-arguments
protected (access modifier)
can be accessed internally and within child classes
polymorphism
when parent class reference refer to a child class object
method overloading
two methods have same name but different signatures so no conflicts occurr
what does an interface and a class that implements that interface look like?
// Interface
interface Animal {
public void animalSound(); // interface method (does not have a body)
public void sleep(); // interface method (does not have a body)
}
// Pig “implements” Animal interface
class Pig implements Animal {
public void animalSound() {
// The body of animalSound() is provided here
System.out.println(“The pig says: wee wee”);
}
public void sleep() {
// The body of sleep() is provided here
System.out.println(“Zzz”);
}
}
abstract class
partially specified class that cannot be instantiated (but can be extended by a child class)
abstract method
method that is declared without implementation
what are the differences between an abstract class and an interface?
- polymorphism works with both
- a class can implement multiple interfaces but can extend one abstract class
- abstract classes can include some implemented methods
primitive data vs objects
primitive data types are predefined and stored in the stack
objects are created by users (value stored in stack, the real variable in heap)
process
ongoing execution of a computer program (don’t share resources with each other)
thread
a means to split execution into multiple simultaneous executions
code multithread in Java
// Make a subclass of thread
class MultithreadingDemo extends Thread {
public void run()
{
try {
// Displaying the thread that is running
System.out.println(
“Thread “ + Thread.currentThread().getId()
+ “ is running”);
}
catch (Exception e) {
// Throwing an exception
System.out.println(“Exception is caught”);
}
}
}
ORR
// Implement Runnable interface
class MultithreadingDemo implements Runnable {
public void run()
{
try {
// Displaying the thread that is running
System.out.println(
“Thread “ + Thread.currentThread().getId()
+ “ is running”);
}
catch (Exception e) {
// Throwing an exception
System.out.println(“Exception is caught”);
}
}
}
synchronised *Java keyword
prevents method from being executed until the previous call to the same method ends
why separate design and implementation?
interfaces and abstract classes are used for design, you can change implementation independently of interface
static *Java keyword
static member variables can be accessed without creating object, static resources are shared with objects of same class
git init
turn local directory into git repository
.gitignore
lists files that cannot be committed
My First Heading
My first paragraph.