Sunday, January 4, 2009
Happy New Year Everyone
Happy New Year to all of you and may this year will fill your lives with challenges that will bring you to success....
Tuesday, December 16, 2008
C#.Net vs. JAVA
as a computer instructor, i'm always asked by my students this question -"why C#.Net and not Java?" of course i do have answers but sometimes i become so subjective-meaning it depends on the application that one will be developing...
This article compares the same program written in the C# and Java languages and then compares the dissembled code of both languages.
Java Hello Program:
class Hello
{
public static void main(String args[])
{
System.out.println("Hello");
}
}
Disassembled Java Hello Program:
class Hello
{
Hello()
{
// 0 0:aload_0
// 1 1:invokespecial #1
// 2 4:return
}
public static void main(String args[])
{
System.out.println("Hello");
// 0 0:getstatic #2
// 1 3:ldc1 #3
// 2 5:invokevirtual #4
// 3 8:return
}
}
Explanation of Java program:
To understand this you must have some knowledge of computer internals concepts for eg. Opcodes, instruction templates etc. I assume that you already know them.
As usual this code will also start with main method. The first line tells that print ?Hello? it is a normal print statement. A specific instruction, with type information, is built by replacing the ?T? in the instruction template in the opcode column by the letter in the type column. In this case it is a load instruction for type reference.
invokevirtual or invokespecial is used to access a protected method of a superclass, then the type of the class instance being accessed must be the same as or a subclass of the current class.
The Java virtual machine uses local variables to pass parameters on method invocation. On class method invocation any parameters are passed in consecutive local variables starting from local variable 0.
C# Hello Program:
using System;
class Hello
{
public static void
{
Console.WriteLine("Hello");
}
}
Disassembled C# Hello Program :
.method private hidebysig static void
{
.entrypoint
// Code size 11 (0xb)
.maxstack 8
IL_0000: ldstr "Hello"
IL_0005: call void [mscorlib]System.Console::WriteLine(class System.String)
IL_000a: ret
} // end of method Hello::Main
Explanation of C# .Net Program:
The first line defines the Main method by using the .method MSIL keyword. Note that the method is defined as being public and static, which are the default modifiers for the Main method. Also note that this method is defined as managed.
The next line of code uses the MSIL .entrypoint keyword to designate this particular method as the entry point to the application. When the .NET runtime executes this application, this is where control will be passed to the program.
Next, look at the MSIL opcodes on lines IL_0000 and IL_0005. The first uses the the ldstr (Load String) opcode to load a hard-coded literal ("Hello") onto the stack.
The next line of code calls the System.Console.WriteLine method. Notice that the MSIL prefixes the method name with the name of the assembly that defines the method. This line also tells us the number of arguments (and their types) that are expected by the method. Here, the method will expect a System.String object to be on the stack when it's called. Finally, line IL_000a is a simple ret MSIL opcode to return from the method.
Monday, December 15, 2008
Number Quiz
hi there....
if you're fond of numbers i have here a quiz that will somehow make you think....it's all about numbers that i got from www.funtrivia.com
kindly check this out...
1. There are only two numbers that are twice the sum of their individual digits. One of them 0 and I am the other one. I am a multiple of 9. Which number am I?
- You may have heard of the famous Fibonacci numbers. (1, 1, 2, 3, 5... where the next number is the sum of its previous two numbers) Well, I am one of them. What makes me more special is that I am the largest cube in this sequence. Which number am I?
- No other numbers are more special than me. I am the only number that is located between a square and a cube. More hints for you; I am smaller than 50 and I am an even number. Which number am I?
- I know number 10 is special, because we use it in our number system. However, I am not talking about number 10. I am the smallest number with 10 divisors. More clues to help you; I am smaller than 50 and a multiple of 12. Which number am I?
- A bit of thinking here for this question. I am the largest four-digit number with different digits, each greater than the one before it. Which number am I?
- . I am the age of the oldest person in the Bible - Methuselah when he died. I am a three-digit odd palindromic number that ends in 9. The sum of my individual digits is 24. Which number am I?
- . If you have a calculator with you now, you can find me. I am the answer for 1^7 + 2^6 + 3^5 + 4^4 + 5^3 + 6^2 + 7^1. But if you do not have one, never mind. I end in 2 and the sum of my individual digits is 12. I am greater than 700 but smaller than 800. Which number am I?
- Another palindromic number for you. I am the smallest five-digit palindromic number that ends in 9. Which number am I?
- If you are obsessed with Fibonacci numbers (1, 1, 2, 3, 5...) then this is the question for you. I am the largest square in the Fibonacci sequence. I am smaller than 150 and a multiple of 12. Which number am I?
Thursday, December 11, 2008
Design Pattern Classification
To my students:
There are the different design patterns in their respective classes. Please take note...Behavioral design patterns
Chain of Responsibility | Define a method of passing a request among a chain of objects. | ||||||||||||||
Command | Encapsulate a command request in an object. | ||||||||||||||
Interpreter | Allow inclusion of language elements in an application. | ||||||||||||||
Iterator | Enable sequential access to collection elements. | ||||||||||||||
Mediator | Define simplified communication between classes. | ||||||||||||||
Memento | Save and restore the internal state of an object. | ||||||||||||||
Observer | Define a scheme for notifying objects of changes to another object. | ||||||||||||||
State | Alter the behavior of an object when its state changes. | ||||||||||||||
Strategy | Encapsulate an algorithm inside a class. | ||||||||||||||
Template Method | Allow subclasses to redefine the steps of an algorithm. | ||||||||||||||
Visitor | Define a new operation on a class without changint it.Creational design patterns
| ||||||||||||||
Structural design patterns
|
Wednesday, December 10, 2008
some programming issues
As an individual involved in the academe, I firmly believe that students must have background in this aspect to make them ready when they face the actual IT world...
I include in this article a very simple creational design pattern - the Factory Design pattern. I hope this can give some knowledge to you guys out there....
The factory method pattern is an object-oriented design pattern. Like other creational patterns, it deals with the problem of creating objects (products) without specifying the exact class of object that will be created. The factory method design pattern handles this problem by defining a separate method for creating the objects, whose subclasses can then override to specify the derived type of product that will be created. More generally, the term factory method is often used to refer to any method whose main purpose is creation of objects.
Check this very simple example...
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class MainFactory
{
public BaseFactory GetObject(int x)
{
BaseFactory b = null;
switch (x)
{
case 1: b = new FirstObject();
break;
case 2: b = new SecondObject();
break;
default: Console.WriteLine("invalid");
break;
}
return b;
}
}
interface BaseFactory
{
void CreateObject();
}
public class FirstObject: BaseFactory
{
public void CreateObject()
{
Console.WriteLine("First object created...");
}
}
public class SecondObject : BaseFactory
{
public void CreateObject()
{
Console.WriteLine("Second object created...");
}
}
class Program
{
static void Main(string[] args)
{
MainFactory f = new MainFactory();
BaseFactory bf = f.GetObject(1);
bf.CreateObject();
Console.ReadKey();
}
}
}
Note: Depending on the integer value of the GetObject argument, the MainFactory class will create the object...
How to know the number of ticks from 1970 to 2007?
Here's a sample code to display how many ticks there are from 1970 to 2007.
using System;
namespace Ticks
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(DateTime.Now.Ticks );
Console.ReadKey();
}
}
}
Output: 633645793615625000