August 21, 2020

Compile and Run simple Java Program -- beginners guide.

First we need to type simple program that say famous 'hello, world!' message on screen. lets dive into our code.

class Welcome {
	public static void main(String[] args){
		System.out.println("Hello, World!");
	}
}

That's it.

In java things are get done inside the class. Class contain methods and properties. In our example there is only one method called main and no properties. Name of our class is Welcome. Main method is entry point of Java program.

In order to compile (convert intermediate code) and run (interrupt by JVM) you have Java installed on your machine. To check this, issue the following command on your terminal (Linux) or CMD (window):

javac

If you got some message other than similar "command not found!" then you have Java installed on it. Other wise head on oracle site and download and install latest java JDK in your machine to move further.

Make sure you are in your program directory where your Welcome.java file is resides.

From there issue the command "javac Welcome.java" which generate byte code which is executed by JVM.

If the above command successful then issue the command "java Welcome" which print result of your java program "Hello, World!".

That's it.