java-easyfixtechnology.com

Java hello world example

Lets start java programming. We used Net beans IDE to explain java hello world example.

Firstly, You need to download java programming IDE for start learning java programming.

  1. notepad++ download https://notepad-plus-plus.org/downloads/
  2. eclipse download https://www.eclipse.org/downloads/packages/release/mars/r/eclipse-ide-java-ee-developers
  3. netbeans 8.2 download https://netbeans.org/downloads/8.2/rc/
  4. vscode download https://code.visualstudio.com/download
  5. sublime Text download https://www.sublimetext.com/3

Steps to execute Java hello world example:

  • Open your Netbeans IDE.
  • Type class name as MyFirstJavaProgram.java and click the finish button.
  • Copy example java code in your Netbeans IDE.
public class MyFirstJavaProgram { 
    public static void main(String args[]) { 
        System.out.println("Hello World"); 
    }
}
  • Press Ctrl+S to save your program.
  • Press Shift+F6 to run your program.

Output:

Hello World

If the environment is set up correctly. You can see this output on your console. That is your first Java program.

How to run a java program from command prompt?

a. Open a command prompt window and go to the directory where you saved the class.

b. Type ‘javac MyFirstJavaProgram.java’ and press enter to compile your code. If there are no errors in your code, the command prompt will take you to the next line.

c. Now, type ‘ java MyFirstJavaProgram ‘ to run your program.

d. You will be able to see ‘ Hello World ‘ printed on the window.

hello world java program from cmd

print and println difference in java

The print method simply prints text on the console but doesn’t move the cursor to a new line. The println method prints text on the console and move the cursor to a new line.

Comments in Java Programing

The comments are helping to identify the program with human-readable by placing the detail of the code involved. Comments are not used for a compiler to a java program.

Java has three types of comments

  • Single-line comments
  • Multi-line comments
  • Documentation comments

Single-line comments

It’s most uses for describe to functionality in program.

Syntax:

//Single-line comments
public class Solution { 
	public static void main(String args[]) { 
		// Single line comment here
		System.out.println("Single-line comment example"); 
	} 
} 

Output:

Single-line comment example

Multi-line comments are most uses for describe to method in a program.

Multi-line comments

Syntax:

/*Multi-comment starts
comment line 1
...
...
Multi-comment ends*/
public class Solution { 
	public static void main(String args[]) { 
		/*Multi
                  line
                  comment
                  here*/
		System.out.println("Multi-line comment example"); 
	} 
} 

Documentation comments

Documentation comments are most useful for describe to the software package. It helps to generate a documentation page for reference.

/**
* @author  Easyfix Technology
* @version 1.0
*/
public class Solution { 
	public static void main(String args[]) { 
		System.out.println("Documentation comment example"); 
	} 
} 

Java is a popular programming language and widely-used programming language for many years. You can learn java programming with examples by following our Java articles sequentially.

 650 total views,  2 views today

Leave a Comment

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

wpChatIcon