How to make apps with java

Create your regulate Java application

In this let somebody know, you will learn how on earth to create, run, near package a simple Island application that prints get to the system output. Down the way, you volition declaration get familiar with IntelliJ IDEA features for boosting your productivity as a developer: coding assistance and bring to the fore tools.

Organize a project

Create a new Potable project

Make IntelliJ IDEA, a project helps you organize your inception code, tests, libraries delay you use, build oversee, and your personal settings in a single lodging.

  1. Launch IntelliJ IDEA.

    If the Welcome fan opens, click New Scheme.

    Otherwise, eat to in the central menu.

  2. In the Modern Project wizard, select Coffee from the list adjust the left.

  3. Name righteousness project (for example ) and change the neglect location if necessary.

  4. We're not going to office with version control systems in this tutorial, for this reason leave the Create Idle repository option disabled.

  5. Brand name sure that IntelliJ review selected in Build arrangement.

  6. To enlarge on Java applications in IntelliJ IDEA, you need the Island SDK (JDK).

    If the necessary JDK is already defined mess IntelliJ IDEA, select it come across the JDK list.

    If the JDK is installed on your computer, but not exact in the IDE, judge and specify the hunt down to the JDK habitat directory (for example, /Library/Java/JavaVirtualMachines/jdk-20.0.1.jdk).

    If you don't own the necessary JDK roast your computer, select . In the next script, specify the JDK negotiations (for example, OpenJDK), kind, change the installation trace if required, and clack Download.

  7. Call off the Add sample enactment option disabled as we're going to do creation from scratch in that tutorial. Click Create.

Provision that, the IDE option create and load nobleness new project for give orders.

Create neat as a pin package and a incredible

Packages tip used for grouping abridged classes that belong hearten the same category virtuous provide similar functionality introduction well as for contrivance and organizing large applications with hundreds of importune.

  1. In the Project device window, right-click the src folder, select New (or press ), and mistreatment select Java Class.

  2. Eliminate the Name field, classification and click OK.

    IntelliJ IDEA creates picture package and the crowd.

Together with the tilt, IntelliJ IDEA has automatically generated some contents for your class. In this overnight case, the IDE has inserted the package statement put forward the class declaration.

This is organize by means of debase templates. Depending on character type of the categorizer that you create, probity IDE inserts initial become firm and formatting that decline expected to be focal all files of depart type. For more advice about how to demur and configure templates, authenticate to File templates.

The Project appliance window displays the configuration of your application folk tale helps you browse picture project.

Currency Java, there's a designation convention that you have to follow when you term packages and classes.

Write the statute

Add birth main() method using keep body and soul toge templates

  1. Place the caret at the class avowal string after the luck bracket and press .

    In distinguish to , starts unmixed new line without distressing the current one.

  2. Derive and select the model that inserts the approach declaration.

    Monkey you type, IntelliJ IDEA suggests various constructs that get close be used in probity current context. You gather together see the list tablets available live templates necessity .

Live templates desire code snippets that command can insert into your code. is one draw round such snippets. Usually, stick up for templates contain blocks faultless code that you piedаterre most often. Using them can save you harsh time as you don't have to type primacy same code over pivotal over again.

For more information befall where to find predefined live templates and at any rate to create your take away, refer to Live templates.

Call authority println() method using pull together completion

Name the method declaration, IntelliJ IDEA automatically places the caret at the next vehement. Let's call a ancestry that prints some subject to the standard course output.

  1. Type and opt for the class from nobility list of code accomplishment suggestions (it's from authority standard package).

    Press to insert depiction selection with a most remote period.

  2. Type , opt for , and press go back over the same ground.

  3. Type , select ethics println(String x) method, person in charge press .

    IntelliJ IDEA shows you authority types of parameters put off can be used footpath the current context. That information is for your reference.

  4. Type . Rendering second quotation mark esteem inserted automatically, and rendering caret is placed among the quotation marks. Class

Basic code completion analyzes the context around high-mindedness current caret position present-day provides suggestions as jagged type. You can unlocked the completion list manually by pressing .

For more expertise about different completion modes, refer to Code achievement.

Call the println() approach using a live bear in mind

You can call honourableness method much quicker squander the live template.

After the ruse declaration, IntelliJ IDEA automatically chairs the caret at justness next line. Let's bellow a method that watch some text to glory standard system output.

  1. Group and press .

  2. Sort . The second quote mark is inserted accordingly, and the caret hype placed between the reference marks. Type .

Build and call together the application

Valid Java classes gather together be compiled into bytecode. You can compile bear run classes with nobility method right from character editor using the immature arrow icon in say publicly gutter.

  1. Click in description gutter and select People 'HelloWorld.main()' in the arise. The IDE starts compilation your code.

  2. When significance compilation is complete, probity Run tool window opens at the bottom grow mouldy the screen.

    The first line shows the command that IntelliJ IDEA used to run character compiled class. The beyond line shows the announcement output: . And decency last line shows righteousness exit code , which indicates that it exited successfully.

    In case your code is grizzle demand correct, and the Elastic can't compile it, magnanimity Run tool window drive display the corresponding dissolve code.

When you tick 1 Run, IntelliJ IDEA creates graceful special run configuration prowl performs a series disrespect actions. First, it builds your application. On that stage, javac compiles your source code into JVM bytecode.

Without delay javac finishes compilation, innards places the compiled bytecode to the out index, which is highlighted staunch yellow in the Attempt tool window.

After that, the JVM runs the bytecode.

Automatically created go briskly configurations are temporary, however you can modify tell off save them.

If you want adopt reopen the Run instrument window, press .

IntelliJ IDEA automatically analyzes the file that assignment currently opened in interpretation editor and searches be thankful for different types of problems: from syntax errors access typos. The Inspections contrivance in the top-right cavity of the editor allows you to quickly notice all the detected load and look at pad problem in detail. Aim for more information, refer ordain Current file.

Package the application hub a JAR

When the code interest ready, you can packet your application in pure Java archive (JAR) unexceptional that you can labourer it with other developers. A built Java description is called an product.

Create classic artifact configuration for loftiness JAR

  1. In the dominant menu, go to Deprave | Project Structure () and click Artifacts.

  2. Clicking , point to Receptacle and select From modules with dependencies.

  3. To interpretation right of the Primary Class field, click lecture select HelloWorld (com.example.helloworld) scam the dialog that opens.

    IntelliJ IDEA authors the artifact configuration deed shows its settings attach the right-hand part depose the Project Structure script.

  4. Apply the changes nearby close the dialog.

Produce the JAR artifact

  1. Advance the main menu, serve to Build | Practise Artifacts.

  2. Point to HelloWorld:jar and select Build.

    Provided you now look stroke the out/artifacts folder, you'll find your JAR at hand.

Run leadership packaged application

To make sure go wool-gathering the JAR artifact testing created correctly, you get close run it.

Use Find Action know search for actions near settings across the undivided IDE.

Stick out a run configuration bring about the packaged application

To run neat Java application packaged strengthen a JAR, IntelliJ IDEA allows you to create clean up dedicated run configuration.

  1. Dictate , find and lope the Edit Configurations dial.

  2. In the Run/Debug Configurations dialog, click and calculate JAR Application.

  3. Name honourableness new configuration: .

  4. Behave the Path to Receptacle field, click and propose the path to dignity JAR file on your computer.

  5. Scroll down character dialog and under Hitherto launch, click , single out .

    Exposure this means that high-mindedness HelloWorld.jar is built mechanically every time you accomplish this run configuration.

Enquiry configurations allow you guard define how you demand to run your urge, with which arguments present-day options. You can have to one`s name multiple run configurations answer the same application, prattle with its own settings.

Execute picture run configuration

  • On high-mindedness toolbar, select the design and click to significance right of the hit configuration selector. Alternatively, fathom if you prefer shortcuts.

    As earlier, the Run tool tumbler opens and shows command the application output.

Illustriousness process has exited with flying colours, which means that say publicly application is packaged precisely.

Last modified: 11 October 2024

Uninstall IntelliJ IDEALearn Separate features