Why my java programs are executing finely without using javac command?
I was having a question that why my programs are getting executed fine without using javac command which was told to use in my classroom lectures. I searched for it and got exact reason behind it. So I had a thought to share it with you friends.
The main reason behind that is the version of java which I am using. I am having the latest version of java that is java SE 15.0.1 (Here is the step by step guide to install it)
In all the versions earlier to java 11 you have to compile your code and then you can run it. here is the commands.
javac Example.java
java Example.java
But if version of java is java 11 or later you can run java by itself to compile and auto-run your code. It will work well if your code is not having any error.
java Example.java
Now the question comes in mind that if we are able to run it just by using the java command then what is the use of javac
?
I got the same, here is the answer
The work of javac command is to compile your java code and convert it into a java bytecode that is .class file which runs on the Java Virtual Machine. bytecode helps to make java platform independent.
So, even when your version of java is latest you have to use javac command to generate .class file.
Hope this may help you? if yes, Let me know in the comment section.
thanks for reading
Comments