Thursday, February 25, 2010

Constant and Some programming Rules - Haunted me Constantly

Last week we gone through Data Type, today we will discuss about constant and some programming rules.
Constant: A numeric or string value that does not change. Constant expressions combine constants and operators, but no variables, and evaluate to the same value every time. If you are storing a constant value of any type, like- n=10, a numeric constant and integer type or s=”Foxing the Fox”, a string constant.

In BASIC when you store a string constant you have to mention the variable with a dollar ($) sign, s$=”Foxing the Fox”, a string constant.

Numbers, a decimal point and a negative sign all can be stored in a numeric variable, for string values can consists alphabets, numbers and symbols. Where boolean could have TRUE and FALSE.

Constant always come in the right side of the equal sign and variable in left side.
A=10
B=20
A=B


Mathematically above statement wrong but in computer we are just telling that the  B is a constant and value of A will replace by the value of B, but  B remain unchanged. Therefore, A becomes 20 and B remains 20.

C++, Java and C# provide the ability to declare a variable whose value specified at compile time and cannot be change at runtime. Java uses the  final field modifier to declare such a variable, while c++ and C# uses the  const keyword.

Rules for different Programming languages


Every programming language having its own Syntax (Grammar), rules and guidelines. Like old days in BASIC (GW-Basic) we have to bind a program with line number for each statement and line number should be in ascending order
10 a=10
20 b=20


Further when Bill Gates gave us Qbasic, line numbers were optional but only to be given when one use transfer control to other statement than the next one. Same follows for FORTRAN too.

Let us move to ‘C’, it is a process oriented programming language, where main control remain inside main() function, confuesd?

void main()
{
Statement;
Statement;
Child_function();
Statement;
}

Where child_function() is a method or procedure where you can do certain routine and at the end you return to main() function to the next statement.

Enter the OOPs, relax life is more easy than before, if you understand it. Object-Oriented Programming (OOP): A system of programming that permits an abstract, modular typing hierarchy, and features polymorphism, inheritance, and encapsulation.

First, let us ask – What is abstract?

Abstraction : Identifying the distinguishing characteristics of a class or object without having to process all the information about the class or object. When you create a class — for example, a set of table  navigation buttons — you can use it as a single entity instead of keeping track of the individual components and how they interact. Represent essential features of a system without getting involvement with the complexity of the entire system.

Let me clear above point, as if you are using a watch and using as single unit. You do not have to bother how and what makes it work.

Inheritance is where in some cases, a class will have "subclasses," more specialized versions of a class. Subclasses inherit attributes and behaviors from their parent (super) classes, and can introduce their own.

Encapsulation Conceals the exact details of how a particular class works from objects that use its code or send messages to it. Encapsulation is achieved by specifying which classes may use the members of an object. The result is that each object exposes to any class a certain interface — those members accessible to that class.

Polymorphism is an object-oriented programming term. The ability to have methods with the same name, but different content, for related classes. The procedure to use is determined at run time by the class of the object. Function overloading, constructor overload is one of the example.

What is an object? Object means an instance. An object is a software bundle of variables related methods. An object is a particular instance of a class. The set of values of the attributes of a particular object is called its state.

What is a class? class is a model that defines the variables and the methods that common to all objects of a certain kind. A class is an abstract type. A class defines the abstract characteristics of an object, including its attributes, fields or properties and also its behaviors or methods or features. For example, the class Dog would consist of quality shared by all dogs, for example breed, fur colour etc.

Syntax
public class mySpace()
{
//Global variable declaration
public static void main(String args[])
{
//Body of the program
}
}
It is not easy to write about all programming languages, I just tried to write those are in demand. Next week coming with user defined function(UDF)/method.
!!!So, do not expect a blast as these functions are very boring, for time being Bonne journée.!!!

Thursday, February 18, 2010

Data Type – Lots of hype around it

While we were learning computer programming, having only a few options and always thinking that life as a programmer will be very easy. Thanking all the way to John G. Kemeny and Thomas E. Kurtz from Dartmouth College for their invention, that was the 78KB single file software call BASIC. In our days of learning, we were always thinking all the times about programming only. Apart from BASIC, FORTRAN and PASCAL also there. Then COBOL come calling, cursing it all the time for writing few unnecessary things before finally can start doing what the program meant for. Since then it kept coming to me one after one like big missile C, C++, JAVA, VB, C#, J#. Dot net, HTML with all those script and many DataBase Packages.

In the beginning, we do not have to bother about Data Type, only thinking about Numeric Variable and String variable. Then programming like C enter the scenario and all of certain space and time complexity came to the picture, but frankly speaking no body thought us this very important thing. Anyway, let me explain what Data Type is:

Data Type: A variable is a symbolic name for a computer memory location, while declaring a variable the program must keep track of the type of data or information to be stored in the variable. This is defined as data type.

Primitive data types are those are not composed, it also known as fundamental data types. Each primitive type has - a set of values, a data representation and a set of operations. These are some example of primitive data types:

Integers: Integers are whole numbers with no fractional part. This group includes byte, short, int and long. Where byte keyword is used to declare a primitive Java data type containing an integer value in the range of negative 128 to positive 127. A byte is defined as 8 bits in length, regardless of the platform the Java bytecode executes on.
Characters:: This group includes char data type, store can a solitary letter, digit or symbol.
Floating point: A number with fraction part known as float. This group consists float and double.
Boolean: This group includes Boolean data type, which represents true/false values.
While declaring a variable with particular Data type you have to check with the memory occupation of that Data Type and declare exactly what you want and not something else it may occupy unnecessary memory space. Memory eaten by a Data Type and Range: (also take notice of different type of programming language have its different type space and range)

short : -32768 to 32767, inclusive (2 byte)
int : (for Java and higher ) - +2.15*1009 (4 bytes). (for c and c++) : -32768 to 32767, inclusive (2 byte)
long : 9.22*10308 (8 bytes)
float : + - 3.4*1034 (4 bytes)
double : + - 3.4*10308 (8 bytes)
char : from '\u0000' to '\uffff' inclusive, that is, from 0 to 65535 (2 bytes)
boolean: (2 bytes)

Non primitive types are called reference types and they have name starting with capital letter. Eg: Integer, Float etc. For these primitives you cannot create instances but for the non primitives you can create the instances.

In computer science, composite data types are data types, which can be constructed in a program using its programming language's primitive data types and other composite types. The act of constructing a composite type is known as composition. E.g. struct.

Abstract Data Type: An Abstract Data Type describes values and operations, but not representations. An ADT should protect its data and keep it valid. All, or nearly all, data should be private. Access to data should be via getters and setters. An ADT should provide: A contract, A necessary and sufficient set of operations

Some common ADTs, which have proved useful in a great variety of applications, are : Container, Deque, List, Map, Multimap, Multiset, Priority queue, Queue, Set, Stack, String, Tree.

Each of these ADTs may be defined in many ways and variants, not necessarily equivalent. For example, a stack ADT may or may not have a count operation that tells how many items have been pushed and not yet popped. This choice makes a difference not only for its clients but also for the implementation.

!!!While using Data Type, think about space and time complexity, for time being Sayonara,  next week with bit of programming rules and constant!!

Thursday, February 11, 2010

Variable - Very able and Desirable too.

Writing computer programs means storing lots of Data and Information. This directly stored in to the computer volatile memory (RAM- Random Access Memory). Therefore, when you want to store it you also have to keep a track with each. While storing these we have to name the memory location where we store the Data or Information, this is known as Variable or Identifier.

Variable is the name of the memory location given by the user to store data or information. Therefore, a variable is a facility for storing data and user can choose the name as they want but have to maintain few rules. Most of the programming languages, the rules are same.

Rules of naming variable:
  1. All variable should start with an alphabet.
  2. A numeric digit allowed.
  3. Space or special characters (Symbols) not allowed but note for few exception bellows.
  4. No keyword can be use as identifiers.
In Java, C, C++ you can use a underscore (e.g. Emp_name). In Basic, (I cannot forget you) you can use a dot(.). In addition, while storing Alphanumeric values (Alphabets, numbers and symbols) the variable should ends with a dollar ($) sign. The Variable store the alphanumeric data are also known as String
Variable. 

Example of Variable – Java, c, c++, c# - A, NO, NUM, I, I123.
Basic - A, NO, NUM For numeric variable and A$, B$, A123$ IS FOR String variable.

Keyword Reserved words that convey meaning to the computer. Used to write programming syntax. A programming syntax or statement should have at least one keyword. (E.g. Input, printf(), cout<<, int, class)

Some OOPs (Object Oriented Programming) Variable or Identifier name is case sensitive. That means if you give a variable name Num, num, Num, NUM, all will work as different name.

So once again its time to say Adio, milte hai next week with concept of Data Type, but this one for you

[Variables are free of charge but do not misuse it, do not declare more than you need, its occupy memory space and most unprofessional thing to do.]

Thursday, February 4, 2010

Extra Burden of These Two Alphabets

Hi Students!
Love to be here for you. Hope you get the best of it and your suggestions are always welcome. Before I proceed with some serious business, let us relax a bit. Computer programming and math’s somewhat is inter connected. Apart from the common logic, one common bonds between two subjects are always exists, X factors and N factors.

We always assume X and go up to N, result is a bagful irritation. Like you, I also like to get rid of both. Leave alone X, as it is looks bit harmless but ignoring N means my all names, two pet names and the biological existing stamp may look very meaningless. So left with no other option always talking in terms ‘N’ times, ‘N’ numbers and ‘N’…

I can understand your pain, I think even God have no idea about the constant value of ‘N’, otherwise by the time we would have cracked it.

Therefore, next blog I am coming up with few finer points about these dreaded Variable and then gradually move to the higher notes. Meet again break ke bad, same day same time, till then I will give you a tip
!!!Do not carry burden of X until N times, just leave it on the computer to do so.!!!