Intro to Programming

There is a question comes in everyone's mind before getting started with coding or ds algo or Competitive Programming(cp) - Which is the best programming language to get started with? And truly it's quite important to figure out the language which is most suitable for you. So we're just going to recommend you two languages-

  1. C++
  2. Java

Now, If you are interested in doing some development and also wanted to learn ds algo and cp, definitely choose Java.

But if your main focus is cp and wanted to do game development or likes to work on Operating System then choose C++.

C++

C++ is a programming language which can be used to develop games, operating systems, Graphical User Interfaces(GUI) etc. It supports procedural programming object-oriented programming (OOPs), functional programming(FP), etc. C++, developed by Bjarne Stroustrup, is a relatively faster programming language in comparison with other and That's why it is most recommended and widely used in Competitive coding rounds. It consists some rich libraries like Standard Template Library(STL) which includes template classes that has various data structures such as stacks,lists,trees,graphs, arrays, etc

Java

JAVA another most recommended programming language for Competitive Programming. It is developed by Sun Microsystems and is used to build large class applications. Java works great within corporate environments, although it can be used for small tasks, it's less suited for that. Many popular IDE's and tools are are written and developed in Java such Eclipse, IntelliJ IDEA and NetBeans IDE. In this course I will pick Java as a programming language for learning data structures and algorithms. It has various features like OOPs, Functional Programming, Generics, etc. It is relatively more stable than other and it also has multi-threading support. Java is very efficient at memory management and it is very fast.

Java Plateform Independent

As you may have hear from others that Java is a platform independent language, so what does it mean basically lets understand.

lets we have,

      code           machine
    c = a + b  -->   Binary
 (human-readable)   (base-2)
                       /\
                      0  1

Binary is base-2 number system. which is basically 0 and 1. We write the code which is by the way human readable, computer can not understand it that's why we need to convert it into binary. so somehow we need to bridge this gap. Now it's like there are two people talking in different languages and they wanted to communicate with each other. Similarly here at the one end we have a high-level language like Java & C++ and on the other hand a hardware which understand only binary therefore we need a sort of imediator to bridge this gap. This imediator comes into the picture is called Compiler. so this conversion(Human-readable to binary) done by this compiler okay. Now Let's talk about both the languages C++ and Java and how the compiler works.

        code  (.cpp)
          ↓
       compile
          ↓   (.exe or a.out)
       machine

In case of C++, first our code which is in .cpp file is compiled and then a new .exe or a.out file generated by compiler. And that .exe or a.out file is run on the machine or Plateform. Now the binary outcome(compiled outcome) is different on different plateforms means if we are using Windows, then the compiled outcome is an .exe file. If we are using Linux or Mac, then the compiled outcome is an a.out file.

Now this brings us to a problem which is if we want to share the compiled ooutcome with someone, we cannot directly do that because that compiled code might not work on the other machinne or plateform. now the question arises how do we share our code with someone? well we can share the source-code (.cpp) file but generally we don't do that cuz we don't want to share our private code. This is a problem with C++. Now Java is different from C++ in that this problem is something delt in java and you don't have to worry about it.

        code  (.java)
          ↓
   ←-------compile-----------|         |   (.class)    |
   |         |               |
   |         |               |
   ↓         ↓               ↓
Plateform1 Plateform2  Plateform3

In case of Java the compiler compiles the .java file and generates a .class file. So the compiled outcome is the same on all plateforms. we can share that .class file with anyone without sharing our actual source-code.

Now how is that happen in java? Does that mean that all plateforms understand the same binary outcome? No all plateforms have their own binary outcome and it's different. so how is that happen? okay so JVM(Java Virtual Machine) comes into the action. JVM is another layer which is there in between compiler and plateform. JVM is a virtual machine which is a program which runs on the plateform and it's responsible for converting the human-readable outcome into the binary outcome. So different plateforms have different JVM's and it converts .class file into the relevant binary outcome that need to run on particular hardware.

Now I think you got the point. This is why Java is called Plateform Independent. Now lets move further.