Saturday, January 24, 2015

Programming is fun...


palash Kanti Kundu palash Kanti Kundu palash Kanti Kundu palash Kanti Kundu palash Kanti Kundu





Sounds interesting ?


What will you achieve following these space ?
This series will try to
2.            provide you information on Java with examples.
3.      draw analogy of Java programs to real world scenarios


Who am I ?
I am Palash Kanti Kundu, an IT Professional.


Why am I doing this ?


What if you are not getting what you are finding for ?


What if you find wrong information ?
Everyone is error prone. So am I.


Palash Kanti Kundu

Thursday, December 4, 2014

What is a computer program ?

What is the use of a bat if you don't know how to play Cricket ?
Completely useless, right ?
Same thing happens with computers without a program to run on it.

With that said, here comes a formal definition of a computer program.

Computer Program: In computing, a program is an organised set of operations for a computer to perform. Program is more like a recipe for a computer which consists of  a set of ingredients (which are known as variables) and a set of instructions(which are called statements) to tell the computer what to do with the variables.

Program has an executable form for computer to use directly. This form is not suitable for human being. This is also known as Low-Level program or machine language. The instructions provided in this form can be directly used by the processor. Another form of a program is High-Level program or source code, which is suitable for human reading or editing.

The human readable source code must be converted to machine readable low level machine code by a compiler or assembler or interpreter.

Source Code: Source code is a program written in a high level language (Such as C, C++, Java etc.). This is used by computer programmers who specifies the computer how to work. Source codes are often written in a text format. Source code is not machine dependent. You can write a program in Machine A and can run the same program in Machine B.

These are then provided to a special process, known as compiler as an input to produce a low level machine code understood by compiler.

Source Code Program written in High Level Language

Machine Code: Machine code or machine language is a set of instructions to be used directly in the computer's central processing unit. Machine language is completely machine dependent.

Every processor or processor family has its own set of instruction due to the architecture of the processor. So machine code written for a particular family of processor can not be run on a different family of processor.

Following is a program in its Hex form. This program runs and prints Hello World !

Machine code of a program
Following is the bit string provided to CPU to perform. This is the lowest form of a computer program.
Instruction to CPU in bits (0 and 1)

Prev Next
Palash Kanti Kundu

Detailing Differenet form of Languages


What is this ???
Is this an amount of money you have to spend to learn about programming or is this a number of days earth will exist further ???
Many of you are thinking like this. This is simply a garbage value to you, but unfortunately this is the only thing a computer understands.
Yes, only 0's and 1's. Using these two digits only computer does everything. It does not matter to a computer what purpose it is serving, may be its a secret bank information, may be a music, may be a picture to display or may be simply this article you are currently reading. A computer don't know what it does it just recognises that it has a string of bits to process.
If you provide the following to a computer, it will try to think (though it can't), what am I supposed to do with this ?
'add 4 with 2 and show me the result'

So, you have a question in your mind, 'Why the hell you told about high level languages which are in human readable format and also you have written a program that clearly is in english and yes it greets with 'Hello World' ?'

I am not mad and neither I am telling a lie. Yes, correct, both statements are 100% true.
You also keep remembering every time,
  • Computers can not recognise human readable language.

  • You can instruct computer in a human readable language.
Confused ???
Well I was also confused in my first class of basic computing.
Its not a magic, essentially the human readable language is translated to machine readable form, its basically another program which does this for you.
 A program to generate another program ?
Yes that's true. These programs are just like people who can speak more than one languages.
There are programs which sits on your computer whose basic responsibility is to translate the human readable high level language to a machine readable low level language.
There are many forms of these programs.
Mostly we deal with Compiler, Assembler, Linker, Loader and Interpreter.

On a broader view we can have 3 types of Language
  1. Machine Language - This is the only form of language computer can directly execute. These are fast and contains only 0's and 1's or On or Off switch. If you know about binary numbers, you can relate these. Only operations are performed using this language. This form is completely machine dependent. So you can write for a particular machine and port it to another to get the result.
  2. Assembly Language - An advanced version of machine language. With this you can have some more flexibility like ADD, SUB, CMP, JMP etc. Although it is advanced, you can only support different operations only and to write logic, you have to think of this logic as a set of operations. This is also machine dependent.
  3. High Level Language - This form is best suited for human. You can write logic, repeat operations, use information or whatever you want to. This is not machine dependent meaning you can write a program on a machine and run it on another. But the main drawback is this form is slow when compared to the former two. Cause this needs to be translated into the lowest level form.
So, I think you also think that you can instruct your PC to perform some operations for you although your PC is not able to understand what you are asking it.

Sounds interesting?
If it is a YES, you can keep on reading I have something more to tell you...

Prev     Next
Palash Kanti Kundu

Detailing High Level languages.

I assume that, reading the previous post you are a bit curious to instruct your PC to perform tasks.
If that is not the case, you will get some basic knowledge on programming which you can use anywhere.

So leaving upto you either to read on or to move away and surf some other websites...

Before going into further details always keep in mind, We always try to simulate our real world using computers. If there is anything in the world of computers, Smartphones, Tablets or any other processing units available, there is always a real world existence of the same. Nothing in the world of computers is beyond the real world.

Let's start our journey...
To instruct your computer to perform tasks, you need to know a language. May be its machine language or a high level language. You can hand code machine language but its really tough and hard to maintain. So, better you start with a high level language. There are plenty of high level languages available like FORTRAN, COBOL, BASIC, C, C++, C#, VB, SQL, HTML, JavaScript, Java and many more. Since 1957 with FORTRAN as the first official High Level Language release till today there have been many high level languages developed and widely used in industry. Each language performs a specific kind of task.

We can thus categorize languages in different groups.
I will try to give an overview of some groups.

Mark Up languages: Many of us put underlines while reading an article or put some extra efforts in a portion of text while writing an article or sometimes you try to differ some part of the text by indentung while writing. Many of us use different ink colours.

All these are techinques to present your creativity in your own style or sometimes thease are also used with procedural instructions such as marking up a manuscript or proof reading.

Hence from the name you can guess what a mark up languages tries to achieve.
Yes, it basically provides an instruction how to show with particular information or what you need to di with the information provided.
There are many markup languages available. Some of them are GenCode, SGML, HTML, XML, XHTML.

Functional Language: With mark up languages you can define how to show an information or what to do with information. Using them you can not define how to do it. Functionl language exists for that.
Some of the functional languages are C, C++, Java.

Data oriented language: These are powerful tool for searching and manipulating data represented in entity relationship diagrams.
Some of them are SQL, Clarion, Clipper, dBase.

There are many other types of programming languages. To get a complete overview, the following link is useful.
If you are in a learning phase, you don't have to worry about all these now. You will eventually get to know or simply you can come back to this post and click the link.

We now have a basic idea of what a program is, how a program is used, what are the different form of a program, what is a language, what are the types of language we have.
With all these knowledge we can start with Java...

Prev     Next
Palash Kanti Kundu

Introduction to Java

What is Java ?
Java is a programming language and a platform. I will detail it later.
Where is Java ?
Java is anywhere.
  • Java is in embedded hardware platforms like micro controllers, sensors, PDAs, TV set top boxes and many more embedded and mobile devices.
  • Java is in desktop application
  • Java is in Android mobiles and tablets
  • Java is in server client architecture
  • Java is in web browsers
  • Java is in smart cards, ATM cards, SIM cards
How java manages all these ?
Java has different flavours to choose from depending on what you are trying to put it in work.
  1. JavaCard - for smart cards with very limited resources
  2. J2ME (Java Platform Micro Edition) - for small devices with limited resouurces
  3. J2SE (Java Platform Standard Edition)- for standard desktop application development
  4. J2EE (Java Platform Enterprise Edition) - for enterprise applications, mostly used in a client server architecture.
What java offers ?
Java is full of features.
Java is,
  • Simple - easy to learn. Also java has many built in libraries that makes development easier.
  • Architecture independent - means you can write applications on a system and can run on any platform with adequate support.
  • Robust - java is reliable. It puts a lot of emphasis on possible. Java compiler detects many errors upfront and tries to minimize errors on runtime.
  • Secured - a java program runs on Java Virtual Machine which is a layer on top of Operating System. So a java program can not harm another program running.
  • Object Oriented - I will discuss this later.
  • Interpreted - Java Compiler generates which is interpreted by Java Virtual Machine. Thus it can be portable and run by different environments.
  • High Performance - Java provides Just In Time compilation which makes the execution of compiler generated byte code faster.
  • Multithreading - different threads of an application can run simultaneously. Something like listening to your favourite track while walking down the street.
  • Memory management - Java helps developer to forget about memory management. Java does this for you. It has a its own garbage collection mechanism which takes of the unreferenced objects and deallocates them. Although Java does memory management, if your code has something wrong memory leakage is still possible.
Java provides so many things, you have to pay for it...
Absolutely no, Java is free. Development tools and runtime environments are absolutely comes at no cost.
There are license for some use cases but you don't have to worry about it. Everything you will need comes for free. All you need to do is to learn how to instruct the computer using Java.
Check this if you have a doubt.

Prev     Next
Palash Kanti Kundu

History of Java

The initial objective of creating Java was something different that it looks today.
Back in 1991, James Gosling, Mike Sheridan and Patrick Naughton initiated this project in June with a motive of writing applications for interactive television. Gosling's office had a oak tree outside which influenced the first version of Java to be named as Oak. Later the project was renamed to Green and furthermore it is renamed to Java as it is being used today. The name Java was influenced by Java coffee which was largely consumed by the creators.
Since the first release, Java has undergone different changes and enhancements. Consequently it has different versions available till date. Some of the version came up with a code name attached to it.
Following are the major versions till date,
  1. JDK 1.0 - code named Oak released on January 23, 1996
  2. JDK 1.1 - released on February 19, 1997
  3. J2SE 1.2 - code named Playground and released on December 8, 1998
  4. J2SE 1.3 - code named Kestrel and released on May 8, 2000
  5. J2SE 1.4 - code named Merlin and released on February 6, 2002
  6. J2SE 5.0 - code named Tiger and released on September 30, 2004
  7. Java SE 6.0 - code named Mustang and released on December 11, 2006
  8. Java SE 7.0 - code named Dolphin and released on July 28, 2011
  9. Java SE 8.0 - released on March 18, 2014
There are lot of stories in the web on Java history and significant changes it undergone but for now its ok to get to the next step.

Prev     Next
Palash Kanti Kundu

Java Installation

Practice makes a man perfect

So, let's start our coding. But before that you have to do some more before you can actually start writing your program. I am assuming you are using Windows 7. For other systems, you can check corresponding manuals.

  1. Download JDK
           As given by the link in the previous post, download JDK in your machine
     2.  Install JDK
          Once you have downloaded the installer, double click on it and click Next util it comes to an end.
     3.  Set PATH of your system
          Your system is now have installed JDK. Next we have to set the PATH variable of your system.

           Right click on My Computer
             Click on Properties. On right pane you see, Advanced system settings. Click that.
             A pop up opens. Click Environment Variables...

               This opens another pop up.  In the upper box, you will find JAVA_HOME. Double click it. It opens a pop up. Copy the Variable value and press OK.

                  In the lower box find PATH and select that one. Click on Edit.
                      Leave everything as it is. Just paste the value in the last in the Variable value field.

                     Now click OK on each pop up and open Command Prompt and type javac -version

     4. Congratulations
                Java is now installed in your system.  All set, On the next level, we're going to write our first program

Prev     Next
Palash Kanti Kundu