Some important points to remember before writing a Java program are:
Java programs can be written in any text editor, such as Notepad, Notepad++, NetBeans, Eclipse, etc. However, before installing any editor, you must install the Java Virtual Machine (JVM). In this tutorial series, I will be using Visual Studio Code editor for writing programs.
Example 1: Write a Java first program to display the message "Hello World".
class First { public static void main(String args[]) { System.out.println("Hello World"); } }
Save the program as "First.java", Open the 'Command Prompt', navigate to the directory where you saved the program, and type the following commands:
public static void main(String[] args) public static void main(String []args) public static void main(String args[]) public static void main(String... args) static public void main(String args[]) public static final void main(String[] args) final public static void main(String[] args)
public void main(String[] args) static void main(String[] args) public void static main(String[] args) abstract public static void main(String[] args)
Example 2: Find the Sum of 2 numbers.
class Sum { public static void main( String args[] ) { int a=10, b=20, c; c = a + b; System.out.println("Sum = " + c); } }
Having a semicolon at the end of a class in Java is optional.