This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Wednesday 29 June 2016

C++ VS Java

Both Java and C++ support object oriented programming, yet there are differences between them. To begin with, Java is a pure object oriented programming language; therefore, everything is an object in Java (single root hierarchy as everything gets derived from java.lang.Object). On the contrary, in C++ there is no such root hierarchy. C++ supports both procedural and object oriented programming; therefore, it is called a hybrid language.

Following are the major differences between Java and C++: 

Java C++
Java does not support pointers, templates, unions, operator overloading, structures etc.
The Java language promoters initially said "No pointers!", but when many programmers questioned how you can work without pointers, the promoters began saying "Restricted pointers." Java supports what it calls "references". References act a lot like pointers in C++ languages but you cannot perform arithmetic on pointers in Java. References have types, and they're type-safe. These references cannot be interpreted as raw address and unsafe conversion is not allowed.
C++ supports structures, unions, templates, operator overloading, pointers and pointer arithmetic.
Java support automatic garbage collection. It does not support destructors as C++ does. C++ support destructors, which is automatically invoked when the object is destroyed.
Java does not support conditional compilation and inclusion. Conditional inclusion (#ifdef #ifndef type) is one of the main features of C++.
Java has built in support for threads. In Java, there is a Thread class that you inherit to create a new thread and override the run() method. C++ has no built in support for threads. C++ relies on non-standard third-party libraries for thread support.
Java does not support default arguments. There is no scope resolution operator (::) in Java. The method definitions must always occur within a class, so there is no need for scope resolution there either. C++ supports default arguments. C++ has scope resolution operator (::) which is used to to define a method outside a class and to access a global variable within from the scope where a local variable also exists with the same name.
There is no goto statement in Java. The keywords const and goto are reserved, even though they are not used. C++ has goto statement. However, it is not considered good practice to use of goto statement.
Java doesn't provide multiple inheritance, at least not in the same sense that C++ does. C++ does support multiple inheritance. The keyword virtual is used to resolve ambiguities during multiple inheritance if there is any.
Exception handling in Java is different because there are no destructors. Also, in Java, try/catch must be defined if the function declares that it may throw an exception. While in C++, you may not include the try/catch even if the function throws an exception.
Java has method overloading, but no operator overloading. The String class does use the + and += operators to concatenate strings and String expressions use automatic type conversion, but that's a special built-in case. C++ supports both method overloading and operator overloading.
Java has built-in support for documentation comments (/** ... */); therefore, Java source files can contain their own documentation, which is read by a separate tool usually javadoc and reformatted into HTML. This helps keeping documentation maintained in easy way. C++ does not support documentation comments.
Java is interpreted for the most part and hence platform independent. C++ generates object code and the same code may not run on different platforms.

There are many other subtle differences and similarities in Java and C++. Here, we included the major ones. To read more see the references section at the end.

Hope you have enjoyed reading differences between Java and C++. Please do write us if you have any suggestion/comment or come across any error on this page. Thanks for reading!

Compiler VS Interpreter


Learn the main differences between compiler and interpreter. This article tells you how source code converts into machine code and bytecode. Both compiler and interpreter take a different approach for this conversion.

“What is the difference between compiler and interpreter?”, this used to be one of the often asked question during my computer science courses. If you’re learning programming, you would definitely need to compare compiler vs. interpreter and learn the difference. Unfortunately, most of the computer science students tend to just mug up the answer without truly understanding the concept. Even a few teachers don’t know the concept of compiler and interpreter so well as to teach their students!

This morning, while speaking with one of my team members, I once again remembered this classic compiler vs. interpreter comparison and I immediately decided to write a small piece about it. This article will be useful for all the programmers wannabes.

What is a Compiler?

First of all you need to understand that computers and humans speak different languages. While humans speak languages like English, French, Hindi, Spanish, Chinese, Japanese, Arabic etc.; computers speak only one language i.e. binary. Alphabet of computers contains only two letters, namely zero and one. Computers are machines and for them it is much easier to work using a simpler encoding of 0s and 1s.
The problem is that we are not comfortable with binary and computers find our languages too difficult to understand. To get around this problem a middle path of an intermediate language is used to convey human commands to the computers. This intermediate language is called —the programming language.
Programming language is not plain English. It is essentially a predefined syntax of writing logical computer instructions which humans can also understand.
We also need something to convert programming language into binary language for the consumption by computer. This is where compiler comes in scene.
Compiler is a software that checks a computer program (called source code) and lists all the errors found. When humans remove all these errors, compiler converts the program into binary code (also known as machine code or object code). Computers can understand binary code and therefore they can execute instructions written by humans using programming language.



Compiler vs. Interpreter
Now we already know what a compiler does. Task of interpreter is also more or less the same but interpreter works in a different fashion. The difference between the functioning of compiler and interpreter will be clear from the table of comparison given below:
#CompilerInterpreter
1Compiler works on the complete program at once. It takes the entire program as input.Interpreter program works line-by-line. It takes one statement at a time as input.
2Compiler generates intermediate code, called the object code or machine code.Interpreter does not generate intermediate object code or machine code.
3Compiler executes conditional control statements (like if-else and switch-case) and logical constructs faster than interpreter.Interpreter execute conditional control statements at a much slower speed.
4Compiled programs take more memory because the entire object code has to reside in memory.Interpreter does not generate intermediate object code. As a result, interpreted programs are more memory efficient.
5Compile once and run anytime. Compiled program does not need to be compiled every time.Interpreted programs are interpreted line-by-line every time they are run.
6Errors are reported after the entire program is checked for syntactical  and other errors.Error is reported as soon as the first error is encountered. Rest of the program will not be checked until the existing error is removed.
 7A compiled language is more difficult to debug.Debugging is easy because interpreter stops and reports errors as it encounters them.
 8Compiler does not allow a program to run until it is completely error-free.Interpreter runs the program from first line and stops execution only if it encounters an error.
 9Compiled languages are more efficient but difficult to debug.Interpreted languages are less efficient but easier to debug. This makes such languages an ideal choice for new students.
10Examples of programming languages that use compilers: C,  C++, COBOLExamples of programming languages that use interpreters: BASIC, Visual Basic, Python, Ruby, PHP, Perl, MATLAB, Lisp

Following image shows how different languages are either compiled or interpreted:
Difference between compiler and interpreter.

Difference between Compiler and Interpreter

So, what did we understood from the above table of comparison? We now know that the reason a compiled runs faster because it gets converted into machine code all at once. Computer can easily understand machine code and therefore can run the whole program quickly. But this also means that the entire compiled code has to reside in the memory —and thereby making the compiled programs more memory guzzling. With memory available in abundance, nowadays, this is no longer a concern. But in earlier days of programming, when memory was an expensive resource, program size up to every bit and byte used to matter.
In comparison, interpreter is a more human-friendly program. It works quite a bit like humans work. It begins program execution right at the first line and will go on showing you the result of the program until it will hit an erroneous line of code. As a result, for programmer it is much easier to locate error and to understand the nature of error. However, interpreter is slow. An interpreted programs gets interpreted every time it runs.
Java is Both a Compiled and Interpreted Language Ah! Java is an amazing programming language. Designed originally by James Gosling, this language encompass several innovative features. One of such features is Java Virtual Machine (JVM). Also, Java is both a compiled and interpreted language. When you write a Java program, the javac compiler converts your program into something called bytecode. All the Java programs run inside a JVM (this is the secret behind Java being cross-platform language). Bytecode compiled by javac, enters into JVM memory and there it is interpreted by another program called java. This java program interprets bytecode line-by-line and converts it into machine code to be run by the JVM. Following flowchart shows how a Java program executes.




Execution of a Java program. Java is both a compiled and interpreted language.
I hope this article helped you in understanding the concepts of compiler and interpreter. If you have any further questions on the difference between compiler and interpreter, please feel free to comment and ask me. I will most certainly try to assist you.

Tuesday 28 June 2016

C VS C++ Programming Languages



Let’s learn the major differences between C and C++ programming languages. C++ offers excellent object orientation programming (OOP) paradigm. Nevertheless, C is still the most widely used in software development.
This is one of the most asked question in the Computer Science courses. If you have done a computer science, information technology or related courses, chances are that you’ve faced this question asking you to explain “major differences between C and C++ programming languages”. And of course, most of you would have listed several such differences. Let’s explore this important question and make a comprehensive list of differences between C and C++
Before, we get into a bit technical stuff let’s recap what are C and C++. Well, C is probably the most widely used computer programming language. C was originally developed by Dennis Ritchie between 1969 and 1973 at AT&T Bell Labs. The reason why C has been so popular lies in the efficiency with which C converts into machine instructions. This efficiency has made the applications written in C super-fast.
A list of differences between C and C++ programming languages.
A list of differences between C and C++ programming languages.
Major differences between C and C++

Following table contains various points where C and C++ programming languages differ from each other.
#CC++
1C is a procedural (aka structural) programming language.In addition to begin procedural, C++ is also an object oriented programming language.
 2In C language, the solution is achieved through a sequence of procedures or steps. Therefore, C is a function driven language.C++ can model the whole solution in terms of objects and that makes the solution better organized. C++ is an object driven language.
 3Concept of virtual functions is not present in C.C++ offers the facility of using virtual functions.
 4Operator overloading is not possible in C.C++ allows operator overloading.
 5Data in C functions is not secured. Data can be easily accessed by other external functions.All the data in C++ can be put inside objects. This provides better data security.
 6C is a middle level language.C++ is a high level language.
 7C programs are divided into modules and procedures.C++ programs are divided into classes and functions.
 8C programs use top-down approach.C++ programs use bottom-up approach.
 9In C, the main() function can be called from other functions.In C++, the main() function can not be called from other functions. The program execution begins from main() function.
 10C language does not provide the feature of namespace.Namespaces are available in C++.
 11Exception handling is not easy in C. It has to be done by using other functions.C++ provides exception handling through Try and Catch block.
 12Inheritance is not possible in C.Because C++ is an object oriented language, inheritance is possible.
 13In C, all the variables must be declared at the beginning of a scope.C++ allows declaring variables anywhere within the scope. This allows us to declare a variable when we use it for the first time.
 14In C, function overloading is not possible. Function overloading is to use two functions with the same name within a scope.Function overloading is possible in C++
 15Standard Input in C is received through scanf() function whereas standard output is given through printf() function.C++ uses cin>> and cout>> as standard input and output functions respectively.
 16C programs are saved in files with extension .cC++ programs are saved in files with extension .cpp
 17Mapping between data and functions is difficult in C.In C++ data and functions are easily mapped through objects.
 18In C, polymorphism is not possible.Being a fully object oriented language, C++ offers polymorphism.
 19C supports only built-in data types.C++ supports both built-in and user-defined data types.
C++ is the object oriented and updated version of C language.Therefore, C++ not only shares a lot of C features but also provides new features, such as object-orientation. As a result, most of the C++ compilers can also compile C programs. Following Vann diagram shows how C and C++ share features and how different they are:
C++ contains almost all of C.
C++ contains almost all of C.
The following graph shows the usage of various programming languages between 2002 and 2015.
Comparison of usage of various programming languages during 2002 and 2015. Source: TIOBE index.
Comparison of usage of various programming languages during 2002 and 2015. Source: TIOBE index.
As you can see, the use C language has been more or less steady during last 14 years. In comparison, Java and C++ have been going out of favor.

So, these are the major differences between C and C++ programming languages. Of course, there are lots of other differences as well, do let me know if you want me to include anything in the list.