Core Java Tutorial

Core Java Tutorial

Java Hello world example Program

To create a simple java program, you need to create a class that contains the main method. Let’s get into the practical example.

Step 1:

Open a notepad or any text editor and type the below program

public class Sample 
{
  public static void main(String[] args) 
  {
 
    System.out.println("Welcome to candidjava.com");
 
  }
 
}

Save the file as Sample.java (class name.java)

Step 2

Open a new cmd prompt and locate the java file where it is saved.

compile using javac sample.java, you can see a .class file generated in the same location

Run using java Sample (java classname)