Process Advisors

ey-logo
*Subject to Terms and Condition

Hello World Program in Notepad:

Open the Notepad.

Type the following code:

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

Save the file as Hello.java. You can do this by clicking on File > Save As and then select the directory where you want to save the file. Make sure to type the filename as Hello.java and select “All Files” in the Save as type dropdown menu.

Open the command prompt and navigate to the directory where you saved the Hello.java file.

Compile the program by typing javac Hello.java and press Enter.

If there are no errors, run the program by typing java Hello and press Enter. The program will output “Hello, world!” in the console.

java -cp /tmp/jLRff3bu2p HelloWorld
Hello World

Output
Hello World

If you want to learn Java, refer to our Java Fundamentals blog.

Program Explanation

  • class: This keyword is used to declare a class in java.
  • public: It is an access modifier that represents visibility. It means it is visible to all.
  • static: It is a keyword. The advantage of the static method is that there is no need to create an object to invoke the static method if it is a nonstatic method, JVM creates objects and then calls main () method, which will give the problem of an extra memory location. That’s why main() method becomes static.
  • void: It is the return type that means it doesn’t return any value.
  • main: It represents the startup of the program. Without the main program cannot run.
  • String[] args: It tells that the main() has a parameter which is an array of String references. This array is created by the Java system just before main() acquires control. The elements of the array refer toStrings that hold text from the command line that starts the program.
  • System.out.println(): It is used print statement which is inside the ().

Learn Java

Java Comments

It is useful to place a comment in place to indicate what you are doing. It is added into the program for making the program easier to understand and these are not compiled by the compiler or interpreter. It is useful if you want someone else to be able to ever read your code.
There are two ways to declare comment in java which are as follows:

  • Single Line comment
  • Multi-Line comment

 

Single Line comment in Java:

It is used to apply the comment on a single line. To apply single line comment // is used.

Example:

System.out.println("Hello World");  // It will print Hello World

Multi-Line comment in Java:

It is used to apply the comment on multiple lines.

Example:

System.out.println("Hello World");  /*  It will print
Hello World */

Keywords in Java Programming

Keywords are also known as reserved words which express a special meaning to the compiler and interpreter. Keywords in Java are –

abstract assert boolean break
byte case catch char
class const continue default
do double else enum
extends final finally float
for goto if implements
import instanceof int interface
long native new package
private protected public return
short static strictfp super
switch synchronized this throw
throws transient try void
volatile while

Course Schedule

Name Date Details
Python Course 27 May 2023(Sat-Sun) Weekend Batch
View Details
Python Course 03 Jun 2023(Sat-Sun) Weekend Batch
View Details
Python Course 10 Jun 2023(Sat-Sun) Weekend Batch
View Details

Leave a Reply

Your email address will not be published. Required fields are marked *