Notes from: Introduction to Programming

This guide uses the Java language to cover programming topics.

1. Introduction to programming

00:04

Programming is important.

2. Class vs Objects

03:21

Class - is a blueprint or outline. A class manages state and behavior.
Object - is an instance of a class. An object is what lives in memory. It is the house made from the blue print.



//define a class by using "class"
class SomeClass {
    //stuff
}

//create an object by using "new"
SomeClass sc = new SomeClass();

Class constructors - "a special type of subroutine called to create an object. It prepares the new object for use, often accepting arguments that the constructor uses to set required member variables." - wikipedia
Class contructor - "a special method that is used to initialize objects. The contructor is called when an object of a class is created. It can be used to set initial values for object attributes." - w3schools

3. Constructors

04:37


Invoking the keyword new starts a process called instantiation.

Instantiation is the process of Java creating an instance of an object in memory according to the class type
Instantiation is like spawing an object. You can spawn many different houses from the same blueprint!

A constructor is a block of code that is executed when the new keyword is invoked.

The default no-arg constructor is created by the compiler if you don't write any constructors.

class A{
    //contructor
    public A(){...}
}

If you write your own constructor, then the compiler will NOT create a default no-arg constructor for you.



class SomeClass {
    int somevariable;

    public static void main(String[] args){
    ...
    }
}

its possible to overload a constructor if you specify different parameters for each constructor.

06:21

4. Encapsulation

07:03

What is Encapsulation?
Encapsulation - is the act of enclosing an item inside of a capsule or container.

In software development, encapsulation refers to the act of protecting data members from outside influence.

Data hiding is an oversimplification of the concept of encapsulation; it is partially correct.
Data hiding refers to the act of declaring member variables private, so that outside classes and other entities cannot directly access these variables.

This is a partial implementation of encapsulation, but doesnt completely describe the term in that with encapsulation you don't have to use a private modifier only.

There are others such as protected or default access levels that languages use to restrict access to data.

5. Access Modifiers

08:26

We are going to explore more about the public keyword on the main method. It is part of a group of keywords known as access modifiers. There are three of them and each controls how other classes access or call a method variable or class.

What is an access modifier? An access modifier - changes the permission levels other classes have to this method, class or variable.
An access modifier - is a keyword that you can apply to classes, methods, and instance variabels to control whether other classes are permitted to manipulate it.

There are 3 access modifiers, but there are 4 levels of access listed from least restrictive to most restrictive:

  1. public - means that all classes in any package are available to call or execute this method.
    least restrictive; all classes have access
  2. default - not an access modifier;
    only classes in the same package have access
  3. protected - Only subclasses (in any package) have access;
    classes in same package have access as well
  4. private - most restrictive;
    no classes (except inself) have access

10:25

Using an Access Modifiers

Typically, when you declare a variable or method, you'll specify an access modifier in front of it.

Classes only support the public or default level of access.

Methods and variables support all access modifiers.

Common patterns create private varaibles and public accessor methods.
Rule of thumb: Use the most restrictive access level unless you absolutely need the access.

6. Inheritance

12:27

Inheritance - Gives access to the variables and methods of one class to another.

Inheritance creats an "is-a(n)" relationship between the child and parent class. But the converse is not always true.

This relationship is one-way. All magazines are books, but not all books are magazines.

If one object is an example or a subtype of another object, the two can likely be arranged as an inheritance relationship.

For example:

A class in Java can only extend on other class.

7. Polymorphism

15:28

Polymorphism means many forms and reffers to the is-a relationship between two objects create by ineritance.

Is-A(n) Relationships

When one class extends another, an instance of that child class is also an instance of the parent class.

If one class can be described as an exmaple or subtype of another class it can probably inherit from it.

Contractual Members


A child class is guaranteed to have the public variables and methods of a super class, even if the implementations differ

This lets you write code that expects instances of a super class, but can also handle instances of child classes.

References Review


Objects are stored in heap memory, and their addresses are stored in reference variables.

reference variables use a class as a type - they can hold the address of any object that is-an instance of that class.

Dog myDog = new Dog();

Creates a new Dog object, stores the address of the Dog object in a reference variable named "myDog" that is type Dog

17:20

Reference types.
Upcasting

19:26

Method Overloading

At times you may need to have functionality in a class that supports similar types of input and output.
Instead of creating methods with really similar or unquie names, what you really need to do is employ method overloading to make your class more readable.

What is method overloading?
Method Overloading - is the creation of methods with the same name as another in the same class but it differs in parameters.

Example:
class Claculator
{
    public int add(int i, int j)
    {
        return i + j;
    }
    public double add(double i, double j)
    {
        return i + j;
    }
    public long add(long i, long j)
    {
        return i + j;
    }
}

21:13

Overridding Methods

Inheriting Methods

A method signature is the basic outline of a method:

Ex: modifiers methodName(parameters) exceptions

Any child class that you write to extend a class will inherit its methods as long as they are not marked private.

A child class can specify a new implementation for a method that is inherited.

Significance of Overriding
Overriding allows child classes to provide new implementation for their parent functionality. Useful for polymorphic references.

To override a method, you must first have a method on a parent class. In the child class, you will need to specify a mehtod of the same signature.

8. Abstraction

23:47

Abstraction - occurs when you simplify a complex thought or complex system.

When designing something, it is possible to simplfy a complex system by drawing a "black box" around the complexity and focus on the inputs and outputs of the system.
Indeed, it is sometimes helpful to break complex systems down into a network of black boxes.

The black box is an abstraction of the system.

25:02

Interfaces

An interface is a special type of construct in Java.
Used to guarantee the availability of methods in implementing classes.

All mehtods are: public abstract
All variables are public static final

Intrefaces are written similar to classes except they use the word "interface" instead of the word "class".

public interface Doable {}

public class Chore
    extends Task
    implements Doable{}

Interfaces make compiler-enforced contracts. A class that implements an interface must
A class that implements an interface must provide an implementation for every interface method, or be an abstract class
Interface methods do not have implementations and interface variables are static, so no states or behaviors are inherited

Said to have "type" inheritance. A class that implements an interface is polymorphically considered an instance of the interface.

Name interfaces for adjectives or verbs.
An interface describes what behaviors a class should have, it provides none of its own.
Ex. Runnable, Serializable, Functional

A class can implement multiple interfaces

Interfaces extend other interfaces, with no limits on the quantity allowed

Interfaces cannot extend classes, and do not implement other interfaces

Keyword:static

The static keyword determines if a method or variable belongs to the class as a whole or only an instance. What is Static?
Static - is a keyword that marks an item as a member of the class.

Recall that a class acts as a blueprint and an object is an instance of the class.

Any methods or variables that you label as static are available without having to create objects of that class type.

That main method is always labeled as static.

Keyword:final

What is Final?
Something marked final means that it cannot change its value.

If a variable is marked final, then code cannot change its value once set.

If a method is marked final, then code in subclasses cannot override it.
If a class is marked final, then another class cannot extend it.

9. Loop Statements

29:58

What is a while loop?
A while loop will repeat a block of code based on a condition; it essentially tells the program to start back up at the top from where it is defined.

while (condition)
{
    ...
}

What is a Do-while loop?
A do-while loop, will execute its statements at least once, and then continue repeating them based on a condition.

do
{
    ...
} while (condition);

10. Data Structures

32:38

Variables are not sufficient to organize data.
Data structures are used to organize data.

Arrays - a linear collection of variables of same size, and often type.
Arrays are core to most languages.

What if you don't care about memory adjacency and would like to grow or shrink the array length as needed?

Vectors or Lists are:
36:13
Linked Lists
37:21
Maps / Dictionaries

11. Exceptions

38:05

Exceptions

The throws Clause

11. SQL DB

39:42

Data Organization

40:26
Relational Databases
41:18
SQL
42:31
SQL Sub-Laqnguages
43:42
Column Datatypes
45:47
Table Constraints
Column attributes that restrict data
48:35
What is a join?
A Join is an operation that combines the results of two tables.

Common types of joins:
49:30
Define and construct a simple WHERE clauses. Where clauses
Basic Sytax

A WHERE clause is appended to the end of a SELECT statement.

SELECT STATEMENT WHERE condition;

The condition indicates a column to filter and any comparison operators and values.

Ex:
SELECT * FROM EMPLOYEES WHERE
employee_id > 5;

12. HTML/CSS

50:58

HTML

Example of a sample HTML document:

<!DOCTYPE html>
<html>

    <head>
        <title>My First Webpage</title>
    </head>

    <body>
        <p>A paragraph</p>
    </body>

</html>

Element - a set of tags and their enclosed content. Everything higlighted is part of the element: <tag>content</tag>

Highlighted is an example of a paragraph element:
<p>We went to the park.</p>

Tags:

Highlighted is an example of a paragraph tag:
<p>We went to the park.</p>

Some tags are composed of both an opening tag and closing tag:
<tag attribute="value">content</tag>

A tag can also be a self closing tag:
<selfclosingtag/>

Attributes examples:


54:30
Tables

Webpage design naturally fits a grid system:
56:23
Lists
58:06
Responsive Web Design
59:00
Designing Webpages
  1. Design for the smallest size first; increase afterwards.
  2. Lines of text should be 8 to 10 words long.
59:23
Coding Responsive Webpages:
1:00:14
Best Practices
1:00:42

CSS Syntax

Summary
1:02:15

CSS Selectors

Types of Selectors
1:02:33
Element Selector: tagname
Selects a specific tag
1:03:15
Class Selectors .
1:03:50
ID Selectors #
1:04:25
Universal Selector *
1:04:45
Selecting Multiple Elements ,
1:05:18
Parent-Child Selector >
1:05:58
Ancestor-Descendant Selector
1:06:22
Sibling Selector +
1:07:00
Summary

1:07:14

13. JavaScript

JavaScript is a programming language that provides instructions to a web browser.

1:08:28
Including JavaScript
1:10:26
A datatype is a specialized form of information (number, string, etc.)

1:10:59
javaScript Datatypes
1:12:54
Using Variables in JavaScript
1:13:39
Naming Rules
  1. follow camelCase convention
  2. names must begin with letter, _,or $
  3. numbers, and Unicode escape sequences can be used after the first character
  4. names are case-sensitive:
  5. numOfTurns is not equal to NumOfTurns
1:14:57
Variable Assignment
  1. Use the equals sign (=) to assign a value to a variable
1:15:41
Variable Re-Assignment

var a;
a = 25;
a = 13; //the variable has a new value
a = 'hello'; //the variable has a new data type
1:16:01
Re-Assigning to Null
  1. To set the value of a variable to an empty value use null
  2. var a = 23;
    a = null;