Wednesday, October 23, 2013

One Way of Learning Code

I got a new way to learn code. Actually I always implement this method while learning anything new, even during college while learning my course study - be it about operating systems or learning about the process of Software Development.



In one word - its 'IMAGINATION'!




Imagine that while you are reading a certain code, you actually create the scene as to relate to what is exactly happening in the background.



Here is the simplest example from Java:



IMPORT JAVA.IO.*;

CLASS HELLOWORLDPROGRAM{

PUBLIC STATIC VOID MAIN(STRING ARGS[]){

SYSTEM.OUT.PRINTLN("HELLO WORLD!");



Now here is how I go about understanding the program line by line:



Line 1: import java.io.*;

This line suggests that something is being included (or imported) into the program. Maybe like a tool (say, a spanner) from a common tool box!



Hmm maybe the asterisk denotes that ALL THE SPANNERS can be required for this job.



Line 2: class HelloWorldProgram{

A 'class' huh? Well, here it comes:



Though its empty for now :P

Well this class is our very own 'HelloWorldProgram' class which is quiet naughty but too smart! :D



Line 3: public static void main(String args[]){

'main' : Explanation- The main part of the program. The point where the program starts executing.

Like a starting point!



'void' : Explanation : doesn't 'return' anything

It will not receive any return gift?

'static' : Explanation: Specifying object not required to invoke

No need of a letter or phone call to call 'main'

'public' : Explanation- Available outside class

The people at the park also can see 'main'



( ) : These look like two cupped hands. Maybe they take something inside them!

'String' : Well yes the ( ) do have something in them: String ! String? A thread? A chain? But of what?



'args[]' : Oh here it is: A chain of 'args[]' . args? Like 'arguments'? A chain of arguments! (In programming though, 'String' represents a word or a sentence and '[]' - array - represents a chain)

What for do you need an argument? Oh! You argue with the Java store cashier (compiler) that you need 2 oranges more along with the program at no extra cost!

And the cashier in most cases gives way for the extra oranges!



Line 4: System.out.println("Hello World!");

Lets try a short story on this one!

Hmm System?? Is it also a class? Maybe an older one. Hmm maybe its a neighbour class to our dear "HelloWorldProgram" class but with bigger boys and girls.



But "System" class members offered some help out here. They have offered to help us out with a "method" (println) to let our students shout out "Hello World!".



Lets see how they do it:

One of "System" class students (object) doesn't seem to oblige in shouting out "Hello World!" for our students. He says on behalf of System class he will shout out "Hello World" to the shout-box (standard output - Monitor/Screen).



Maybe we can call him whenever we want to shout out something into the shout-box! Isn't that cool? It means we don't actually don't have to learn, but rather call out the class students (objects) to help us out each time we wish to say something to the shout-box!

Line 5 & 6: }

The End! Curtains fall! But wait! What's the output? Hmm the shout-box received a 'Hello World!' And that's what it shows!



This is one way I learn. Will update if I get any other ideas!
Full Post

No comments:

Post a Comment