This free book helps beginners to understand the reasons behind various coding constructs. And this book does not focus on any programming language. So, you can think it is for java or C# or whatever…(Examples were given in pseudo programming language)
Please sorry for grammar mistakes, English is not my native language. You’re welcome to point out anything I can improve on. Thank you!
- If Conditions
- Classes & Objects
- Static vs. Instance
- this keyword
- Protected Modifier
- Overriding & Polymorphism
- Abstract Classes & Interfaces
- Interfaces as callbacks
- Importance of abstraction
Statements are commands in your program which instructs cpu to do something. Statements are executed in sequential order (one after another). Following is an example:
Suppose we want to print the value of 1024*1024 twice.
The simplest form of our code would be something like this:
The problem of this code is we have to calculate the value of 1024*1024 two times. Instead of multiplying two times, we can use a temporary memory to store the calculated value. So, when we require the value of 1024*1024 again, we use that temporary memory instead of multiplying those values again. We named that temporary memory as a Variable.
Variables allow us to capture & reuse the result of calculation.
When you declare a variable, you’ll need to give a type of that variable first. Type of a variable identifies what it can hold. For example: int type can hold a number, string type can hold a name of a person
After you declare the type, you need to specify the name of the variable. This name can be use anywhere in your program where you want to use the value it holds.
Here is an example:
Sometimes we want our program to take decisions by reading external inputs. Without decisions, our program acts in same way for any input.
To make decisions we use if, else if, else control structures.
You can use following coding formats:
Following program reads an input from user & prints some details according to the value of that input.
Suppose you want to print “hello” 10 times. Will you write print “hello” ten times? nop.
That’s why we have loops! When we want to do the same thing again & again, we are using loops to do that.