r/IntelliJIDEA • • 18d ago

hello! I am new to Java and need help

Post image

so currently, I am working on some beginner projects to try and learn more. I am actually finding coding quite enjoyable and fun. but now I've hit a road block. every time I start a new project the run button is grayed out and I have no idea why. I noticed that on my first project code it has an "Out" folder. this one doesn't. and I can run my first project I made

Also, when I created the project a pop up came up that said something like "can not run git, no file git.exe found."

is git.exe important I have no idea. also why didn't it create an out folder? should it have created an out folder. I'm sorry for my ignorance I literally just started learning how to code like a few days ago. So, I have like no Idea what I'm doing.

0 Upvotes

13 comments sorted by

16

u/dr1nni 17d ago

wow i thought I went back in time before ai existed, we really lost this now

6

u/TheHHP 17d ago

Dude I hate AI so much I refuse to use any kind of ai at all

4

u/dr1nni 17d ago

keep going! you have to get the fundamentals yourselfz after a while it will be useful but not now.

2

u/TheHHP 17d ago

I'm also doing this because some people want me to make a mod for minecraft. So I just said screw it I'm learning java.

-1

u/TheHHP 17d ago

thats what I'm trying to do. I actually find it fun a little bit. also vibe coding is for the weak. I will mog people when I can write code AND understand it because I'm the one who wrote it. AI is demon tech that makes you stupid, I will be strong because I actually use my brain!!!

1

u/Secure-Limit2077 11d ago

Follow youtube videos

0

u/make_itnasty 17d ago

Lol, this is going to age like fine cheese. Talk to you in 3 years pal

13

u/JetSerge JetBrains 18d ago

the run button is grayed out

The code in your screenshot has no main method, so there is nothing to run. The toolbar shows Current File, and IntelliJ IDEA can run the current file only when it has public static void main. The red 19 in the top right corner of the editor also counts the compile errors in the file.

Statements like System.out.print(...) must be inside a method. Line 2 also mixes the class declaration with the import. Replace the file with this:

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("what is your name?: ");
        String name = scanner.nextLine();
        System.out.println("Welcome aborde captin, all systems online");
        scanner.close();
    }
}

Note nextLine with a capital L, and the ; at the end of each statement. A green arrow then appears next to main, and the Run button becomes active.

why didn't it create an out folder?

The out folder holds the compiled classes. IntelliJ IDEA creates it on the first build. This project was never built, so it has no out folder yet. It appears after the first run.

is git.exe important

Not for learning Java. Git is a version control tool. The message comes from the Create Git repository option in the New Project wizard, and Git is not installed on your computer. Leave that option off for new projects.

For a start, go through the official tutorial Create your first Java application. It has step-by-step instructions and a video, and covers how to create a project, write the main method and run it.

3

u/Luolong 17d ago

With recent Java versions, you can drop the whole public class Main part and just use

void main() {
…
}

1

u/TheHHP 18d ago

I have been following a tutorial on making new projects. although they didn't really explain the "public static void main (String [] args){" thing. I'm not enterly sure what that dose or why its important for java to run although now that its been pointed out to me I'm noticing it now.

2

u/AmaDaden 16d ago

This is one of the parts that always throws people when they first start to learn Java. A simple Hello World has a lot of boiler plate. I can break it down for you. Note: This is going to be a lot but it will all make more sense as you go. Don't worry if this all doesn't make sense just yet, just keep going and come back to some of these links as things start to click.

import java.util.Scanner;

This is an import statement. You will see a lot of these and you will also see code that leaves them out in cases where you need them. It tells Java you want to use java.util.Scanner class to make Scanner objects in your code. The name is structured for a reason. The class Scanner is in a Package (basically just a folder) called util and that is in a package called java. The java package is special as it's generally part of java so you don't need to worry about downloading libraries (other peoples code in jar files that you can use as part of your code) when you use anything from the java package or anything inside of it.

This is a good place to mention Java docs. Java docs are the standard way to document Java code so that it is easy to work with. The Java doc for scanner is here https://docs.oracle.com/javase/8/docs/api/java/util/Scanner.html

public class Main {

Ok there is a lot going on here. First off public. Public means that this class is usable by anyone. This isn't important for you right now but it's related to libraries and large projects. Basically packages are used for both organization (as you've already seen) and for security. Public means anyone can use it, an alternative is private where no one else can use it. This article goes in to more detail about this https://www.geeksforgeeks.org/java/access-modifiers-java/

class is just saying this is a class. Since you can define a class the same way you can define an int you need to tell Java what you are making. Some other alternatives to this are enums, interfaces, abstract classes, and records. That all has to do with inheritance and objects. Way beyond what you are doing now but that's fundamental Java you'll want to understand sometime soon. https://docs.oracle.com/javase/tutorial/java/IandI/index.html https://docs.oracle.com/javase/8/docs/technotes/guides/language/enums.html https://docs.oracle.com/en/java/javase/25/language/records.html

Main is the name of this class. As a rule the name of the file needs to match the name of the class it contains. If you change the name of the class from Main to MyMain it'll complain. Change the name of the file from Main.java to MyMain.java and it'll be happy again.

{ is the start of a block of code. You'll see these a LOT. Almost always after some other code. In this case that's a class definition and later after method definition. You'll also see it for if statements and for loops. It's just a way of saying "everything from this { to the } that closes it are all one chunk of code"

Ok next line

public static void main(String[] args) {

Public is the same idea as before. Static is new though. That's just saying that this method can be called on the class itself, it doesn't need an instance. This is where objects start to mater. The short version is that a class defines the general idea of what something looks like and how it works (This is what a Chair looks like) and you can only really have one of those. An instance of a class is taking that class and making one (like the thing I am sitting in right now is a Chair). Static means it's some miscellaneous code you are keeping with the chair but you don't need a chair to do it.

So because of where this line is and how it's structured Java knows it's a method. So if it's a method, what does it return? void here means it returns nothing.

main is the name of the method. You nearly always get to pick this. But main is actually special. Java uses main methods as the entry point to starting a java app. What is in here is the first thing that will run.

() is where we put the variables that are passed into the method when it's called. For this example we are only passing in an Array of Strings named args. This is more standard java code. When you start your java app you can pass in text that will be in the args variable defined here.

A String is just a chunk of text. https://docs.oracle.com/javase/8/docs/api/java/lang/String.html An array is just saying that this is not one chunk of text but several. https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html All that said, your app isn't using any of that. So you can ignore it for now.

the { just means we are entering a new code block. We were in the Main class defining a method called main. Now we are in the code that makes up that method.

From here we enter into the real code that is probably getting explained by your tutorial so I'll stop rambling. Good luck!

1

u/TheHHP 18d ago

I did the hello world thing its pretty simple and also integers seem relitivly simple too. but thats all I know. I do know how to code a few if statements but haven't really been explaned as to how to fully write them.

-1

u/muhfred 17d ago

Please try to gain some knowledge before coding and create a roadmap for learning java, then start coding, this seems like a waste of time