No, not that Gosling

--Originally published at Ce qui est chouette

Now onto Triangulation’s 245th episode, an interview with the creator of Java, undercover-engineer, James Gosling. What’s the deal with airplane food? And this interview, of course:

  • There’s more solutions to one problem. As Gosling said Java came out of laziness, in place of a Pascal compiler. Thinking out of the box shenanigans, but good shenanigans.
  • Being a spy is cool. Gosling “broke into” his university’s facilities to learn to program, programming’s that cool; spies go a long way to program.
No, not that Gosling
“The Stanford Dish” in flickr by Todd Lappin under a CC license.

-The about ‘ese’


No, not that Gosling

Overloading vs. Overriding

--Originally published at Orientierteprogrammierungobjekteundetwasmehr

Overloading vs. Overriding

Serendigity. “Overload” Online Image. Flickr. Octover 3, 2007. https://www.flickr.com/photos/maleny_steve/1473552769/

Overloading and overriding are two similar concepts -they both are about creating several methods with the same name- but very different when it comes to practical functionality and implementation.

Overloading (formally, static polymosrphism) is resolved at compile time, and it is when the methods with the same name are declared in the same class, distinguished only by their signatures (the parameters of the method), so when the compiler knows which method overload you are calling based on the data type of the arguments you are passing.

Overriding (or overwriting, according to ken), is resolved at runtime and it is when you define a method that is already defined in a parent class. It can be resolved because of the data type of the “implicit first parameter” (aka, the object itself).

Java implementation

Overloading

Overloading vs. Overriding

Overloading with different data types and number of parameters.

Overloading vs. Overriding

Overloading with same data types and number of parameters, but different order.

Overloading vs. Overriding

Overloading allow different return types.

Overloading vs. Overriding

The return type of the method is not considered when overloading.

Overriding

Overloading vs. Overriding

In this example of overriding I have the Person abstract class, this class cannot be instantiated, but it provides like a “template” for its children classes. For example, the Person class has a String field “name”, because every person has a name, and a public method “talk” because all persons can talk (ok, almost all), this method prints “I’m a ” to the console, because, like I said, this is like a template, and different persons have different (very interesting) things to say. The method “getName” returns the name of the person. The constructor just takes the String name, although you can’t call this constructor directly, it can be called from its children classes.

It’s children classes are not abstract and extend (are children of) the Person class. They implicitly have “name”, a method “talk” and a method “getName”. Read the code of the Student and the Teacher classes and note how the constructors have a line “super(name)”, this is a call to the parent class constructor, and it will throw an error if it’s not there. Both the Student and the Teacher class Override the talk method, the notation @Override over the talk method just tells the compiler that you are overriding a method (no shit, Sherlock), it’s not required but you should use it to enforce proper overriding of a method. The talk() methods of Student and Teacher call the “super.talk” method (unlike the constructor, you can miss this statement here and there will be no errors), it prints “I’m a “, and then it prints something else. I also included an Overload of an Overriding method (mind blown) in the Student class to show the difference, it just prints “I love” + the argument (there is no call to super.talk()).

In the main method of the Person class I declare 2 persons, one teacher and other student, also, I declare a Student as a Student, this sound stupid but actually affects in the code. The preferred way is to declare the variable with the data type of the abstract class and instantiate it as the type that you actually want to use (Declared type on the right and Actual type on the left), so your code is not dependent from a specific implementation of an interface/abstract class. You can read more about this here. You can see that when the talk method is called from both the teacher and the student they print different things. Finally, to call the Overload method “talk(String food)” of “s” (with Declared type Person and Actual type Student) you have to implicitly cast it to Student and then call the method, like ((Student)s).talk(“tacos”), this is because this implementation is not declared in the Declared type of “s”. However, with “c” this does not happen, you can call that overload method because the Declared type of “c” is Student. Anyway, this is not considered a good OO practice, you should avoid writing methods that are not in the parent class, because there is a method specific to the Children class, and therefore making the code dependent from that class, and what you want is to make the code independent from specific implementations of the children class (like explained in the previous stack overflow link).

Overloading vs. Overriding


Overloading vs. Overriding

#WSQ11-Library

--Originally published at Blog

And this is the most boring wsq that I have ever done!
Because all it asked of me was filling the blank methods with just some return statements in most cases.
The most interesting I did in this assignment was doing a for loop and throwing some exceptions.

So i entered the WSQ11 blog post in kenscourses and clicked the first link because I’m too lazy to read.
And the first thing I notice is that I don’t know what to do here, obviously, instead of go back and read the instructions I started doing the first assignment.
#WSQ11-Library

After some dedication and hard work doing that thing about gravity I realized it was too stupid, so I deleted all the files, including System32.

So now I had the tough task of reading the instructions.
According to the English dictionary of Cambridge, the word “to” is pronounced as “tu”.
The instructions said that I should try to “tutu” the Library assignment.
#WSQ11-Library

All I did in the book class was add some fields, getters and setters.
#WSQ11-Library

And in the Library class I just used the Book class to create the simulation of a library.
It also asked me to create a static method, I was so excited.
#WSQ11-Library

After that I kept reading and clicked on a link, and the first thing a saw was a big message saying “Buy my book!”, it was so gross that I had to leave the site.
#WSQ11-Library

github


#WSQ11-Library

WSQ10 – College Advice

--Originally published at Alan TC201

I was very impressed of the fact that this blog post has aged very well. It was published in 2005 by Joel Spolsky, and a lot of things he said are still relevant in 2016. The points that interested me the most was about try to learn C, not C++, Java or python. C is the mother language so if you understand C is very probable it will be easier to learn about their sons. Like some people say, if you learn latin in will be a lot easier to learn its derivatives.WSQ10 – College AdviceWSQ10 – College Advice

The second one was the one that said to learn microeconomics. It is very common that you have your work and that everything you do will be about that specific job, that everything else will be fix or ready for you, but no, you need to be prepared to face different situations, one of them seems to be the economic one, maybe you are an awesome programmer but if you do not know how the world works it will be very difficult to get used to it.

WSQ10 – College Advice

The last thing is about de good summer internship, that is easy to say than done, in my country this types of things tend to cost a lot, and in the summer is the time when I save money to bought the books and things I need for the next semester of study. So when the opportunity comes I sure will try it out.

WSQ10 – College Advice


WSQ10 – College Advice

Project update #01

--Originally published at Blog

the team members are:

  • Hermes Espínola González
  • José Andrés Choza
  • Juan Salvador Fernández
  • Gerardo Cruz

The idea of the project is create a video game where the objective is fight in an arena.
Due to the fact that we don’t know anything about 3D modeling and animation, we will use creative commons assets from the unity asset store.
We have already implemented the movement of the character.

Project update #01

For the artificial intelligence we will be using a plugin for unity called RAIN. We are reading the documentation and trying to create our first AI character.


Project update #01

WSQ07 – Babylonian Method in JAVA

--Originally published at Alan TC201

This babylonian method was a little difficult, simply because compared to python, Java has a very weird syntax. I had to use a method of this person that I foun on the internet. (http://www.dreamincode.net/forums/topic/43600-babylonian-algorithm/)

Here is a link to understand Babylonian Method  (https://www.deltacollege.edu/dept/basicmath/Babylonian.htm)

Something new that I use in the s program was the scaner (http://puntocomnoesunlenguaje.blogspot.mx/2012/08/java-scanner.html)

WSQ07 – Babylonian Method in JAVA

BLOG POST NOT FINISH

WSQ07 – Babylonian Method in JAVA


WSQ07 – Babylonian Method in JAVA

Masterie: visibility modifiers in Java

--Originally published at Alan TC201

Masterie: visibility modifiers in Java

“Java provides a number of access modifiers to set access levels for classes, variables, methods and constructors. The four access levels are:

  • Visible to the package. the default. No modifiers are needed.
  • Visible to the class only (private).
  • Visible to the world (public).
  • Visible to the package and all subclasses (protected).

Default Access Modifier – No keyword:

Default access modifier means we do not explicitly declare an access modifier for a class, field, method, etc.

A variable or method declared without any access control modifier is available to any other class in the same package. The fields in an interface are implicitly public static final and the methods in an interface are by default public.”
Info( http://www.tutorialspoint.com/java/java_access_modifiers.htm)

Controlling Access to Members of a Class

Access level modifiers determine whether other classes can use a particular field or invoke a particular method. There are two levels of access control:

  • At the top level—public, or package-private (no explicit modifier).
  • At the member level—public, private, protected, or package-private (no explicit modifier).

A class may be declared with the modifier public, in which case that class is visible to all classes everywhere. If a class has no modifier (the default, also known as package-private), it is visible only within its own package (packages are named groups of related classes — you will learn about them in a later lesson.)

At the member level, you can also use the public modifier or no modifier (package-private) just as with top-level classes, and with the same meaning. For members, there are two additional access modifiers: private and protected. The private modifier specifies that the member can only be accessed in its own class. The protected modifier specifies that the member can only be accessed within its own package (as with package-private) and, in addition, by a subclass of its class in another package.

The following table shows the access to members permitted by each modifier.

Access Levels
Modifier Class Package Subclass World
public Y Y Y Y
protected Y Y Y N
no modifier Y Y N N
private Y N N N

The first data column indicates whether the class itself has access to the member defined by the access level. As you can see, a class always has access to its own members. The second column indicates whether classes in the same package as the class (regardless of their parentage) have access to the member. The third column indicates whether subclasses of the class declared outside this package have access to the member. The fourth column indicates whether all classes have access to the member.

Access levels affect you in two ways. First, when you use classes that come from another source, such as the classes in the Java platform, access levels determine which members of those classes your own classes can use. Second, when you write a class, you need to decide what access level every member variable and every method in your class should have.

Let’s look at a collection of classes and see how access levels affect visibility. The following figure shows the four classes in this example and how they are related.

Masterie: visibility modifiers in Java

Classes and Packages of the Example Used to Illustrate Access Levels

The following table shows where the members of the Alpha class are visible for each of the access modifiers that can be applied to them.

Visibility
Modifier Alpha Beta Alphasub Gamma
public Y Y Y Y
protected Y Y Y N
no modifier Y Y N N
private Y N N N

Info (https://docs.oracle.com/javase/tutorial/java/concepts/)

 

BLOG POST NOT FINISH, THIS IS ONLY THE INFORMATION

Masterie: visibility modifiers in Java

 

 


Masterie: visibility modifiers in Java