Compile java with netbeans

Java Quick Start Tutorial

In this tutorial, which should take about 10 minutes to complete, you are given a quick introduction to the basic Java development workflow in NetBeans IDE.

The aim of this tutorial is to get you started with Java development with Maven in NetBeans IDE. Though not needed to complete this tutorial, to get started understanding and working with the Java language itself, see the Java Tutorials, and to understand Maven, the Apache Maven Website.

Setting Up the Project

Take the steps below to set up a new Java project.

  1. In the New Project wizard, select Java Application, as shown in the figure below. Then click Next.

proj wizard maven2 small

The first time you create a new Java project, you will be prompted to download and enable support for Java. Follow the prompts and install as recommended by the wizard.
  1. In the Name and Location page of the wizard, type HelloWorldApp in the Project Name field, (as shown in the figure below):

proj wizard2 maven small

The project is created and opened.

Creating a Java Source File

Right-click the package name and choose New | Java Class, (as shown in the figure below):

proj wizard3 maven small

In the New Java Class wizard, type Main in the Class Name field, (as shown in the figure below):

proj wizard4 maven small

The Java source file is created and opened.

You should see the following components, (as shown in the figure below):

  • Projects window: Top left, contains a tree view of the components of the project, including source files, libraries that your code depends on, and so on.
  • Source Editor: Central area, contains files, where most of your work will be done, currently with a Java source file called Main open.
  • Navigator: Lower left, useful for quickly navigating between elements within the selected class.
Читайте также:  Threading примеры python 3

proj opened maven small

Adding Code to the Java Source File

A skeleton main class has been created for you. Let’s add some basic content to produce a ‘hello world’ message.

  1. Between the braces, type psvm and press Tab . You should now see public static void main statement.
  1. Within the public static void main statement, type sout and press Tab . You should now see a System.out.println statement.
  2. Within the quotation marks, type hello world .

You should now see the following:

file opened maven small

Notice that when you press Ctrl + Space , the editor shows you multiple ways of completing the code at the cursor, as well as related documentation:

editor cc maven2 small

Running the Application

Make sure to save the Java source file, right-click the project and choose Run or choose Run Project under the Run menu. Click Select Main Class.

In the Output window (which can be opened from the Window menu), you should see the below.

run output maven small

Congratulations! Your application works.

You can view the build output by opening the Files window (from the Window menu) and expanding the target node.

You now know how to accomplish the most common Java development tasks. To learn the complete Java development workflow, including testing and debugging, see Developing General Java Applications.

Источник

Оцените статью