Flashcards
212
Cards in this deck (54)
- 1ConstantsSomething.FEMALE
(Type Safe) - 2EnumerationsSomething.Gender.Female
(Strongly Typed) - 3For EachFor Each
for (int i : myArray) { System.out.println(i); }
For Each with Enumerations
for (Gender g : Gender.values()) { System.out.println(g); - 4Parameter PassingThe Actual Parameter (The Value)
The formal parameter (The Variable)
Java is pass by value - 5InheritanceInheritance provides a mechanism to promote reuse and extensibility
Some classes can be inherit from, derived from or extend another
It is transative - 6Inheritance TermsBase class, super class, parent class
(Extends Keyword) - 7Method OverridingUsed to change the behaviour by replacing a method in the superclass
- 8Method OverloadingThis means we can have more than one method with the same, in the same class… as long as they have different parameter lists
- 9PolymorphismAny instance of a class which inherits (Extends) from another can also be treated as an instance of that class
- 10Polymorphism ConstraintsClass can extend one other class no more
- 11InterfacesAbstract Specification of zero or more methods
Cant contain any instance variables
Cant contain any methods
A Class can implement any number of interfaces - 12Interfaces With PolyPolymorphism in Java is also applied to interfaces. As we can definitively say a class has the capabilities defined in an interface, we can apply polymorphism without compromising type safety.
- 13Object ClassMother of all classes (Provides core functionality)
- 14GenericsRuns purely at compile time, and use type free syntax and only when an instance of a class is created is it bound to specific types
- 15Generics DefinedTypes are defined as classes or interfaces (Identifier in <> brackets) Benefits extensibility with compile time type safety
- 16RecursionAlternative method to create loops, a finite nested model of itself
Infinite loops are just as problematic in recursion as with iteration - 17Avoiding Infinite Recursive LoopsEnsure terminating case, ensure its monotonic across a state space, ensure all parts of a definition eventually lead to the terminating case
- 18Types of recursionHead Recursion - The first statement in a method is recursive
Middle / Multi Recursion - One or more arbitrary statements in a method is recursive
Tail Recursion - The final statement in a method is recursive. - 19Encapsulationprovides more coherent classes, data structure code is now independent of application code, application code is not cluttered with data structure detail
- 20ReflectionAbility of a program to introspect, and reason about its own structure
The CLASS class implements this functionality - 21The CLASS classRepresents a single class, newInstance() creates an instance of that class
- 22CLASS class and reflectionEnable runtime extensibility
- 23MutabilityAccessors - Write only if you want the variable to be visible outside the class.
Mutators - Write only if you want the variable to be mutable
Mutability is the characteristics of a type that is permitted to change value during its lifetime
Key principle in safe OO design - 24Functional ProgrammingA programming paradigm that treats
computation as the evaluation of mathematical
functions and avoids state and mutable data. - 25Console.Log();Write to console (Output)
- 26Console.Error();Write to error stream
- 27setInterval();Execute function at set time
- 28setTimeout();Execute function after a delay
- 29LetVariable that are mutable
- 30Constimmutable variable
- 31**Exponent
- 32.indexOf();Finds the index of matched item
- 33.push();Pushes an element to end of the array
- 34.shift();Pops an element from the front of the array
- 35.lengthcurrent length of an array
- 36.concat();Concatenates one array onto the end of another and returns a new array
- 37Object.keys();Returns an array of all the keys in the object
- 38Object.values();Return an array of all the values
- 39JSON.stringify();Produces a 'safe' JSON data object, without any functions!
- 40JSON.parse();Does the reverse of 'JSON.stringify()'
- 41Function JSfunction test() {
console.log("TEST);
}
test(); - 42Variable functionslet test = function() { console.log( “Just a test!” ); }
let b = test; b() - 43functions with parameterslet f = function( x ) { return x + 1; };
f(3) - 44Passing functions a functionlet f = function( x ) { ... };
function g( handler ) { return handler( 4 ); }
g( f ); - 45LambdasThere are three major technical uses for lambda use: •Searching •Sorting •Currying
- 46Lambdas Filtering[1,2,3,4,5].filter( a => a > 3 );
- 47Lambdas Sorting[1,5,3,6,-4].sort( (a,b) => a - b );
- 48Lambdas Curryingconst f = x => y => x * y;
- 49CurryingPros: Partial Evaluation
Load distribution
Cons: Can be very easily misunderstood - 50Pass by referencelet mutableData = { a: 1, b: 2 };
function alterStuff( data ) { data.a = 4; data.b--; }
alterStuff( mutableData ); console.log( mutableData ); - 51On hookEach call takes an event to match against, and a function to execute when this event occurs.
- 52JS ClassExcept this minor change - in JavaScript, unlike Java, the constructor is declared simply as 'constructor' for a given class.
- 53MapOrdering doesn't matter
- 54Reduce• accumulator - a value shared between function runs, which 'accumulates' the single result • element and index - The current element and element index to process • initialValue - What to set the accumulator to at the start
Information
- Description
- Flashcards on 212, created by Jarl Jackson on 15/05/2019.
- Created by
- Jarl Jackson
- Views
- 2
- Rating