College Advide – #WSQ10

--Originally published at My Programming Course

En este WSQ Joel nos da unos avisos, 7 de los cuales son escenciales:

  1. Learn how to write before graduating.
  2. Learn C before graduating.
  3. Learn microeconomics before graduating.
  4. Don’t blow off non-CS classes just because they’re boring.
  5. Take programming-intensive courses.
  6. Stop worrying about all the jobs going to India.
  7. No matter what you do, get a good summer internship.

En los cuales concuerdo en la mayoría. Los dos primeros puntos creo que son escenciales para el transcurso de la carrera, no necesariamente hasta el final. Siempre tenemos que asistir a clases para aprender todo lo que podamos. Que no nos importe o nos detenga salir fuera y que al final podemos darnos el lujo de tener un buen descanso.

 

Ward Cunningham

--Originally published at TC201 Winter 2016 Jorge

Mr. Ward Cunningham, th creator of the Wiki, started with a little database made of cards using Hyper Card(It combines databse capabilities with a graphical, flexible, user-modifiable interface.) because his goal was the absortion of technology amongts technologist, and he made a database out of cards that tracked how ideas moved throught his company.

I find it really impressive how can just one person think of an idea to help himself and his company and it ends up being one of the most used tools amongts students and researchers or whoever uses it to find any kind of information, like, almost all kinds of concepts and information can be found there.

At some point of the interview the guy asked what should students learn or something like that and Ward replied that we should learn what a boolean variable is, jquery and javascript. I guess I'll be a little bit busy this summer.

Ward Cunningham

Mr. Ward Cunningham, th creator of the Wiki, started with a little database made of cards using Hyper Card(It combines databse capabilities with a graphical, flexible, user-modifiable interface.) because his goal was the absortion of technology amongts technologist, and he made a database out of cards that tracked how ideas moved throught his company.

I find it really impressive how can just one person think of an idea to help himself and his company and it ends up being one of the most used tools amongts students and researchers or whoever uses it to find any kind of information, like, almost all kinds of concepts and information can be found there.

At some point of the interview the guy asked what should students learn or something like that and Ward replied that we should learn what a boolean variable is, jquery and javascript. I guess I’ll be a little bit busy this summer.

Ward Cunningham

Mr. Ward Cunningham, th creator of the Wiki, started with a little database made of cards using Hyper Card(It combines databse capabilities with a graphical, flexible, user-modifiable interface.) because his goal was the absortion of technology amongts technologist, and he made a database out of cards that tracked how ideas moved throught his company.

I find it really impressive how can just one person think of an idea to help himself and his company and it ends up being one of the most used tools amongts students and researchers or whoever uses it to find any kind of information, like, almost all kinds of concepts and information can be found there.

At some point of the interview the guy asked what should students learn or something like that and Ward replied that we should learn what a boolean variable is, jquery and javascript. I guess I’ll be a little bit busy this summer.

Ward Cunningham

Mr. Ward Cunningham, th creator of the Wiki, started with a little database made of cards using Hyper Card(It combines databse capabilities with a graphical, flexible, user-modifiable interface.) because his goal was the absortion of technology amongts technologist, and he made a database out of cards that tracked how ideas moved throught his company.

I find it really impressive how can just one person think of an idea to help himself and his company and it ends up being one of the most used tools amongts students and researchers or whoever uses it to find any kind of information, like, almost all kinds of concepts and information can be found there.

At some point of the interview the guy asked what should students learn or something like that and Ward replied that we should learn what a boolean variable is, jquery and javascript. I guess I’ll be a little bit busy this summer.

Can’t stop procastinating. (Second Partial Questions Review)

--Originally published at GilbertoRogel

After about 13 hours of trying to start studying i finally managed to do so. Here's a little study guide i made from the help of the Internet and other people's blogs: (INHERITANCE AND POLYMORPHISM ARE ON MY 1ST PARTIAL STUDY GUIDE POST)

Delegation: When an object receives a request, the object can either handle the request itself or pass the request on to a second object to do the work. If the object decides to pass the quest on, you say that the object has forwarded responsibility for handling the request to the second object.

CRC Cards: Class, Responsibilities, collaborators. Although CRC cards were originally introduced as a technique for teaching object-oriented concepts, they have also been successfully used as a full-fledged modeling technique.

Class: represents a collection of similar objects.

Responsibilities: something that a class knows or does.

Collaborators: another class that a class interacts with to fulfill its responsibilities

Overloading (compile time) and overriding (runtime): The most basic difference is that overloading is being done in the same class while for overriding base and child classes are required.

OVERLOADING: Method overloading in Java occurs when two or more methods in the same class have the exact same name but different parameters.

Also a valid case of overloading, since the   //parameters are of different types:   

int changeDate(float Year) ; 

int changeDate(int Year); 

OVERLOADING EXAMPLE

//A class for adding upto 5 numbers

class Sum {

    int add(int n1, int n2) {

        return n1+n2;

    }

    int add(int n1, int n2, int n3) {

        return n1+n2+n3;

    }

    int add(int n1, int n2, int n3, int n4) {

        return n1+n2+n3+n4;

    }

    int add(int n1, int n2, int n3, int n4, int n5){

        return n1+n2+n3+n4+n5;

    }

    public static void main(String args[]){

         Sum obj = new Sum();

         System.out.println("Sum of two numbers: "+obj.add(1, 2)); //3

         System.out.println("Sum of three numbers: "+obj.add(1, 2, 3)); //6

         System.out.println("Sum of four numbers: "+obj.add(1, 2, 3, 4)); //10

         System.out.println("Sum of five numbers: "+obj.add(1, 2, 3, 4, 5)); //15

    }

}

Here we have 4 versions of same method “add” which means you’re overloading the method add().

OVERRIDING: An overridden method would have the exact same method name, return type, number of parameters, and types of parameters as the method in the parent class, and the only difference would be the definition of the method.

OVERRIDING EXAMPLE

class Car{
    public int speedLimit(){
        return 100;
    }
}
class lilCar extends Car{
    public int speedLimit(){
        return 150;
    }
    public static void main(String args[]){
         Car obj = new lilCar();
         int num= obj.speedLimit();
         System.out.println("Speed Limit is: "+num); //150
    }
}

Here speedLimit() method of class lilcar is overriding the speedLimit() method of class CarClass.

  • What do you feel are the benefits to object-oriented programming?
  • Why do you think your change to object-oriented programming is difficult or what makes it difficult for the standard student?  

These two questions are more subjective so i'll let them be. 

Usefull Links: Delegation    CRC Cards    Overloading and overriding      More overloading and overriding

 

Gilberto Rogel García a01630171

Library Assignment

--Originally published at TC201 Winter 2016 Jorge

The libraries of SmallTownX need a new electronic rental system, and it is up to you to build it. SmallTownX has two libraries. Each library offers many books to rent. Customers can print the list of available books, borrow, and return books.

Problem: We provide two classes, Book and Library, that provide the functionality for the book database. You must implement the missing methods to make these classes work.

Doing this wsq was quite challenging but at the end I managed to do it. I watched some videos in yutube and checked some code on the internet that helped me think the proper way on how to solve this library assignment problem. If you want to go to my github repository to check out the code, click here.

#TC201 #Topic4 What is delegation?

--Originally published at Venkon Programming

Delegation is a technique where an object expresses certain behavior to the outside but in reality delegates responsibility for implementing that behaviour toan associated object. This sounds at first very similar to the proxy pattern, but it serves a much different purpose. Delegation is an abstraction mechanism which centralizes object behaviour.

The delegation design pattern allows an object to delegate one or more tasks to a helper object. Two classes are used to achieve this: the delegate and delegator, both which realise a common interface. A method (or methods) on the interface represent the functionality to be delegated. A call to the delagtor calls the matching function on the delegate.

STUDY GUIDE

--Originally published at GilbertoRogel

What is an object, attribute and method? 

An object is an instance of a class - it's a concrete 'thing' that you made using a specific class. So, 'object' and 'instance' are the same thing, but the word 'instance' indicates the relationship of an object to its class.

This is easy to understand if you look at an example. For example, suppose you have a class House. Your own house is an object and is an instance of class House. Your sister's house is another object (another instance of class House). ObjectObject

Attributes are also data members and properties of a class, they are varaibles declared inside class, they describe the current state of an object.

Methods perform operations on objects that alreaedy exist, methods must be declared to return something, although it can be void.

What is abstraction? 

Abstraction is the process of hiding the implementation details and showing only the functionality. It is used to hide certain details and only showing essential features of the object. chozacastro´s blog

Example from Lynda: 

Lynda video example

This represents the superclass "Shape" which is also an abstract class. You can see it's an abstract class because of the "abstract" before "class Shape".

This class also has an abstract method which doesnt have any code inside because every subclass will make use of this method differently.

This is a subclass called "Rectangle" of the superclass "Shape" thats why we put "public lass Rectangle extends Shape, to make sure Rectangle is a descendant of Shape.

As you can see the class Rectangle is using the method CalculateArea with some code inside that will do the process of getting the area of the rectangle

So this is another subclass of the superclass Shape, this time it represents a Triangle and it has a method also called CalculateArea but with a different code than Rectangle because to calculate the area of a triangle is different than to calculate an area of a rectangle so obviously the method has to be different and this is what abstraction is for, to change the inside of the abstract method as many times as we want in the subclasses.

Finally, this is the main class.

Here we created the Shape "rectangulo" as a new Rectangle so when we use the method calculateArea() it will use the method in the subclass Rectangle and not the one in the subclass Triangle and as you can see it worked. I put 10 and 15 for lenght and width and it showed that the area is 150 which is correct.

Then we created the Shame "triangulo" as a new Triangle so when we use the method calculateArea() it will use the method in the subclass Triangle and not the one in the sublcass Rectangle and as you can see it worked again. i put 10 and 15 again but this time for height and base and the area is of course 75 because 10*15= 150 and 150/2 = 75.

 

 What is encapsulation?

In encapsulation the variables of a class will be hidden from other classes, and can be accessed only through the methods of their current class, therefore it is also known as data hiding. Luis Varga's blog

-Allows the programmer to hide the instance data definition.

-Protects the integrity of the instance data.

-Hides the methods implementatios, this ensures that data structures and operators are used as intended.

-Prevents outside access with protective barrier

Encapsulation Lynda Video

What are "has-a" and "is-a" relationships?

The has-a relationship means that one type of object contains another or is composed of another. Some examples are: a car has-an engine, a bicycle has-a wheel, and a coffee cup has coffee.

The is-a relationship means that one type of object is a more specific version of a general type. Some examples are: a car is-a vehicle, a bicycle is-a vehicle, and a coffee cup is-a cup. The is-a relationship is modeled with inheritance. Abstraction, "Has-a" "Is-a" Relationships, Encapsulation

What are the mechanics for class description (coding) in the JavaProgramming Language?

  • Defining a class creates a new object type with the same name
  • Every object belongs to some object type, it is an instance of some class
  • A class definition is like a template for objects: it specifies what attributes the objects have and what methods can operate them
  • The methods that operate on a type are defined in the class definiton fot that type Luis Vargas blog

What are visibility modifiers, their purpose and use in practice?

Public, Private, Protected and Package Protected(No Modifier)

Public

Public is the most well known of the Java keywords. Public is also the easiest of the Java access modifiers because of its nature. A variable or method that is public means that any class can access it. This is useful for when the variable should be accessible by your entire application. Usually common routines and variables that need to be shared everywhere are declared public. 

Private

Private helps to encapsulate your methods and variables most effectively. What do I mean by encapsulate? I mean that only things that should be able to access those methods and variables can do so. There is actually only one way a private method or variable can be accessed: within the class that defined them in the first place. Private variables and methods are those that are meant to be directly accessed by the Java class that owns them.

Protected

Protected variables and methods allow the class itself to access them, classes inside of the same package to access them, and subclasses of that class to access them.

Package Protected (No Modifier)

What happens if you do not put any of the Java access modifiers on your methods and variables? Java will still compile your code, so what gives? No access modifier at all means that the method or variable defaults to package protected. This means that only the same class and any class in the same package has access. You get all of the same access as protected minus the ability for subclasses to access the method or variable (unless the subclass is in the same package).
Java made easy

What is inheritance and Polymorphism?

Inheritance

Different kinds of objects often have a certain amount in common with each other. Mountain bikes, road bikes, and tandem bikes, for example, all share the characteristics of bicycles (current speed, current pedal cadence, current gear). Yet each also defines additional features that make them different: tandem bicycles have two seats and two sets of handlebars; road bikes have drop handlebars; some mountain bikes have an additional chain ring, giving them a lower gear ratio.

Object-oriented programming allows classes to inherit commonly used state and behavior from other classes. In this example, Bicycle now becomes the superclass of MountainBike,RoadBike, and TandemBike. In the Java programming language, each class is allowed to have one direct superclass, and each superclass has the potential for an unlimited number ofsubclasses:

STUDY GUIDE

The syntax for creating a subclass is simple. At the beginning of your class declaration, use the extends keyword, followed by the name of the class to inherit from:

class MountainBike extends Bicycle {

    // new fields and methods defining 
    // a mountain bike would go here

}

This gives MountainBike all the same fields and methods as Bicycle, yet allows its code to focus exclusively on the features that make it unique. This makes code for your subclasses easy to read. However, you must take care to properly document the state and behavior that each superclass defines, since that code will not appear in the source file of each subclass. Inheritance

Polymorphism

It allows you to have the same name for a method, but it acts differently based on the class that has that method defined.

For example: Animal is a superclass with the speak method and Dog, Cat and Pig are Subclasses of Animal but each one of them speak differently, a Dog barks, a Cat meows and a Pig Oinks which means you have to redefine the speak method for each class depending on how they comunicate.

So Polymorphism is saying that it has the same method name (speak) but the actions that are performed are dependent on the class.

Polymorphism Lynda video

 

Gilberto Rogel García

Special thanks to Luis Vargas, this wouldnt have been done without your help.

#TC201 #Topic3 What is encapsulation?

--Originally published at Venkon Programming

 

Encapsulation in Java is a mechanism of wrapping the data (variables) and code acting on the data (methods) together as a single unit. In encapsulation the variables of a class will be hidden from other classes, and can be accessed only through the methods of their current class, therefoe it is also known as data hiding.

To achieve encapsulation in Java

  • Declare the variable of a class as private
  • Provide public setter and getter methods to modify and view the variables values.

Encapsulation is used to reduce dependencies, so if you want to change something you can change it and it won't affect other classes because it was encapsulated and it only affects that class.

Example:

#TC201 #Topic3 What is encapsulation?

Source: Encapsulation