Cover

cover

Advertisements
Cover

Preface

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!

R.Hasaranga
ruchira66@gmail.com

Preface

Index

  1. Expressions
  2. Statements
  3. Variables
  4. If Conditions
  5. Loops
  6. Functions
  7. Recursion
  8. Classes & Objects
  9. Static vs. Instance
  10. Constructor
  11. Encapsulation
  12. this keyword
  13. Inheritance
  14. Protected Modifier
  15. Overloading
  16. References
  17. Overriding & Polymorphism
  18. Abstract Classes & Interfaces
  19. Interfaces as callbacks
  20. Importance of abstraction
Index

Variables

Suppose we want to print the value of 1024*1024 twice.

The simplest form of our code would be something like this:

untitled

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:

untitled

 

Variables