How to write and run Java programs?

Now save the file with name demo.java on desktop. Here you can replace demo with any other name that you want.

Then open command prompt (cmd) and type cd desktop and press enter to change current directory to desktop.
We changed directory because our program is saved on desktop.

To compile java program type javac demo.java and hit enter. Type java demo to run the program. Remember that here we have to compile
with program name and execute with class name that we have used in program. The
java program name and class name can be different.

Understand the Program

System: Get reference id of the device on
which program is running. Here the device is cmd.