'Why is IntelliJ not recognising stuff as I type? BlueJ is easily recognising the same code?

I'm an absolute beginner. I learnt a bit of Java in my highschool and we were using BlueJ back then.

I wanted to brush up so I started with the simplest code:

public class HelloWorld
{
 public static void main (String[] args) 
{
System.out.println ("Hello World");
} 
}

But now I'm using intelliJ and it didn't recognise the code and as a result isn't showing the run button on the left of my editor window margin. I saw the tutorials online and the instructor typed the exact same code and had green buttons at the left the code to run the Java file but I'm just not able to find that. Moreover if I try running it anyway using the main options bar, it doesn't do anything!

I tried this in BlueJ and it easily ran. So I'm confused now. BlueJ would recognise as I typed and changed the colors of the text but intelliJ isn't changing the color of the text which means it isn't really recognising that code? Can someone please explain?



Solution 1:[1]

I found out my mistake. Apparently, creating a new class by right clicking on the option named 'src' (which is located under the project name solves the problem. Until now I wasn't really right clicking on 'src' I would just arbitrarily right click anywhere and never really noticed. I thought it'd create my Java class automatically wherever necessary but apparently that doesn't happen. It creates my class exactly where I ask to. I guess creating it outside the 'src' file/option doesn't allow for the recognition.

Solution 2:[2]

For Intellij a custom theme plugin can change the color of the text to help with recognizing variables, methods and so, but for code completion make sure that you hit ctrl + space to ask intellij for suggested code completion.

Also it looks that your code is setup wrong, give this a try:

class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!"); 
    }
}

Solution 3:[3]

You do not need to click on the green play button. There is a shortcut to run the class you are working, it is just as simple as do ALT+Shift+F10, and your code will run inmediatly. If you find difficult to remember shortcuts, if you look at the top bar, you can see the Run tab. You will find the Run button, which does the same as the shortcut.

Hope this helps.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dexter
Solution 2 Dalton LB
Solution 3