First Hello World! Program

web development, php, java

First of all, We understand all keyword which uses in Hello World Java Program.

class: class keyword is used to declare classes in Java

public: It is an access specifier. Public means this function is visible to all.

static: static is again a keyword used to make a function static. To execute a static function you do not have to create an Object of the class. The main() method here is called JVM, without creating any object for class.

void: It is the return type, meaning this function will not return anything.

main: main() method is the most important method in a Java program. This is the method that is executed, hence all the logic must be inside the main() method. If a java class is not having a main() method, it causes a compilation error.

String[] args: This represents an array whose type is String and whose name is args. We will discuss more arrays in the Java Array section.

System.out.println: This is used to print anything on the console like printf in C language.

Println: This is used to print for the next line. Which Together With System.out.println.

Print: This is used to print not the next line. Which Together With System.out.print.



1 package helloworld;

2

3 public class HelloWorld {

4

  • public static void main(String[] args) {
  • //Print the words Hello World on the screen

7        out.println(“Hello World”);

8    }

9

Steps to Compile and Run your first Java program

Step 1: Open a text editor and write the code as above.

Step 2: Save the file as Hello.java

Step 3: Open a command prompt and go to the directory where you saved your first java program assuming it is saved in C drive.

Step 4: Type javac Hello.java and press Return(Enter KEY) to compile your code. This command will call the Java Compiler asking it to compile the specified file. If there are no errors in the code the command prompt will take you to the next line.

Step 5: Now type java Hello on the command prompt to run your program.

Step 6: You will be able to see  Hello world program printed on your command prompt.

Scroll to Top
%d bloggers like this: