Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand and learn Netbeans

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

How to understand and learn Netbeans, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Netbeans organizes the code according to Project, and each executable Java program is a Project. So, the * * step to start work with Netbeans is to create a new Project in Netbeans, which can make use of the menu in Netbeans: File- > New Project...,. After selecting this menu, Netbeans will prompt a dialog box asking for the type of Project. Because only the Application of Java is introduced here, select "Java" on the left side of the dialog box, select "Java Application" on the right side, and then follow the Netbeans prompt. After entering the name of Project, follow the default prompt. All the way down next, you can see that Netbeans has created a new Project and generated a file called Main.java in this Project. This is the source file of Java, and you can write some basic Java code in this file.

There can be multiple files in a Project, and each file can write Java source code. The Java source code file must have a .java extension. Java programs are composed of Java source files one by one.

If you want to execute the code you write, there are two ways in Netbeans:

(1) Open the source file you wrote. If the source file meets the executable conditions, you can click the right mouse button, select "Run File" from the pop-up menu, or press the shortcut key "Shift+F6".

(2) run the code according to the settings of Project. At this time, just select Run- > Run Main Project in the Netbeans menu. Note that if multiple Project is established in Netbeans, Main Project is running at this time. For an introduction to Main Project, please see below.

Here is how Netbeans organizes Java programs and some basic knowledge of the Java language.

Java organizes programs in terms of "class". There can be one or more class definitions in each Java source file, but it is customary to store only one class definition in a Java source file. Class (class) is the basic unit for writing Java programs.

As we all know, programs are made up of code, and in most programming languages today, code is written in functions, which is how C language organizes programs. Java in the three basic code (that is, order, selection, loop) syntax is basically the same as C language, its code should also be written in the function, but Java further requires that the function must be written in the class, data, that is, the definition of variables, constants, and so on, must also be written in the class. The class is written in a source file with a .java extension.

A program is often made up of multiple source files, and NetBeans uses Project to manage them, and each Project represents a type of Java program, such as a website or an enterprise application. Netbeans provides a variety of Project options for programmers. We are learning Java applications, so the type of Project we chose before is Java Application.

The way to create a Project in Netbeans is through the File- > New menu, which can be used repeatedly so that programmers can create a variety of Java applications. In this way, there may be multiple Project in the Netbeans, but only one of these Project is active, that is, when you use the Netbeans menu to complete the compilation, running and other work, these work can only work on a Project, the Project is called Main Project. When you create a Project with the File- > New menu, the Project automatically changes to Main Project, and the name of its project is displayed in boldface.

When you create a Project using the File- > New menu, each Project created causes the Main Project to change to the currently newly created Project. If you want a non-Main Project to become a Main Project, right-click the Project and select "Set As Main Project" from the pop-up menu. This is important for beginners, because when you want to run Project, if the Project is not Main Project, the result is the result of a program running in another Main Project, not the current Project.

The following figure shows the above:

Project1 (Main Project)

| |

|-Class1.java (the source file where the class Class1 is located)

| | |

| | |

|-Class1 (definition of class Class1) |

| | |

| |-definition of variables and constants in Class1 |

| | |

| |-function definition in Class1 |

| |

|-Class2.java

| |

| |-the source file where other class definitions are located |

| |

Project2 (not Main Project, the color of the Project is not the color of boldface)

| |

| |

| |

ProjectN

Let's introduce some knowledge of the semantic methods of Java:

Java uses the keyword class to define classes in the following format:

Class class name {

}

The front of the class can be decorated with or without the public keyword. If a class is decorated with public, according to Java, the source file name of the class must be the same as the class name of the class, for example:

The definition of class Class1:

Public class Class1 {

Int a word / this is the variable definition in the class

Void printA () {

/ / here is the code in the function

}

}

At this time, because the definition of the class Class1 is modified by a public keyword, the definition code of the Class1 must be stored in a source file called Class1.java, otherwise it will lead to compilation errors.

In order to avoid the association between this class name and file name, using Netbeans to write Java programs, to add a new class, you can use the leftmost button in the toolbar, click, in the pop-up dialog box to select Java Class, this wizard will automatically generate a class you specify the source file and generally the code, you can generate code on the basis of further learning to write the class.

Why does Java require functions to be written in the class? This is what Java calls an object-oriented feature. The ultimate goal of programming is to give the complicated things originally done by people to the computer, and the programming language is the tool to accomplish this work. When human beings are doing things, the main body of things is someone who will think about how to do it according to the information they have when doing things; that is to say, when people do things, they consider the data and the methods of processing data together. In fact, object-oriented programming simulates this feature, which uses classes to abstract a task that needs to be done: the data that completes this task is the variables and constants defined in the class in the Java language; and the steps to do things, in the Java language, are the code written in functions. Facts have proved that designing code with class as the main body can express the tasks involved in programming more effectively.

We can compare this approach with the C language, where the basic unit of writing a program is a function, and the data processed by the function is not explicitly placed with the function. To pass this data, either through global variables, or through the parameters of the function, which makes the writing of the function very complex when dealing with more data. On the other hand, Java language takes class as the basic unit of writing program. by reasonably distributing the defined data and functions in each class, when dealing with a large number of data, the program can group the data according to the class, and then design the related functions according to the grouped data, thus effectively solving the problem that a large number of parameters need to be transferred in C #.

In fact, the design class is only a step in object-oriented programming, and the design of the class is equivalent to completing a drawing to do things. In order to actually complete the tasks according to these drawings, the tasks described in the drawings must be carried out. This is to call the data and functions defined in these classes in the Java language. how to call the data and functions in these classes? That is, how do you use these defined classes?

First of all, it needs to be clear that there are two types of data in Java:

1. Basic data types, also known as value types, are similar to those basic data types in C, such as integers, floating-point types, etc.

2. The compound data type, also known as the reference data type, is the class defined by the programmer in the source file. In fact, the class is similar to the structure data type in C, unlike the structure, it has both the definition of internal members and the definition of functions.

In Java program, the essence of programming is to use compound data types to encapsulate the processing of basic data. Once the class is designed, it is equivalent to having a new data type. If you want to use this new data type, you need to use this data type to declare a variable, and then use that variable to use the data defined in the class, or call the function defined in the class. This is how classes are used in the Java language.

Declaring a variable with a class is similar in form to defining an ordinary variable, such as:

Class1 c1

This form is very similar to the variable that defines the structure type in C language, but unlike C language, after the variable of structure type is declared, the data it contains will automatically allocate memory, and the variable of this type of Java class must be explicitly allocated to its memory, otherwise, it will not be available. The syntax of the assignment is as follows:

C1=new Class1 ()

You can also combine these two sentences:

Class1 c1=new Class1 ()

After defining a variable of type Class1 named C1, how do you call the variables and functions defined in Class1?

Variables defined in a class can be referenced in this way:

C1. Variable name

As you can see, the way variables defined in the class are referenced in Java is the same as the way structural members are referenced in C.

For functions defined in a class, you can call them in this way:

C1. Function name (actual argument list)

After defining how the class is used, where does the above statement that makes calls to variables and functions in the class start?

Here we need a starting point for program execution. Like C, Java has a function called main, but Java has a series of requirements for this function, that is, this function must be defined as follows:

Public static void main (String args []) {

/ / write execution code

}

In this function, the code for the data and functions in the above calling class is written here and it is executed.

To sum up, Java's programming steps can be done in the following three steps:

1. Consider the problem to be solved and see how many parts it can be solved, what data each part needs and the functions that deal with it.

2. According to the sections listed in step 1, design the class and define the data and functions to be processed in the class

3. Consider how these designed classes are called, and write the called code in one of the following functions:

Public static void main (String args []) {

/ / write execution code

}

Because Java requires that all functions be defined in a class, the main function should also be defined in a class, and it is customary to put the main function in a separate file, where the class is defined, which is called the main class of the Java program (when Netbeans generates Project, it generates the code of the main class by default and gives it a name called "Main").

In Java, because variables or constants are defined in the class, the variables or constants defined in the class are called "fields", some books call them "properties", and some books call them "data members"; and functions are also defined in the class, commonly referred to as "methods".

In a Java program, theoretically, there should be only one class with main methods (functions), but sometimes, for programming convenience, there may be more than one class that contains main methods. Any class that contains main methods can be run. In Netbeans, right-click in this file and you can run it directly. This is the way to run Java programs mentioned at the beginning. The second way mentioned above is to run the Java program by selecting Run- > Run Main Project, which requires Main Project to specify which class the main method is to run. By default, when you create a Project, the main method in the Main class in the generated Main.java selects the method that runs Run- > Run Main Project. If you want to change this setting, you can right-click on the project name, select "Properties" in the pop-up menu, select the "Run" node on the left side of the pop-up dialog box, and then enter the class name that contains the main method in the "Main Class:" edit box on the right, or click the "Browse" button on the right side of the edit box to let Netbeans help you specify the main class to run.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report