Skip to content

Watched an MIT lecture

I watched This lecture and it has been very informative.

I learned the difference between Static and Dynamic typing, as well as the difference between strong and weak type checking.

Static typing states that once a variable has been given a type, it cannot be changed until it goes out of scope.

Dynamic typing is the exact opposite of that, you can change types as you want anytime you want.

Wikipedia defines strong typing as “the prevention of a successful execution of an operation on arguments which have the wrong type.”

For example, if you’re mixing integers with strings in a strongly typed language, this will result in a compile-time error.

While weakly typed languages try to cast one of the operands to perform the requested operation.

I also learned that when writing a test case, like an if statement, one should consider all possible cases that might occur.

As failing to do so usually results in bugs.

Since the course is being taught in python, and I’m a Java programmer, I understood why python uses indentation, it’s simply python’s way of grouping statements together, much like curled brackets “{}” in C-Like languages, like Java.

Advertisements

I passed the exam!

I just took SCJP – or OCPJP if you prefer – earlier today and I scored 70%!

It took me about an hour and a half to finish, about half the allowed time.

I was going to go over my answers once more, but I just couldn’t resist the temptation of finishing early, specially that I was confident in most of my answers.

This is a really big step for me,  and I hope this will get me places later in life.

Hello, World! in Java without main()

While I was reading the SCJP book, I came across the concept of initialization blocks, or init blocks for short.

Those blocks of code get executed before any method code is executed.

One kind of these blocks is static init blocks, those get executed immediately after the super constructor has finished execution.

This made me think, “I could output text to the screen without having any methods at all!”.

So, I sat down, fired up vi, and started writing the code.

At first, I had a few problems, I tried to write a method inside the static init block, which was a terrible idea, as the code didn’t compile.

So, I removed the method, and just kept the statements inside the block, it compiled, and then I decided to run it.

It did print the desired text to the screen, but I ended up getting a MethodNotFoundException at the end of execution.

So, I added a call to System.exit() to avoid this, and it worked as if I had a regular main method with the previous code.

Without further ado, here’s the code :


public class Main{
        static{
                System.out.println("Hello, World!");
                System.exit(0);
        }
}

Doing some coding

Today, I tried to write code that involves actual problem solving

I wrote a method that calculates the factorial of a number, here’s how I did it :


public static double calculate(int number){
	if (number > 0){
		int result = 1;
		for(int i = 1; i <= number; i++){
		result *= i;
		}
		return result;
	}
	else if(number == 0) {
		return 0;
	} else {
		String message = "Cannot calculate factorial for a negative integer";
		throw new IllegalArgumentException(message);
	}
}

Here, I used a loop to calculate the factorial if the number supplied to the method is bigger than zero.
And if it was zero, it should return zero.
If it’s a negative number, it should throw an Exception, I chose IllegalArgumentException here.
I also wrote another method to calculate Fibonacci numbers, here’s the code :


public static int getNumber(int number){
        int[] sequence = new int[number];
        sequence[0] = 0;
        sequence[1] = 1;
        for(int i = 2; i < sequence.length; i++){
            sequence[i] = sequence[i-1] + sequence[i-2];
        }
        return sequence[sequence.length - 1];
    }

Here, I used an array to keep track of the numbers calculated, and used indices to calculate more numbers with the help of a for loop.

Back to studying for OCPJP (formerly SCJP)

I have been studying for this exam on and off for a year now.

I now know a lot about Java SE, and I’m somewhat ready for the exam, there are a few things that need revising.

I’m currently using two books, this and this.

I’ve read the first book many times, and I’m using the second one because it’s more precise, something that I need right now.

I’m hoping that I will be done with this soon, preferably before my birthday which is next month.

Status as of Feb 5, 2011

I’m currently reading this book

Beginning C++ through game programming

It’s called Beginning C++ Through Game Programming by Michael Dawson.

What I like most about this book is that it actually makes learning C++ fun!

I’m currently in Chapter 5 : Functions.

I intend to move on to learning Gtk– afterwards,I’ve always been interested in making GUIs.

I’m also working on a side project using IDv3 in Java.

To-do list

These are things I hope to learn in the near future, those are listed in no particular order :

This page will be updated on a regular basis to reflect my current position and goals

  1. Python Disutils
  2. SQL and RDBMS.
  3. Read Clean Code (In progress).
  4. CSS.
  5. Apache Wicket.
  6. Play! Framework.