How to use Netbeans to write a Java Program

Let’s begin with a simple Java program that displays the message Hello World! on the
console by using Netbeans IDE.

Step 1: After open Netbeans IDE we select File -> New Project


Step 2: In next dialog we type Project Name and select Project Location for application


Step 3: Pass the following code into editor and click Run

public class HelloWorldApp {
    public static void main(String[] args) {
        // Display message Hello World! on the console
        System.out.println("Hello World!");
    }
}

Line 1 defines a class. Every Java program must have at least one class. Each class has a name. By convention, class names start with an uppercase letter. In this example, the class name is HelloWorldApp.

Line 2 defines the main method. The program is executed from the main method. A class may contain several methods. The main method is the entry point where the program begins execution. A method is a construct that contains statements. The main method in this program contains the System.out.println statement. This statement displays the string Hello World! on the console (line 4).

String is a programming term meaning a sequence of characters. A string must be enclosed in double quotation marks. Every statement in Java ends with a semicolon (;), known as the statement terminator.

Keywords have a specific meaning to the compiler and cannot be used for other purposes in the program. For example, when the compiler sees the word class, it understands that the word after class is the name for the class. Other keywords in this program are public, static, and void.

Line 3 is a comment that documents what the program is and how it is constructed. Comments help programmers to communicate and understand the program. They are not programming statements and thus are ignored by the compiler. In Java, comments are preceded by two slashes (//) on a line, called a line comment, or enclosed between /* and */ on one or several lines, called a block comment or paragraph comment. When the compiler sees //, it ignores all text after // on the same line. When it sees /*, it scans for the next */ and ignores any text
between /* and */.

Here are examples of comments:

// This application program displays Welcome to Java!
/* This application program displays Welcome to Java! */
/* This application program
displays Welcome to Java! */

Robert Le

I'm a full stack developer. I have experiences with Java, Android, PHP, Python, C#, Web development...I hope website http://learncode24h.com will help everyone can learn code within 24h and apply it in working easily.

View more articles Subscribe
comment No comments yet

You can be first to leave a comment

mode_editLeave a response

Your e-mail address will not be published. Also other data will not be shared with third person. Required fields marked as *

menu
menu