How Java Program Works, Compiler, Interpreter | Java Tutorial

Hi welcome to the second tutorial on java programming language. This video tutorial is the production of theyoutube channel Learning Lad and and in this video tutorial we are gonna learn about thecompilers, the interpreters and also we are gonna learn how a java program works or youknow the process or the steps involved in running a java program.All right lets get started.

So the first thing is executing the programs.So the computers can only understand the code in the binary form which is you know 0’s and1’s and all of you know that when we write the code in the higher level programming languagessuch as java or c++ you kno the statements are gonna be somewhat English like and youknow that form of statements are easy for us to read and understand the program butfor the computer you know it can’t understand the code in the higher level form.So we need to convert that to the binary form.

So all of you know that you know when youwrite a program in c or c++ or java or any other programming language, and that is calledthe source program or the source code. So what we can do is we can translate oursource code you know which is in higher level form to a machine level form which the computerscan understand and execute.

All right.The translation can be done using another programming tool which is called as interpreteror a compiler. So this interpreter and compilers are normallyused to translate the code from one form to another form.And these two are gonna work differently and we are gonna see that next.

So first of all what is a compiler? A compiler is a program which translates theentire souce code into the machine code or you know any other intermediate code you knowwhich can be used to execute the program. So lets see how the compiler works.So first you know we are gonna have the source code written in the higher level languagessuch as c, c++ java or any other.

and then we are gonna use the compiler andtranslate this code to the machine level code or any other intermediate form you know whichwill be optimized form of this source code and then we are gonna use another softwareor program called executor to execute the compiled code.So this is how the compiler works. You know this compiler is gonna read the entiresource code and its gonna convert that to the machine level code or any other intermediateform and then that converted code will be used along with the executor and the outputis generated or got. And then we are gonna see about the interpreter.

So what is a interpreter? An interpreter is a program which reads onestatement from the source code at a time and translated it to machine code or virtual machinecode and then executes that right away. So first we are gonna have the source programand then we are gonna use the interpreter and this interpreter is gonna read one statementfrom the source or you know one statement from the input to that interpreter and thenits gonna translate that and its gonna execute that statement right away and then its gonnacontinue with the next statement its gonna translate that to machine code and executethat and again its gonna take the next statement its gonna translate that and execute that.And similarly its gonna do for the entire code.

So the difference between the compiler and the interpreter is that you know the compileris gonna take the entire source code first and its gonna convert that to the intermediateform or the machine level form and then we are gonna use another software called executorto run the compile code. But with interpreter, you know its gonna readone statement at a time from the source and then its gonna convert that to the machinelevel form, and then its gonna execute that line of statement right away and then it willcontinue with the next statement.

So the next thing is you know how java works?or you know the steps involved when you write a java program and execute a program.So first we are gonna have the java source code.and you know java source code will be saved with the extension of .javaAnd then we are gonna use the java compiler and we are gonna compile the code and we aregonna get the java byte code.

So this java byte code is gonna have the .classextension. So this java byte code is a modified versionor you know the optimized version of this java source code.And then we are gonna pass this java byte code to the java virtual machine or jvm whichis a interpreter. So its gonna read one statement at a timefrom this java byte code and its gonna convert that to the machine level code and its gonnaexecute that.

And then again its gonna continue with thenext statement and its gonna convert that and execute that and similarly its gonna executeyour java program. So we are gonna get the output after executingour program by our java interpreter or you know the java virtual machine. And also in the previous tutorial i have toldyou that you know we are gonna write the java code only once and then we can execute thatsame code in different different platforms.

So we can execute our code in windows, andalso we can execute our code in mac and also we can execute our code in Linux platform.So how it is possible? So what we have is the jvm or the java virtualmachine which is the one which is gonna execute our java byte code.So java provides platform specific java virtual machines.So if you are using windows platform then you are gonna have the windows specific jvm,and for Linux we are gonna have the linux specific jvm, and for mac we are gonna havethe mac specific jvm or java virtual machine.

So all these platform specific jvm or javavirtual machines are capable of executing the java byte code in the same way.So when we pass the java byte code to the jvm in windows its gonna execute that andalso when you pass the same java byte code to linux and mac its gonna execute it in thesame way. So this is how our java program is capableof running in different different platforms. we are gonna have the different platform specificjava virtual machines. that’s it. So this is it guys this is about some informationon the compilers, the interpreters and steps involved in running a java program.

Leave a Comment

Your email address will not be published. Required fields are marked *