You can run Java source code without compiling ! Bye Bye javac !!!

Image from Google Search

Java 11 came up with a cool feature to execute source code in single file without compiling it pre-hand

Lets assume Vicky.java file contains following beautiful world changing source code

For ages, we do the following

But from Java 11, its further simplified like below

So how it works ?

  • From Java 11, java command can compile as well as execute the Java source file
  • Remember, no .class file will be created while running java Vicky.java

Ok what if there is more than one class defined in same Vicky.java file ?

  • java command executes the main method from the 1st class
  • public keyword in class Vicky proved insignificant in this case

Though these are small features, I feel its right step towards simplifying Java…

Thanks for reading..

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store