masterof_none
25-05-2003, 10:16 PM
"Programming is understanding"
- Kristen Nygaard (http://www.wikipedia.org/wiki/Kristen_Nygaard)
-creator of Simula.
Before we dissect HelloRC.java code, we need to understand the programming concept called object oriented programming(OOP).
(Consider System.out.println("Blah")). Why they have too many "dots" here. what does that mean?)
So, What is OOP?
OOP is just another way of organizing your program.
Before OOP, they have what they called modular programming (using functions). However, a guy from Europe (Norway) created a programmming language called Simula, the first OOP language.
What is function?
So in Math, we are thought about function right?(linear function, quadratic function). The same applied here.Consider this:
f(x) = 2x + 1 .
This is a linear function. So, what is this supposed to mean?.
Given a value x, if we apply to that equation, it would become sth else(increase/decrease in value etc). For x equal to 2, f(x) now become 5.
The same thing here in programming. In any programming language,usually they refer the x above as a "parameter".
conceptually , looks like this:
//this is the main function. This function will be called automatically
main() {
//I'll explain this later
int result;
int x = 9;
//result would hold the result of computation of the function
//note: x IS 9 from above
result = f(x);
}
//this is the function
int f(x)
{
//do whatever computation.
int func_result;
func_result = 2x + 1;
//need to pass back to the calling function in the main func above:
return func_result;
}
This example is just meant to illustrate the usage of function (just like math). But computation is a little bitt fancy(pass the parameter to function, and pass back to calling function(main) .
Of course, you can directly compute from the main func:
main() {
int result;
int x=9;
result = 2x+ 1;
}
This yield the same result. but that's not our point.
OK, So...?
So, after we know function, we want to explore the definition of variable.
What is variable?
You already knew. The x above. But in C, you'll find something like this:
int result;
what is this?. That means, result would hold variable integer only. This declaration is to make sure the compiler allocate memory just enough for result to hold integer. No decimal point. If the result has the decimal point, it would cut off. e.g 14.234 become 14 only.
So what if we still want to store the .234 ?
Use float. e.g
float result.
if we want to store a string, we want to use:
char blah[20];
(allocating 20 block of character)
float, char, and int , hence can be referred as
data structure
Now, we're a little bit curious. It seems like we have some limitation here. Instead of storing only number, like int result above, or string only , char blah[20]what if we want to store the both under one common name?
for example, you want to create a dinasour, you want the name, and the age of the dinasour .
for example,
This is my favorite dinasour :
Name: Barney
Age : 5 years old (because Barney like to play with kids)
so, of course, we can;t simply put
int barney;
this will only store the age of Barney, which is 5, or,
char barney[10] = "Barney" ;
this only store the name of the dinasour, but not the age. So, How can we resolve it?
in C, they have what they call, struct (for structure, I suppose)
e.g
struct Dinasour {
char name[10] = "Barney";
int age = 5;
}
now only people know what is the name of this dinasour and the age.
I guess I should stop here. Take a break. Do your own reading.
Post it here if you got confused. I'll try my best to help you.
Next, we'll explore the class concept. (it turns out it is something similar to struct).
to be continued...
- Kristen Nygaard (http://www.wikipedia.org/wiki/Kristen_Nygaard)
-creator of Simula.
Before we dissect HelloRC.java code, we need to understand the programming concept called object oriented programming(OOP).
(Consider System.out.println("Blah")). Why they have too many "dots" here. what does that mean?)
So, What is OOP?
OOP is just another way of organizing your program.
Before OOP, they have what they called modular programming (using functions). However, a guy from Europe (Norway) created a programmming language called Simula, the first OOP language.
What is function?
So in Math, we are thought about function right?(linear function, quadratic function). The same applied here.Consider this:
f(x) = 2x + 1 .
This is a linear function. So, what is this supposed to mean?.
Given a value x, if we apply to that equation, it would become sth else(increase/decrease in value etc). For x equal to 2, f(x) now become 5.
The same thing here in programming. In any programming language,usually they refer the x above as a "parameter".
conceptually , looks like this:
//this is the main function. This function will be called automatically
main() {
//I'll explain this later
int result;
int x = 9;
//result would hold the result of computation of the function
//note: x IS 9 from above
result = f(x);
}
//this is the function
int f(x)
{
//do whatever computation.
int func_result;
func_result = 2x + 1;
//need to pass back to the calling function in the main func above:
return func_result;
}
This example is just meant to illustrate the usage of function (just like math). But computation is a little bitt fancy(pass the parameter to function, and pass back to calling function(main) .
Of course, you can directly compute from the main func:
main() {
int result;
int x=9;
result = 2x+ 1;
}
This yield the same result. but that's not our point.
OK, So...?
So, after we know function, we want to explore the definition of variable.
What is variable?
You already knew. The x above. But in C, you'll find something like this:
int result;
what is this?. That means, result would hold variable integer only. This declaration is to make sure the compiler allocate memory just enough for result to hold integer. No decimal point. If the result has the decimal point, it would cut off. e.g 14.234 become 14 only.
So what if we still want to store the .234 ?
Use float. e.g
float result.
if we want to store a string, we want to use:
char blah[20];
(allocating 20 block of character)
float, char, and int , hence can be referred as
data structure
Now, we're a little bit curious. It seems like we have some limitation here. Instead of storing only number, like int result above, or string only , char blah[20]what if we want to store the both under one common name?
for example, you want to create a dinasour, you want the name, and the age of the dinasour .
for example,
This is my favorite dinasour :
Name: Barney
Age : 5 years old (because Barney like to play with kids)
so, of course, we can;t simply put
int barney;
this will only store the age of Barney, which is 5, or,
char barney[10] = "Barney" ;
this only store the name of the dinasour, but not the age. So, How can we resolve it?
in C, they have what they call, struct (for structure, I suppose)
e.g
struct Dinasour {
char name[10] = "Barney";
int age = 5;
}
now only people know what is the name of this dinasour and the age.
I guess I should stop here. Take a break. Do your own reading.
Post it here if you got confused. I'll try my best to help you.
Next, we'll explore the class concept. (it turns out it is something similar to struct).
to be continued...