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

 Computers are good at following instructions, but not at reading your mind.

0110000110100101010010010010010100
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.
BUT

  • 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.
http://en.m.wikipedia.org/wiki/List_of_programming_languages_by_type
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.
http://www.oracle.com/technetwork/indexes/downloads/index.html

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

Components you need to keep handy

Note: Here onwards, anything referring to Java I will be mentioning Java SE. If any other form I am talking about, I will be mentioning that explicitly.

Writing and running a Java programs needs the following,
  1. Your interest
  2. Your time
  3. A text editor
  4. A JDK
Of these the first two I don't have any control but for the last two I can guide you.


  • A text editor is program where plain text can be written and edited. All modern operating systems come with a preinstalled text editor like Notepad in Windows OS or VI editor in Unix. You can get some more cool stuffs freely available on web but a basic text editor will suffice for now. Some suggests IDEs like NetBeans or Eclipse to use. But personally I think a begineer should not use them. Working with basic editors, you will get to know the steps involved in the process of executing a Java program.
  • JDK or Java Development Kit is a set of tools and libraries for a java application to become alive. There are basically two set of tools and libraries,
  1. Development tools like Compiler, Debugger, different other tools.
  2. Java Virtual Machine or Java Runtime Environment. This is a layer on top of the OS being used to run Java proggrams. I will be spending another post for this topic. Cause this is really important to know about JVM and what it does.
You can download JDK from Oracle website. You will need to decide which version to download. I recommend downloading Java SE 7.0. Following is the link to download JDK.
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html


Now, this is the bare minimum requirement for a java program to run. You write a Java program in a text editor, compile it using Java Compiler javac(part of JDK) and run on JVM(which is also distributed with JDK).


Prev     Next
Palash Kanti Kundu

Your first program on Java

The best training program in the world is absolutely worthless without the will to execute it properly, consistently, and with intensityJohn Romaniello
Yes, that's true. So, let's start our first program. Traditional first program greets world. I am foloowing the same trend.
NOTE: You can use any text editor or fancy IDE like Eclipse or NetBeans but I strongly recommend using simple Notepad cause you are in a very much learning level. I will let you know when it is OK for you to use fancy stuffs.

Open any text editor and cpoy the following
 /**  
  * @author Palash  
  *   
  */  
 public class MyFirstProgram {  
      /**  
       * @param args  
       */  
      public static void main(String[] args) {  
           System.out.println("Hello World");  
      }  
 }  

Save it in file system with name MyFirstProgram.java
Now open command prompt and move to the directory where you saved your program.


and type the command javac MyFirstProgram.java. Wait for a  few seconds while the program compiles and then again type java MyFirstProgram

I wish I was there with you to share the joy...

Next we are going to do some more. Just keep reading...



Prev      Next
Palash Kanti Kundu

Your Second program

What would I do just greeting the world with Hello World ?
I wish my program could greet me as well.

Well, many of my reader are thinking such even I thought the same way...

So, breaking the traditional way of Java tutorials where after the program, it starts theory again. But, this is the last one for now and again we'll be studying some concepts. Otherwise we can't grow.

Again open Notepad, copy the following and save it in file system wth name MySecondProgram.java


 import java.io.BufferedReader;  
 import java.io.IOException;  
 import java.io.InputStreamReader;  
 /**  
  *   
  */  
 /**  
  * @author Palash  
  *   
  */  
 public class MySecondProgram {  
      /**  
       * @param args  
       * @throws IOException  
       */  
      public static void main(String[] args) throws IOException {  
           BufferedReader br = new BufferedReader(new InputStreamReader(System.in));  
           System.out.println("Please enter your name: ");  
           String user = br.readLine();  
           System.out.println("Hello " + user);  
      }  
 }  

Now compile the program using javac MySecondprogram.java and run using java MySecondProgram


Congratulations, you have successfully instructed your machine to greet you by your own. How obedient your slave is. Isn't it ???

Next, we are going to know some theory on Object Oriented Programming...


Prev     Next
Palash Kanti Kundu

Object Oriented Programming...

Objects are abstractions of processing James O. Coplien

As I mentioned earlier, For everything in the world of computer, there is a real world existence and this is being followed in Object Oriented Programming (OOP).

But what this actually means ?
It simply means, anything we want to do, has to be dealt with objects.

What is an Object ?
Anything you can see around, is an object. You PC, your mobile, your watch and you yourself...
Yes, all human beings are objects.

Basically, anything that has something to do is an object where you know, what to do with it but less interested in knowing how this does.
For example:

  1. You eat food, your body works. Except for the doctors, we are really not very much interested in how everything goes under the hood.
  2. You see your watch, it tells time. But rather than you are an watch mechanic, you are less likely to know how this works.
  3. You play cool games on your Android device but you are hardly bothered about how the game runs or how the touch even works.
That's it.

Now, let's put this into a formal definition in terms of Computer Programming.

Object: Object is the basic unit of OOP. An object has some fields(often known as variables) and some behaviors(often known as methods) bundled together in a single unit.

So, how am I an object by your definition ?
Not only you, I am also an object of Human Class defined by almighty creator of the universe. After some days working with Java, you yourself find the analogy and if you don't, comments are always welcome !!!

Now, we know what an object is. We are now going to know about another term, Class.

Class: This is the blueprint of the object. Means, it defines, what are the fields and behavior an object will have, what it will perform. You can think a class as a recipe, where food is the object.
The following picture depicts the relation of class and object.



Who is this JVM between my recipe and my fruit salad ?
We need to go deeper to know this person a bit. Trust me, he is very good for you and your recipe. And even sometimes he makes your recipe more delicious. For now, take him as your friend.

Next, we are going to know some more about OOP. Stay tuned.


Prev     Next
Palash Kanti Kundu

A PIE

Again in mathematics with that 22/7 ?
No, its not Pi, its PIE.

A PIE stands for

  1. Abstraction
  2. Polymorphism
  3. Inheritance
  4. Encapsulation
Let me tell you about these in a little deeper,
  • Abstraction - In our practical life, we experience this almost with everything. We use our cell phone, but don't know how it works, you are reading this post with merely a zero knowledge (unless you are from networking background) of what goes underneath and there are uncountable examples we can see of abstraction. Same is the concept of OOP. Objects interact with each other using their exposed methods but never know, what all is going out of there visit. For example, if object A is interacting with object B via some methods, A will never get to know, what B is doing out of its sight and vice-versa. This is known as Abstraction in OOP.
  • Polymorphism - Polymorphism means an object can be seen in different forms. This is basically a biological term which means that an organism or species can have many different forms or stages. In OOP also, we can have an objects and methods in different forms.
  • Inheritance - This is a very powerful feature of OOP. 

    Inheritance provides two benefits, first it determines an 'IS A' relationship or Generalization. Which means that if two or more object has the same characteristics, then it should be extracted in a general verion of class. And the special characteristics can be defined in the more special version of class. Check the following,
    A male employee is a man who is a human being who is an animal which is a living object. So, male employee has five forms employee, man, human being, animal and living object.Note carefully, a living object has some general characteristics and an animal has some special characteristics, and in every form it is possible. The below picture depicts this,
Second benefit of Inheritance is code reusability. Imagine, you have a plate of fruit salad in front of you, would you like to take that one or will you again go to kitchen, follow the recipe and make another one ? I think, the first choice is more suitable to you (for me as well). If I have something with me, then why do I bother to make that again ? Yes, this is the concept of Inheritance. If you have written a piece of code, reuse it. Through Inheritance, you can do such in OOP.

  • Encapsulation - Encapsulation is built on the concept data hiding. It basically provides following two objectives
  1. Builds the data and the function in a single unit
  2. Restricts access of object components 
           Main benefit of Encapsulation is to modify our implementation without breaking other's.

Lot's of features and it will be even more interesting, when we'll implement all these in our code...

So, Java is Object Oriented ?
Yes, Java is object oriented. We work with objects and interaction of different object is done via methods. Java supports the major features of OOP, A-PIE.



Prev     Next
Palash Kanti Kundu

The way Java works...

A dream doesn't become reality through magic; it takes sweat, determination and hard work -Colin Powell


With the quote in mind, lets assume you are trying to build your own home. At the starting, you are like
This is what a programmer writes
Then you think, this is too abstract and you should ask help from an architect and you give him a call and he works on it.
Mr.  JDK
Then he comes up with a plan that looks something like this,
This is the generated Class file
Now, your plan is complete, now you call for a builder, may be in world of cartoons, but he is also a builder.
Mr. JVM
And what he gives you in return is...
The final output of your program
You are now happy with your home...

So your dream of a home becomes reality this way. Let's see how your idea becomes a working program.

        1. You first think of greeting the world - that's your idea.
        2. Then you talk to JDK via Java language - that's what you write your program
        3. JDK gives you a class - analogous to the 2 BHK home plan
        4. Then you ask for the JVM - who will make your dream to reality
        5. Your program greets the world - the final output of your program

This is just instructions, we'll dive deeper next...

Prev     Next
Palash Kanti Kundu

Write Once Run Anywhere...

From the introductory post you are repeating this, what is this ?
You like your new home and one of your friend wants to know about it. You ask him to build one for him. He finds your plan useful and thinks of reusing it.
Well, yes, the same thing happens in Java too. Once you have made the plan (compiled java class), you can reuse it to build your home (run the program).

So, once you have the compiler generated class file, you can run it on any machine where Mr. JVM is available. Let me put some picture.

You wrote it in Windows and running in other platforms also
On a more detailed picture, it looks like,

Write Once Run Anywhere
So, how it looks like in detailed steps ?
Here it is.
First you write your program in Java,

Source code in java

Next you compile it and compiler generates byte code from the source code. The byte code looks like below,

The byte code generated by the compiler
This is basically written in Hex Code. It is really a bad idea to look the program this way. You can view a Mnemonics version of the generated class file using javap. If you have ever done Micro Processor programming, you can relate things. If not, then also its not a bad idea to take a look...
Mnemonic version of the compiled output
That's all. Now you can run this any environment you like such as Windows, Linux, Unix, Mac OS.
To run a program, you don't require JDK, just JRE will suffice.

Next we will learn about JDK and JRE. What are they and how are they used.




Prev     Next
Palash Kanti Kundu

JDK, JVM, JRE a deeper look

Many of us have seen the error in web pages to install Java. What you simply do is click on the error and it opens a website to download Java. You download Java, install it and restart the web browser. This is very common scenario. Isn’t it?

But there is a lot more than it. If you are following this series, then you can recall that, I asked you to download JDK and not Java.

So, what is the difference?
Yeah, there are differences, you should be clear on. Actually to work with Java, you need to be clear about 3 terms, JRE, JDK and JVM. It’s good if you don’t confuse them or mix them altogether.


  • JVM – Java Virtual Machine (JVM) is an executable program that interprets the byte code generated by the compiler and generates machine code and directly given to OS for execution. Below picture depicts this fact.


          JVM is also responsible for memory management, Garbage collection, security and other                     system         level services.


  • JRE – Java Runtime Environment (JRE) is JVM bundled with some runtime libraries like, deployment tools, Integration libraries, user interface libraries etc.
          JRE = JVM + Runtime libraries
  • JDK – Java Development Kit (JDK) is JRE bundled with development tools like javac, javap, debugger tools, wsimport.
          JDK = JRE + Development tools.

In a nutshell, JDK is the superset, where JRE is a subset of JDK and JVM is a subset of JRE. The below picture depicts this fact where the most outer grey part is JDK, the inner blue part is JRE and the inner most pale blue part is JVM.

JDK, JRE, JVM
If you are an advanced programmer, you can take a look on the oracle documentation here.


Prev     Next

Palash Kanti Kundu

A trip to Class

May be for the first time in your life you would be doing something totally different. You can either hate me love me for this. But unfortunately, you have to do it for now.

So, what are you asking me to do for you?
Very simple task, think yourself as an Object.

Huh… again??? Some posts ago also you mentioned the same, but did not hint how to?
Well, this time I will hint. Let’s think ourselves as objects. We have some state like name, qualification, height, weight, complexion and many more. Again we have some behaviors like interacting with others, doing our jobs, building a social reputation, singing, dancing, eating, walking, running, writing, drawing and many more things we do in our practical life.

OK, I am object, so what’s there to do with Class?
Recall from my previous post, with the help of JVM a Class is converted into an object.
With this, we can check for a formal definition of Class.
Class: A class is a code template for creating objects. Class contains state and behaviour in form variables and methods. When an object is created from the class, in terms of OOP it is known as the instance of the class.
In a nutshell, Class is the blueprint while Object is the implementation.

OK so I am an object, where is my class?
Well, the class definition for human object is maintained by almighty GOD. Everything goes in heaven. Someone wrote their ideas of human and put it in a Class definition and someone has compiled and interpreted the same and we are here in this world.
Well, I don’t know those part in detail. When I will meet almighty GOD (I don’t know about the date, time and venue for that), I definitely will have this question to him.

OK, time for a quick class creation with a few state (now on, we’ll be using the term variables) and behaviors (now on, we’ll be using the term methods).

Let’s create our Human class in the world of Java.

Basic Definition of Human Class
If you are aware of UML, you can relate the diagram. But please note, this does not follow any rules.
This is just for learning purpose and may not be very much useful in other aspects.
If you don’t know what UML is, don’t worry. To learn Java, it’s not required at this point.

What this diagram means?
·   You can see the topmost layer is Human, this is the name of the class.

· The second layer has name: String, height: double, complexion: String. These are the variables and their data types. I will discuss variables in next post.

· The third layer has interact, eat, think, sleep, run and walk. These are methods of Human class.
These are the pieces of code for logic to stay. Algorithms get executed here. Actually all the behavior, data gets manipulated in methods. Will detail this part in later posts.

So, in words, our Human will be having name, height and complexion. Our human will interact, eat, think, sleep, run and walk.
That was the idea of Human. Let’s put it into a Java program.

 class Human {  
      String name;  
      double height;  
      String complexion;  
      void eat() {  
      }  
      void interact() {  
      }  
      void sleep() {  
      }  
      void think() {  
      }  
      void run() {  
      }  
      void walk() {  
      }  
 }  

What is this void and other stuffs?
This is Java syntax, we’ll be coming to these portion very soon. For now, just try to relate the variables and methods.

So basically you have defined how your human object will look like and what it will do. Now, the instances of this class will be created by JVM when your application will run on it.

Prev     Next

Palash Kanti Kundu

Palash Kanti Kundu

Data

Data is a precious thing and will last longer than the systems themselves. - Tim Berners-Lee
Look at that girl, so pretty she is…
I have hundreds of books and I don’t read them...
These are pretty much common phrases people use, isn’t it?
You are thinking, ‘yeah we do but what is the relation of it to Java at all???’
Yes my dear reader, there is relation. What we achieve telling these is the relation with Java, well not only Java but to the whole computer system.
HOW?
We use this kind of phrases to share Data and data is the basis of computer technology. Everything we do in a computer is deal with data.
So, what is Data?
In its simplest form, Data is a collection of information. This information may be of any type, numbers, words, observations, measurement or even just a description (so pretty she is).
With said that, let’s dive deeper. Data can be of two forms,
1.    Qualitative – it represents description or quality of something. Analogous to Adjectives in grammars.
2.    Quantitative – it represents numerical information like 8 chairs, 9.8 meters, 20 litters etc.
Now, in a way, we can divide quantitative data into two parts as well,
1.    Discrete – it has some restrictions on it. It can take certain values and the values are distinct and separate. This data can’t be broken in smaller units. It’s typically counted in whole numbers.
For example: number of pages in a book, gender of a person (male or female), blood group of a person (A, B, O, AB) etc.
2.    Continuous – it is the data that can be measured and broken down in smaller parts and still be meaningful. It is the data that can be measured on a scale and can have any value within a range.
For example: height of a person, length of a road, volume of a cube etc.

Let’s put all these in a picture.
So, what have I achieved knowing all these?
Right now you have achieved nothing except the fundamentals of data. You will eventually understand this part when you will be designing your classes with different variables. Stay tuned, next we are going into variables, where you can put this knowledge usable.


If you have gained some knowledge here, would you like to share this article in your network ?


Prev     Next
Palash Kanti Kundu

Basic blocks

8 = 00000000000000000000000000001000
a = 00000000000000000000000001100001
2.4 = 100000000000011001100110011001100110011001100110011001100110011

Who taught you mathematics ?
I don't know, might be a computer had taught me. Because whatever we may throw but computers looks anything like this only.

No matter how modern it is, Computers can read only two basic things, either a bit is on or off. If you are unfamiliar with the term bit, just consider, it only can determine if a light is on or off and it reads nothing other than these two.

Is it really so or you are just trying to be over smart?
No, I really don't wanna be on lime light and its really true that computers can just read if a bit is on or off and also remember No matter how modern or costly it is, microprocessors (heart of any computer), perform only some very basic and easy operations, may be you did at the age of 8-10.

What ???
Yes, your brain is much much much more advanced than today's most advanced computer and computers and if we think of comparison, the ratio would be more like that of a cell in your body and your whole body.

Then how does this evaluate such complex calculations which human brain can't do???
No, you are wrong, human brain can do more complex things, that a computer can ever perform. But human brains can't do things repetitively.
Computer is idiot box which only follows our instructions over and over without adding anything new to it.

Then why Computers are valued too much in today's world and almost anything these days are done using them ?
Computer system has two parts in it, the hardware or the combination of different physical entities like CPU, RAM, HARD DISK etc. and the Software or the combination of logic.
Software tells Hardware what to do and hardware does it in a super fast way.

You don't need a lot of skills but you need some which you do frequently - some movie
Computers also follow the same rule of thumb. It achieves all its fame by just performing a limited set of skills in a very fast and frequent manner.
Each day these systems (both Hardware and Software) get more and more advanced. Hardware are becoming faster each day while Software are becoming more powerful and more real life oriented each day. So, the whole Computer system is becoming more advanced each day while making lives easier.
So, Computer is valued so much in today's life for making lives easier.

Hmmm...(Girls can read it as 'Awww...') I now get it, human are much more powerful than a computer and a human has to instruct a computer to do something and it will be done in a super fast way. Without existence of a human a computer can do nothing. Am I right ?
Yup, its only that.

So, how do I instruct my computer using Java?
Well, in every program, there are two parts as we've seen earlier also, one is data and another is instruction to what to do with the data. These are the basics of any programming. With the use of these, we instruct our computers.

Data resides on memory and instructions are executed by Processor. In any high level programming language, we have some place holders to store data in memory and on demand to retrieve the data from memory. These place holders are known as Variables.

Variables are places in memory to hold some information. Variables have there names and data types. Data types basically tells the underlying system how much space in memory should be reserved for this variable. Its the responsibility of the compiler or interpreter to keep track of the memory location. The programmer just needs to know the name of the variables and how to use them.
Variables can be of any type like whole number 3,5,7 or decimal number 3.5,4.5,2.83 or a character, 'a', '$', 'l' or a sequence of characters "Palash","loves", "Java" or any other complex type like Human in our earlier examples.

Hey hold on. You just told 'Human', right ?
Yes, Human. Please hold on your queries, we'll be discussing these very soon.

What is the use of having a Telephone Directory if we don't dial a number from it?
Yes, the same thing applies for computer world too. We don't need data if we don't know how to analyze or use it. We instruct computers to work on the data and the sequence of information is known as Methods.
Methods consist of Control Structure and Subroutines. Control structure consists of looping and branching. Subroutines are sequence of instructions packaged as a single unit.

That's all for now. Get yourself a chance to think over this for some time. Next, we'll be looking into variables.


Prev     Next
Palash Kanti Kundu

Remember me !!!

What would happen if you can not remember anything ???
The world would be so bad if you can not remember anything. Suppose, you can not remember if you have already collected a ticket while travelling, you will end up buying a lot of tickets.

Isn't it nice that we can remember things.

Same is the case of Java. It gives us a choice to store data in memory and use whenever required.

With that said, now comes a formal definition of Variable.

Variable: Variable is a reserved memory location to store data with a name and also provides a set of operations to be performed on the data. Programmers use the name of the variable to work on.

A variable declaration have the following syntax
data_type variable_name = [value];

Java is a strongly typed programming language. Each variable must have a particular data type. Java only allow programs to execute if an operation is valid for the particular data type.
For example, you can not perform an operation on numeric data that is supposed to be done on text content.

Now, we know that variable declaration has three parts, data_type, variable_name and value. Lets's go into each part.

 Data Type: Java has two types of data type

  • Primitive Data Type
  • Reference Data type
Primitive Data Type: 8 primitive data types are available in Java. Those are predefined in the Java language and each type has special operations and memory allocation. Let's take a look on each of these,

We can divide these 8 parts in different sections.
Whole number declaration
All the whole number declaration in Java is in two's complement form. 4 whole number declaration is possible in Java.

byte: This is the shortest possible signed whole number declaration in Java. It uses 8 bits (1 Byte). It has a minimum value of -128 and maximum value of 127. So, using this data type, you are only allowed to assign a variable with numeric value range -128 to 127.

short: This is also signed whole number declaration in  Java. The difference with byte is the range and memory space. It uses 16 bits (2 Bytes). It has a minimum value of -32768 and maximum value of 32767. So, using this data type, you are only allowed to assign a variable with numeric value range -32768 to 32767.

int: This is also signed whole number declaration in  Java. The difference with byte and short is the range and memory space. It uses 32 bits (4 Bytes). It has a minimum value of -2,147,483,648 and maximum value of 2,147,483,647So, using this data type, you are only allowed to assign a variable with numeric value range -2,147,483,648 to 2,147,483,647.

long: This is the largest possible signed whole number declaration in  Java. The difference with byte and short and int is the range and memory space. It uses 64 bits (8 Bytes). It has a minimum value of -9,223,372,036,854,775,808 and maximum value of 9,223,372,036,854,775,807So, using this data type, you are only allowed to assign a variable with numeric value range -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.

Real number declaration
Real numbers in Java is represented as IEEE 754 standard and two types of variable is there, one for single precision and another for double precision.

float: This data type is a single-precision 32-bit IEEE 754 floating point. This data type should never be used for precise values, such as currency.

double: This data type is a single-precision 32-bit IEEE 754 floating point.  For decimal values, this data type is generally the default choice. This data type should never be used for precise values, such as currency.

These were related to numeric calculations. Another two data types are for character declaration and boolean declaration.

char: The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65,535 inclusive).

boolean: The boolean data type has only two possible values: true and false. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information, but its "size" isn't something that's precisely defined.

These were the primitive data types you can use your program. Apart from this set, Java provides special support for character sequence through java.lang.String class. You can define any String as primitive declaration and it will be automatically converted to String object. We will be discussing String in more detail later.

Reference Data Type: Apart from the primitives, it is also possible in Java to declare and assign Class types (like Human). More on this in later articles.



So, putting everything in a big picture looks like.


Next, we'll see how a variable name to construct.



Prev      Next
Palash Kanti Kundu