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 create a Java Program in intellij

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly introduces "how to create a Java program in intellij". In daily operation, I believe many people have doubts about how to create a Java program in intellij. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to create a Java program in intellij". Next, please follow the editor to study!

Prepare a project

Create a new Java project

In IntelliJ IDEA, a project helps you organize source code, tests, libraries used, build instructions, and personal settings in a unit.

Start IntelliJ IDEA.

If the screen opens with the Welcome interface, click Create New Project.

Instead, select File | New | Project from the main menu.

In the Create New Project wizard, select Java from the list on the left.

To develop Java applications in IntelliJ IDEA, you need Java SDK (JDK).

If the necessary JDK is already defined in IntelliJ IDEA, select it from the Project SDK list.

If JDK is installed on your computer but is not defined in IDE, select Add JDK and specify the path to the JDK home directory (for example, / Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk).

If you do not have the necessary JDK on your computer, choose to download JDK. In the next dialog box, specify the version of the JDK vendor, such as OpenJDK, and change the installation path as needed, and then click download.

We won't use any other libraries or frameworks in this tutorial, so click Next.

Do not create a project from a template. In this tutorial, we will do everything from scratch, so click Next.

Name the project, for example: HelloWorld.

If necessary, change the default project location, and then click finish.

Create a package and a class

Packages are used to group classes that belong to the same category or provide similar functionality to construct and organize large applications with hundreds of classes.

In the project tools window, select the src folder, press Alt+Insert, and then select Java Class.

"in the name field, enter com.example.helloworld.HelloWorld and click OK."

IntelliJ IDEA creates the com.example.helloworld package and the HelloWorld class.

IntelliJ IDEA, together with the file, automatically generates some content for your class. In this case, IDE inserts package statements and class declarations.

This is done through a file template. Depending on the type of file you create, IDE inserts the initial code and format that should be included in all files of that type.

Note: the Project tool window will Alt+1 the structure of your application and help you navigate through the project. In Java, when naming packages and classes, follow the naming convention.

Write code

Add the main () method using a real-time template

Place the caret at the end of the class declaration string after the left parenthesis {and press Shift+Enter.

Compared to Enter, Shift+Enter starts a new line without interrupting the current line.

Type main and choose to insert the template declared by the main () method.

As you type, IntelliJ IDEA recommends various constructs that can be used in the current context. You can use Ctrl+J to view a list of available real-time templates.

Real-time templates are code snippets that you can insert into your code. Main is one of these clips. Typically, real-time templates contain the blocks of code that you use most often. Using them can save you some time because you don't have to type the same code over and over again.

Call the println () method using the code completion function

After the main () method is declared, IntelliJ IDEA automatically places the caret on the next line. Next we will call a method that outputs some text to standard system output.

Type Sy from the list of code completion suggestions and select the System class (from the standard java.lang package).

Press Ctrl+. To insert a selection with a comma.

Type o, select out, and then Ctrl+. Press it again.

Type p, select the println (String x) method, and press Enter.

IntelliJ IDEA shows you the types of parameters that can be used in the current context. This information is for your reference.

Enter ". The second quotation mark is automatically inserted, and the caret is placed between the quotation marks. Type Hello, World!

Basic code completion analyzes the context around the current caret location and provides advice as you type. You can open the completion list Ctrl+Space by pressing manually.

At this point, the study on "how to create a Java program in intellij" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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

Internet Technology

Wechat

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

12
Report