A data structure is a construct, such as a class or an array, within a programming language.
Dynamic Data Structures
Data sizes can grow and shrink while the program is running
Data sizes can grow and shrink while the program is running
Þ ArrayList (Java Class Library)
Þ LinkedList (Inner Classes)
Generic Types
class definitions with data types parameters
A linked list is a dynamic data structure that links the items in a list to one another
A linked list consists of objects known as nodes.
The nodes are the boxes that are divided in half by a horizontal line.
Each node has a place for some data and a place to hold a link to another node.
The links are shown as arrows that point to the node they “link” to
Generics is one of the core feature of Java programming and it was introduced in Java 5
Generics refer to parameterized classes.
The parameter is a Base_Type that is replaced by any reference type when an object of the parameterized class is created.
e.g. ,
ArrayList<T> arrayListObject = new ArrayList<T>();
We can define our own classes and interfaces with generics type.
In generics, we use angle brackets (<>) to specify the type parameter
When using a parameterized class, you need to specify the type (Reference Type) of the objects that the class will deal with.
A class definition with a type parameter is stored in a file and compiled just like any other class.
After a parameterized class is compiled, the compiled class may be used in a program just like any other class.
A class type must be plugged-in for the type parameter when the parametrized class is instantiated.
The type to be plugged-in for the parameter type when instantiating a Generics class must be a REFERENCE TYPE.
When utilizing the class described in a previous slide, the following is NOT correct.
MyClass<int> sample1 = new MyClass<int>(5);
When utilizing the class described in a previous slide, the following is CORRECT.
MyClass<Integer> sample1 = new MyClass<Integer>(5);
Autoboxing/Unboxing
automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes.
For example, converting an int to an Integer, a double to a Double, and so on.
A parameterized class definition can have any number of type parameters
Multiple type parameters are listed in angular brackets separated by commas.
Functional programming (FP) is a programming paradigm.
It emphasizes the use of pure functions that don't have side effects and always return the same output for a given input.
Functional Programming
The basic objective of this style of programming is to make code more concise, less complex, more predictable, and easier to test compared to the legacy style of coding.
Basically, functional programming is a style of writing computer programs that treat computations as evaluating mathematical functions.
In mathematics, a function is an expression that relates an input set to an output set.
Higher-order functions
In functional programming, functions are to be considered as first-class citizens.
A function is called pure function if it always returns the same result for same argument values and it has no side effects like modifying an argument (or global variable) or outputting something.
A Lambda expression is an anonymous method that has mutability at very minimum and it has only a parameter list and a body.
In lambda expressions, the return type is always inferred based on the context.
Lambda expressions work in parallel with the functional interface.
Lambda Expression
• nameless function
In functional programming, a function is the same thing as a method.
lambda expressions
is essentially a little snippet of code that you can pass around as data but have it treated like a function with parameters.
lambda expressions help Java parallelize itself to run more efficiently on multicore or multiprocessor machines.
normally we will process elements in an ArrayList by creating a for loop that accesses each element one by one.
This is considered external access to the loop.
with lambda expressions we can internally iterate through the ArrayList by providing a function that tells Java how to process each element.