In this tutorial, You'll learn about the simple program of java programming. This tutorial covers java basic syntax, we'll show you run java program from the terminal.
Simple Program of Java
import java.lang.*;
class Simple{
public static void main(String args[]){
System.out.println("HelloWorld");
}
}
C:\Users\codeamy>javac Simple.java
C:\Users\codeamy>java Simple
HelloWorld
In this, we will see the internal details of simple hello world java program. You have to write one java program if you are new to java then take help from our previous tutorial of the java hello world program.
You can use any text editor to write your program like windows - Notepad, Sublime Text, Atom, Brackets, etc., and for Linux - Gedit, Vim, etc.
What will happen at Compile Time with Java Program
What happens at Runtime
Run Java Program in Terminal
- Open Command Prompt(cmd.exe).
- Go to the location where you save your java source code file.
- Type javac command to compile your java file.
- To execute your type java to execute .class file.
Note: Save your text file with .java extension and Your name of java file must be same as the class name.
A class name first letter always starts with Uppercase. These are some rules to write java code.
Java is case sensitive language, i.e. Codeamy and codeamy both are different.
What will happen if you can save your java source code file with any other name, not as class name.
- To compile java code: javac Simple.java
- To execute compile code: java Helloworld