All posts by Ademir Constantino

About Ademir Constantino

Senior Software Engineer

Being at the 30’s

Well, this post is a little bit different from most of the things I write here. First, this is very personal, somehow thought.

What makes me wonder is about being stuck at some point in my life. I graduated at the age of 24, and this was by far the most big achievement I had. Still single, no family. It makes me wonder about what I really want to build out from my life.

The thoughts of moving and really settle down in another country consumed my mind and energy for a long period, and didn’t happen because of some importance here.

The key subject here is… after graduading you have to work a lot, and life passes faster. I am currently enrolled in a master’s degree which finally I can see what I will do to finish this.

Knowledge and music is the only thing that matters to me, and even living with student flatmates doesn’t make me worry too much.

Maybe being a master at the age of 35 (at least) will be something important. Knowledge is the key, all I have. Some certificates in the future, may be.

That is all,

Regards,

Ademir

Bill Gates letter to hobbyists

Hey guys, today I am here to share with you something very interesting about what happened in the 70’s when code was shared by hobbyists which used to develop software in the universities.

I just knew this after watching the movie Revolution OS (which is very nice indeed), and the purpose of this post is to show you who was the “enterprising” mind behind corporative software: Bill Gates — and I just don’t want to make the idea I am against him, of course not, since I believe he did a lot for computer science and Microsoft looks like is changing their minds to open source software since cloud computing took the scene.

There it follows the e-mail Bill Gates sent to the hobbyists encouraging them to make money with software and closing codes/patents — whatever:

bill_gates_letter_to_hobbyists-791x1024

ps:  A very interesting movie to watch is the Revolution OS — a movie about Linux, which tells a bit about Linux, GNU the all the Open Source Software and initiatives. You can find it on: http://topdocumentaryfilms.com/revolution-os/

That is all for today, hope you like it. 😉

Deadlock from Multithreading

INTRODUCTION

The objective of this small article is to give an introduction about threads, deadlocks and how a dead lock may occur illustrated with code using the Java programming language. At the end, I give my personal point of view about the subject.

MULTITREADING

A thread can be defined simply by “a separated computation process” that may be a children of other threads – or a main program (Savitch, 2010). Threads can also operate in a parallel manner, what means multiple computation processes sharing same resources, and running for a common goal.

In Java, this can be achieved by using the Thread class, which offers support for implementing single and multithread applications.

 deadlock4

Figure 1 Illustration of a Thread Program in Java

The code figure above shows a simple thread program coded up with the Java language. Basically, this illustrates one thread instanced by the Thread class. The ThreadExample1 class is just an implementation of Runnable, one of the ways of implementing threads with the Java programming language.

 deadlock2

Figure 2 Example of a Multithreading application in Java

When running the code above, will give the output of:

:/

:/

Is off

:/

Is on

Is off

Is on

Is off

Is on

Is off

:/

Table 1 Ouptut of the program

DEADLOCK

Deadlock is defined by WhatIs.com, 2016 as A deadlock is a situation in which two computer programs sharing the same resource are effectively preventing each other from accessing the resource, resulting in both programs ceasing to function.

deadlock

Figure 3 An illustration of a dead lock

The figure above illustrates a deadlock occurring on the traffic. What happens is that all the cars are trying to access the same resource at the same time, what locks the traffic to flow.

DEADLOCK IN JAVA

“When in doubt, synchronize.”

(Goetz, 2001)

The Java programming language offers synchronization resources in order to prevent dead locks. What happens is that at every variable that is overwritten using multiple threads, it is strictly recommended that you use synchronization.

Example of a potential synchronization deadlock:

deadlock5

Figure 4 Using the synchronization resource (Goetz, 2001)

Image a scenario while thread A calls oneMethod(), while thread B calls anotherMethod(). What happens is that thread A gets the lock on cacheLock and at the same time thread b gets the lock on tableLock. Now the threads are deadlocked.

TIPS TO PREVENT DEADLOCKS IN JAVA

According to the StackOverflow, 2016 forum, some good tips to avoid deadlocks are:

  • Always use lock free data-structures;

  • Release locks after a timeout period;

  • Always acquire the locks in the same order.

CONCLUSION

Deadlocks are a very sensible threat to every program which uses multithreading programs sharing the same resources. While debugging and simulating dead locks are difficult because it needs timing and also it may not occur because of environment and machine load. The Java programming language offers resources to deal with deadlock issues, however it is more of a programmers responsibility to avoid this problem.

REFERENCES

Savitch, W, 2013. Absolute Java. 5th ed. USA: Pearson.

WhatIs.com. 2016. What is deadlock? – Definition from WhatIs.com. [ONLINE] Available at: http://whatis.techtarget.com/definition/deadlock. [Accessed 01 May 2016].

Blogspot. 2016. Figure of a deadlock. [ONLINE] Available at: http://3.bp.blogspot.com/-Whe-8HEWtRs/UAJwpICqPjI/AAAAAAAAAeQ/4XFtKnj1-JE/s1600/Comxf.jpeg. [Accessed 1 May 2016].

Brian Goetz. 2001. Avoid synchronization deadlocks | JavaWorld. [ONLINE] Available at: http://www.javaworld.com/article/2075692/java-concurrency/avoid-synchronization-deadlocks.html. [Accessed 01 May 2016].

Multithreading – Tips to prevent deadlocks in java. 2016. Stack Overflow. [ONLINE] Available at: http://stackoverflow.com/questions/16780937/tips-to-prevent-deadlocks-in-java. [Accessed 01 May 2016].

Multiple Inheritance

INTRODUCTION

The main objective of this small article is to provide an introduction about the multiple inheritance subject, give an overview how it is implemented with the Java programming language and my considerations to conclude.

THE INHERITANCE CONCEPT

The concept of inheritance is very close to what we have in genealogy. Fathers share common attributes with sons, whom all share common attributes from its parents, grandparents and so on. Yet, all of them have their own particularities, like eye color, hair color, etc…

xid-94316198_6Figure 1 Illustration of Genealogy

THE INHERITANCE CONCEPT IN PROGRAMMING LANGUAGES

According to Sklenar, 1997, Simula is known and considered as the first object oriented programming language. This is based on the concept of the conceptualization of the real world brought up to the computing space.

The key aspect of objected oriented programming is to simulate the real world conceptualization of how things are designed, organized and oriented. One of these aspects is the inheritance concept, which is defined and illustrated by Oracle, 2016 as: object-oriented programming allows classes to inherit commonly used state and behavior from other classes. The figure below illustrates the inheritance in a bicycle illustrated analogy:

 

xid-94316199_6

Figure 2 Illustration of inheritance

MULTIPLE INHERITANCE

The concept of multiple inheritances can be illustrated with genealogy indeed. Father and mother share common aspects with their children the same way grandparents share commons aspects and particularities.

Although multiple inheritances to do not be implemented by some objected oriented programming languages, it is very common to happen in different manners.

IMPLEMENTATION ON THE JAVA PLATFORM

It is widely known that Java does not support multiple inheritance, however Java 8 implements functional interfaces (a resource very similar and that can be compared pretty much the same) which are very similar to the concept of multiple inheritances. There is an example which illustrates its functionality below:

code1

(ProgramCreek.com, 2016)

CONCLUSION

In spite of being a powerful resource to the programmer, it is commonly criticized by its complication to debug and even to lead to unnecessary design complexity. The Java programming language does not support it directly; on the other hand it implements resources (such as function interfaces) which may lead in such manner to achieve the same functional result.

REFERENCES

ISOGG Wiki. 2016. Mitochondrial DNA tests. [ONLINE] Available at: http://isogg.org/wiki/Mitochondrial_DNA_tests. [Accessed 20 April 2016].

Sklenar J. 1997. INTRODUCTION TO OOP IN SIMULA. [ONLINE] Available at: http://staff.um.edu.mt/jskl1/talk.html#History_I. [Accessed 20 April 2016].

What Is Inheritance?. 2016. What Is Inheritance? ONLINE] Available at: https://docs.oracle.com/javase/tutorial/java/concepts/inheritance.html. [Accessed 19 April 2016].

Default Methods in Java 8 and Multiple Inheritance. 2016. ProgramCreek.com. [ONLINE] Available at: http://www.programcreek.com/2014/12/default-methods-in-java-8-and-multiple-inheritance/. [Accessed 19 April 2016].

Your next programming interview

This post is dedicated to all the ones which are looking to get prepared for the most difficult job interviews in software development. First of all, I want to make sure you know the fundamentals of computer science in the programming space, and I will recommend some courses which will make you a five star developer in a world-wide scale.

  1. Stanford’s Computer Algorithms Course:

Links and websites to practice and check your ability to deal with computer science and math related problems:

There are also other MOOC platforms such as:

ultimate-mooc-guide