Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need a Hello World example in IntelliJ IDEA

Tags:

In Eclipse, it's easy, I just need to add a class and tick into something like Add public static void main() then run. But with IntelliJ IDEA I can't find how to create a simple "Hello World" project, the run button (Shift + F10) is always grayed out even after I added a main class in Edit Configurations. In fact, my JAVA background is not good and I am also a newbie to IntelliJ IDEA. So I am thankful to someone who show me a way to start.

Thank in advance.

p/s : I started with a Java Module project, import JDK 6.0, I didn't choose any technology. Then I created a package and a class under src\. I saw a TUT video on youtube that there even has a make main() command with right click on the class name but I can't find it anywhere. I am using IntelliJ IDEA 11 in 30 days evaluation.

like image 473
JatSing Avatar asked Dec 13 '11 18:12

JatSing


People also ask

How do you write HelloWorld in Java?

java. Compile it by typing “javac HelloWorld. java” in the terminal window. Execute (or run) it by typing “java HelloWorld” in the terminal window.

How do I start writing code in IntelliJ?

Create a package and a classIn the Project tool window, right-click the src folder, select New (or press Alt+Insert ), and then select Java Class. In the Name field, type com.example.helloworld.HelloWorld and click OK. IntelliJ IDEA creates the com.example.helloworld package and the HelloWorld class.


2 Answers

This is a transcript of how I just created a Hello World in IDEA 10.5.2 on mac. It should be exactly the same on Windows or Linux.

(you might wanna jump to step 10)

  1. On the startup screen choose Create New Project
  2. On the next Create project from scratch
  3. Give a name HelloStack and a folder /tmp/src/HelloStack
  4. Create Module is already checked and should be so. The name is predefined to the same as the project and that is fine.
  5. Just click Next and Finish on the rest of the screens. No technologies are needed.
  6. If the Project tab isn't open, open it now. It's on the left
  7. Under HelloStack there is a folder named src, it's marked in blue meaning that it is a source folder. Right click it and choose New -> Java Class. For this simple project we'll skip packages entirly. Name the class something, mine is HelloStack like the project and module.
  8. Now create a public static void main-method, there is a live template for this, just type psvm and press tab, it will expand to a complete main method.
  9. Another live template is System.out.println, just type sout and press tab. Write something.
  10. Right click inside the main method, choose Run "HelloStack.main()". This will create a runner, make the code, and run the method (class). From now on there is a runner for this and you can press the green arrow to run it.
  11. Done.
like image 200
Andreas Wederbrand Avatar answered Oct 20 '22 06:10

Andreas Wederbrand


There is a very clearly tutorial article for beginners.

http://wiki.jetbrains.net/intellij/Creating_and_running_your_first_Java_application

https://www.jetbrains.com/help/idea/2016.3/creating-running-and-packaging-your-first-java-application.html

like image 33
Bes Ley Avatar answered Oct 20 '22 04:10

Bes Ley