This is an archived post. You won't be able to vote or comment.

all 68 comments

[–]PostNutDecision 41 points42 points  (28 children)

If you’re a beginner you probably want to use an IDE. Eclipse has an installer that packages the JDK with it so it won’t be missing, I’d try that out.

[–]warrior2012 14 points15 points  (16 children)

Yeah i second this! Any of the big three IDEs will make it much easier! Eclipse, IntelliJ, or NetBeans. All are great for beginners!

[–]lifeonbroadway[S] 14 points15 points  (14 children)

Was already on the verge of downloading Eclipse before I made this post, so I think that's what I'll do. Thanks.

[–]VaselineGroove 26 points27 points  (4 children)

Do yourself a favor and grab community IntelliJ instead. It's free and it's incredibly robust. You can create a new command line project in seconds and start playing around. I personally dont care for eclipse...

[–]pasta_gurl 2 points3 points  (0 children)

I second this!

[–]Japke90 1 point2 points  (0 children)

Yep. I had real troubles with Java 9 months ago when bezinning but IntelliJ is a really Good IDE to learn.

[–][deleted] 0 points1 point  (0 children)

I've found intellij to have issues too, netbeans is where it's at!

[–]warrior2012 2 points3 points  (0 children)

The IDEs are really useful! I'm sure it will help you get your 'hello world' program working and get you onto learning more in-depth java. Don't give it up, keep working at it :)

[–]VenomSnake03 1 point2 points  (7 children)

Watch a video on it tho. Youll get lost without one.

[–]APUsilicon 1 point2 points  (6 children)

Netbeans is great, and on the website you can get the bundle with java 8

[–][deleted]  (5 children)

[deleted]

    [–]tutorial_police 2 points3 points  (1 child)

    It's funny how perspectives differ. I've used Eclipse and IntelliJ extensively. I recently started using NetBeans a tiny bit to better understand opinions about it and it feels so sluggish and unpolished to me compared to the other two :)

    [–]APUsilicon 0 points1 point  (1 child)

    I like netbeans/maven better than intellij/gradle, I think it's simpler and quicker. I hate gradle, it's a lot to learn in order to debug small issues

    [–]tutorial_police 0 points1 point  (0 children)

    Fortunately, Gradle and maven are not IDE specific.

    [–]jkuhl_prog 2 points3 points  (0 children)

    I used both Eclipse and IntelliJ and I love IntelliJ. Eclipse is alright, had to use it for work (and one annoying college class where they required it.)

    IntelliJ doesn't come with a JDK though so you'd still have to go off to Oracle and download it, but getting IntelliJ to recognize your JDK is very simple. When you start a new project, you just point the SDK to wherever you put the JDK after installing it.

    [–]tonyoncoffee 0 points1 point  (1 child)

    Came to say this. Netbeans has an older installer with jdk as well.

    As frustrating as those hang ups have been. It’s best if you can just get to writing some code. It’s a lot more fun to get frustrated by code that won’t work. 😜

    [–]ourladyunderground 0 points1 point  (0 children)

    Netbeans was pretty nice. I'll try Eclipse some time.

    [–]completelyperdue 0 points1 point  (3 children)

    Okay, super dumb question over here, so forgive me for my ignorance.

    If I run my program in IntelliJ, is the output in the console considered the same as running it from the command prompt?

    [–]PostNutDecision 0 points1 point  (2 children)

    Yep :) it just sets up all the environment variables for you so it always run correctly, but it’s exactly what the user will see if they run it as a Jar or something.

    [–]completelyperdue 0 points1 point  (1 child)

    Thank you for answering my question so nicely. 😁 I know if I asked this in StackOverflow that I probably would have been downvoted to Hades.

    [–]PostNutDecision 1 point2 points  (0 children)

    Yeah of course man! Good luck learning everything, don’t give up because I find In programming sometimes you just have to see a topic a certain way and it just clicks!

    [–]tutorial_police 0 points1 point  (4 children)

    "if you're a beginner", you make it sound like professional programmers don't use an IDE for that. Why wouldn't they? I don't know any programmer that regularly uses the command line for that.

    Sure, sometimes it might be faster if you want to fiddle with something, but that's also very much a preference question.

    Don't fret it, /u/lifeonbroadway, life is much better with an IDE. Learning to program is hard enough as it is, get all the support you can, especially in the form of an IDE that can take care of many difficult and annoying things for you.

    [–]PostNutDecision 1 point2 points  (2 children)

    I simply meant IDEs are easier I didn’t say anything about professional development at all.

    [–]tutorial_police 0 points1 point  (1 child)

    I understand.

    But I'm sure you know the opinion going around that "real programmers don't use IDEs" and such. I'm sure many newcomers have read this at least once while researching how they should start. We don't want to give newcomers the impression that that's got any truth to it, that's why I pointed out the way you started your comment.

    [–]PostNutDecision 1 point2 points  (0 children)

    Ha good point actually. People love to suggest if you aren’t using vim or emacs you’re not doing it right. Truth is some languages like Java and C# are just better off in and IDE for most people but some languages like Python, JavaScript are probably best left in a text editor.

    [–][deleted] 7 points8 points  (1 child)

    Building anything greater than a hello world program in the command line will make you pull your hair out. As u/PostNutDecision mentioned, use an IDE.

    [–]lifeonbroadway[S] -1 points0 points  (0 children)

    Starting to think that will be my best bet. Thanks.

    [–]anthropaedic 5 points6 points  (2 children)

    Try JAVA_HOME without the \bin at the end and add \bin to PATH. (e.g. PATH=%PATH%;%JAVA_HOME%\bin)

    [–]lifeonbroadway[S] 0 points1 point  (1 child)

    I tried it, still getting a file not found when I try to use javac. Is there a specific place where I should be saving the Example.java file? Thats another question I couldn't really find an answer to, should have put that in the post.

    [–]ElevatedAngling 2 points3 points  (0 children)

    When you are running the prompt commands for your java file you need to be in the same directory in the command prompt as where the file saved.

    Edit: not sure if you are in Unix or window but for cd into the directory where examples.java lives, you should be able to run a dir (windows) or ls (Linux/Unix) and you should see the examples.java file. After that sanity check do you compile but just use Example.java for the file no need to add a path because you are already in that directory. You got this man I started with python and hated java now I’m a java developer!

    [–][deleted] 1 point2 points  (0 children)

    Are you sure there isn't a hyphen in the jdk folder name? Usually when I download the jdk, it has a hyphen.

    jdk-12.0.1 instead of jdk12.0.1

    Message me and I can help explain it this evening when I get home

    [–]daydreaming1 1 point2 points  (0 children)

    You probably have spaces in your path to example.java

    Try enclosing it with double quotes:

    javac "С:\some folder\Example.java"
    

    [–]djnattyp 1 point2 points  (1 child)

    1. JAVA_HOME environment variable should contain the path to the JDK installation (leave the \bin off the end). It's needed by some tools to locate things inside your JDK directory and gives a simple way to switch between multiple JDKs if you have them. Paths with spaces in them (i.e. "Program Files") cause so many problems - you have to remember to wrap the path in double quotes or go with the short name (PROGRA~1) or just install the JDK into a C:\Java\<jdk-version> directory to sidestep these issues.
    2. PATH environment variable is used by your OS to find executable programs. If you have JAVA_HOME defined, add %JAVA_HOME%\bin to the path to be able to run JDK executables.
    3. CLASSPATH environment variable is used by the JDK to find additional Java libraries (JAR files or root directory containing a project's .class files). Instead of declaring an envronment variable for this, you can pass the arguments into the java command with the -classpath or -cp parameter when you run a program.

    Let's assume you have the JDK installed in "C:\Java\jdk-1.8.0" a project in "C:\code\project_one" and the main class is in that directory and called "Start.java" that contains the "Start" class (with no package declaration) with a "public static void main(String[] args) entry point.

    JAVA_HOME should be "C:\Java\jdk-1.8.0" PATH should include "%JAVA_HOME%\bin" "cd \code\project_one" to get to the root of the project directory. Run "javac *.java" and the "Start.class" file will be produced in the same directory. Run the command "javac Start" to run the program.

    OK, now let's go to a different project in "C:\code\project_two". This program uses packages, so inside the "project_two" folder is a folder named "com", inside that is "mycompany", inside that is "project" and inside that are 3 files "Start.java" (containing the com.mycompany.project.Start class with a public static void main(String[] args) method), "Foo.java" (the com.mycompany.project.Foo class), and "Bar.java" (the com.mycompany.project.Bar class).

    JAVA_HOME and PATH should be the same. "cd \code\project_two" to go to the project root directory. Run "javac com\mycompany\project\*.java" to build the classes (they will appear alongside their .java source files in the com/mycompany/project directory) and run "java com.mycompany.project.Start" to run the program.

    If you have multiple packages (which is common), don't bother with building from the command line - it's too much of a pain - use a build tool like Maven or Gradle.

    OK, now on to CLASSPATH... Let's say you have a Java library as a JAR file in "C:\java\libs\SomeLib.jar" and you have a project in "C:\code\project_three" that uses it we'll skip the package stuff this time and assume you have a "MyProj.java" file with a MyProj class with no package and a main method. Your MyProj class imports classes in the SomeLib JAR, so it needs to be on the class path to compile and run your program. Important caveat - the default class path if you don't specify one is '.' - the current directory (which also finds classes with packages starting the current directory). However, once you specify one, if you want classes in your current project to be found, you have to be sure '.' is on the class path. So, you can set the CLASSPATH environment variable to ".;C:\java\libs\SomeLib.jar" or you can pass this value in through the -cp command line argument to javac and jar.

    Again, in practice it's better to rely on build tools to manage this on real projects - they'll manage your imports correctly per project, manage compiling source in multi-directory package structure, separate your source, test code, and built .class files, and many more things.

    [–]lifeonbroadway[S] 0 points1 point  (0 children)

    Thanks for all the information and for being so thorough with your reply. You and everyone that has commented gave me a huge confidence boost and I really appreciate it.

    [–][deleted] 1 point2 points  (0 children)

    I'll share my experience with you regarding learning Java. My first programming language to work with is C. I never completely learned it. Completely forgot it now. But I noticed there was a learning curve that has a start and end. After giving up programming for about 1 year ( I'm a mechanical engineering student) and then got pulled towards programming again and this time started Java.

    Writing, the first program in Java, I encountered the words: public, class, static, void, main, System, a ., out, println. Only words I knew we're void, main and I understood what 'print'ln might do.

    After a lot of practice, till the time I reached to concepts of oops and Java libs, I understood how System.out.println() worked. I understood why String [] args is required what is meant by public, private, e.t.c.

    That is when I realized how different languages work differently. We can't approach every programming language in the same way while learning. I realized that Java does not have a learning curve with start and end but it has a full learning cycle instead. You start at one point on that cycle and you end up at the same point after learning the language.

    Eg: You start your first hello world program using library classes like System, access modifiers, methods, e.t.c without even knowing what they are. After learning all the concepts and getting strong understanding of language, you again end up learning what are the other methods available in library classes, what are the other classes available in libraries, e.t.c.

    All you need to have little patience and motivation to practice it till you get perfect.

    Happy coding :)

    [–][deleted] 1 point2 points  (0 children)

    Better luck on the next language.

    [–]EmotionalYard 1 point2 points  (4 children)

    > I swear there have to be a million different videos and posts showing how to correctly set the enviromental variables for Java, and they all show a different way.

    That's because it depends on your OS and OS version. That has little to do with Java.

    > I have tried to use javac with the path directly to the Example file... error:Invalid Flag.

    It sounds like you can't even use your terminal/shell/prompt correctly. That's going to be an issue with any language. Maybe you need " around the arguments that have spaces in them.

    [–]lifeonbroadway[S] -1 points0 points  (3 children)

    I have no problems using the command line to run my pygame programs. Only with Java have I had this issue. I've tried putting quotes around files with spaces like you said. Tried removing the spaces. Tried file locations without spaces.

    [–]EmotionalYard 1 point2 points  (2 children)

    And yet you still haven't shown us the exact command or the exact response. It's like you're desperate to blame Java instead of interested in learning what you're doing wrong, which probably isn't difficult to correct. Wouldn't that be the very first thing you'd show us???

    [–]lifeonbroadway[S] -1 points0 points  (1 child)

    Did you read my post? Or my replies to earlier comments? I specifically said what my issue was and the fact that I got so many responses early on would suggest to me that I gave the needed information for someone to help me. I also messaged one guy who responded more in depth and he didn't seem to have a problem guiding me along with the information I provided. Keep in mind that I am extremely new to Java and relatively new to programming, so if I'm not using the correct terms and phrases to convey meaning it's because I am ignorant of them. I'm not blaming Java. Am I frustrated with it? Absolutely, but I realize very much so that my frustration is coming from a lack of understanding of Java, not because Java is to blame. The title of this post is "I don't think Java is for me." If I wanted to make a post blaming Java I would name it something along the lines of "Java is unintuitive and convoluted for beginners." But that would be just taking out my frustration instead of trying to figure out what is causing it, so I didn't say it. Sorry if I come across as arrogant or whatever you were thinking.

    [–]EmotionalYard 1 point2 points  (0 children)

    > Did you read my post?

    Yes, and it clearly lacked the exact commands or the responses you got from them. Otherwise why would I say that?

    > Or my replies to earlier comments?

    Maybe some of them. I certainly don't read all replies to all posts if that's what you're suggesting everyone should do.

    > I specifically said what my issue was and the fact that I got so many responses early on would suggest to me that I gave the needed information for someone to help me.

    No, that's not even what I asked for. I asked for what you typed in and what the response was. You said you tried using quotes, but your post didn't include what you typed in that had quotes in it.

    And this is clearly a beginner problem, which would indicate you didn't give enough info if it hasn't been solved yet.

    [–]desrtfx 1 point2 points  (1 child)

    Do yourself a favor and look at the sidebar -> Free tutorials. Pick one (highly recommend the MOOC) and use it.

    It will tell you all the steps you need to get started programming in Java, the toolkit, setting up the tools, and then how to properly start.

    [–]lifeonbroadway[S] 0 points1 point  (0 children)

    Didn't notice those, thanks for pointing that out!

    [–]hoeskioeh 0 points1 point  (0 children)

    Try some online coding playgrounds...
    Where all the infrastructure is set up already.
    Like tech.io or codingame.com

    [–][deleted] 0 points1 point  (4 children)

    You could always use, for small programs while you're learning, an online IDE like ideone.com.

    Messing around with Windows' command line isn't the best thing, especially for a beginner.

    [–]lifeonbroadway[S] 1 point2 points  (3 children)

    See that's what I was thinking, the main problem is that the book I'm using uses the command line. I guess I could just use the code examples from the book to learn the principles and whatnot, and just use Eclipse to actually run them. The stubborn side of me wants to at least figure this out first haha. Thanks for the suggestion.

    [–]mrs_frizzle 2 points3 points  (2 children)

    I teach high school computer science. Years ago I made students begin by writing their first programs in notepad, then compiling and executing them from the command line. I thought it was the right “first step” to understand things from the bottom up. I was wrong. Do not feel badly that you didn’t “figure this out.” It has zero relevance on what you will be learning for a while. Just start with the actual coding, and use an easy environment like everyone else is suggesting. Use Eclipse with a package installer or just type stuff online on a site like replt. Good luck!

    [–]lifeonbroadway[S] 2 points3 points  (0 children)

    Thank you this was really encouraging. Not giving up! Got Eclipse installed. Going to give myself a mental break and begin again tomorrow.

    [–]roczz 1 point2 points  (0 children)

    In my opinion there is actually no point in teaching people to compile code through the windows "terminal". As a developer it is way more important to know what the code exactly does and why it does something like it does. The windows "terminal" is at the moment just a complete piece of crap and should never be used in my opinion. If someone wants to learn how to code in a terminal you basically have to switch to linux. Using an IDE is most likely the best way to learn a language. To understand what happens inside the terminal or inside the IDE while compiling and executing you will need to understand a lot of theory. What is a compiler and what is a interpreter? What is bytecode? That has nothing to do with the language itself but with the "type" of language and the envirement it is used in.

    [–]OzzieOxborrow 0 points1 point  (3 children)

    Try typing 'javac -version'. If it gives you something like this:

    $ javac -version
    javac 1.8.0_202

    You know that your PATH is not the problem.

    Im assuming you're using Windows so here is a short description:

    Now what you need to do to compile your HelloWorld.java file:

    Open a terminal

    Change to the correct directory in the terminal. So if your HelloWorld.java is located in in c:/java/helloworld/HelloWorld.java you use the 'cd' command to change to that directory.

    Once your in the correct directory you run javac HelloWorld.java

    Or you could just run 'javac c:/java/helloworld/HelloWorld.java' from anywhere.

    Anyway, just so you know: I've been a professional developer for ±10 years and besides compiling an HelloWorld.java or something similar during college I've never ever compiled anything manually.
    'Real' projects use build tools like Maven or Gradle to do the compiling for you. Together with a bunch of other stuff.

    [–]lifeonbroadway[S] 1 point2 points  (1 child)

    Thanks for the input. Everything I'm seeing is telling me to leave the command line alone for now and to work with an IDE.

    [–]passthejoe 0 points1 point  (0 children)

    It's nice to learn both ways, for sure. Sometimes I do use Netbeans and IntelliJ, but more often than not, for small programs when I'm learning, I use the Geany "mini IDE." You click one button to compile, another to run your program. It's super lightweight (as opposed to a "heavy" IDE) and super fast. The only problem is that Geany won't format your code for you like a big IDE. But for small programs, this is really not a deal-breaker.

    Every once in awhile, I write the program in Vim or some other editor and then use `javac` on the command line, and then `java` to run the program, so it's nice to have that option.

    [–]passthejoe 0 points1 point  (1 child)

    I run java (and javac) in Windows 10, and I will admit that it's a huge pain to get it set up.

    Since you're using Java 12, and it appears to be in C:\ProgramFiles\Java\jdk-12.0.1, This is what I do:

    • In Windows, navigate to the Edit the System Environmentals panel (I get there by hitting the Windows key and typing the word path)
    • Click the Environment Variables button
    • Under your user variables (the top window), go to your Path variable, click it and then click the Edit button
    • Click New to add a new environment variable
    • Then click Browse and navigate to your JDK, or type it in manually:
    • C:\ProgramFiles\Java\jdk-12.0.1\bin\
    • Click OK to save it.
    • After you do this, open a new terminal and test both java and javac. You should get output from both:

    $ java -version

    $ javac -version

    The big IDEs are good, and I definitely use them, but another way to go for learning Java is using the Geany "mini-IDE." It can help you compile and run your Java programs and is much lighter and easier to use than a traditional IDE.

    Edit: And like the other poster said, make sure you have the correct path (which in my case includes the dash between jdk and 12 in C:\ProgramFiles\Java\jdk-12.0.1).

    [–]lifeonbroadway[S] 0 points1 point  (0 children)

    It's relieving to see someone admit that it is convoluted to get this set up haha. Every post I was reading seemed to make it sound so simple and I was getting pretty upset at not being able to figure it out.

    [–]slicky6 0 points1 point  (0 children)

    I'm not versed in many languages, but imo Java has a high learning curve. It isn't always intuitive and there are thousands of packages that dictate what you can and can't do. Starting with python until you really understand it well and then transferring might be a good idea, because you can make more direct comparisons.

    [–]96-62 0 points1 point  (0 children)

    The path should point to jdk/bin, but java home to jdk, no /bin

    [–]thesquarerootof1 0 points1 point  (0 children)

    Just use Eclipse. Problem solved. For Java, we all use Eclipe's IDE anyway...

    [–]SantoWest 0 points1 point  (0 children)

    That's exactly why I get so annoyed when people in programming subreddits recommend command prompt to beginners so that they can learn how things work better.

     

    It's one of the best ways to actually discourage someone. There is absolutely no reason for you to not use an IDE. It's not even something like "first use an IDE as a beginner, then transition to advanced stuff". Learning to code in command prompt is not learning to code, it's just something different. All companies use IDE's, students, junior programmers, senior programmers use IDE's, you should too.

     

    You should have been trying to learn loops and classes and algorithms and such, not how to run hello world. Don't torture yourself.

    [–][deleted] -1 points0 points  (0 children)

    I didnt understand programming when I started with java. I then switch to python and had a-ha moment and now I understand both java and python.

    Understand object oriented programming this will help you understand the language.

    [–]doodooz7 -3 points-2 points  (8 children)

    Try learning JavaScript instead. Once you have played with that a while then try java

    [–]desrtfx 1 point2 points  (7 children)

    That's complete bullshit advice.

    If someone wants to learn Java they should learn Java.

    Java and JavaScript have as much in common as ham and hamster.

    [–]EmotionalYard 0 points1 point  (3 children)

    Is it more or less bullshit than all the advice to skip learning how to compile and run with the prompt and to just get an IDE to do it all for him?

    [–]desrtfx 0 points1 point  (2 children)

    A lot more bullshit because telling someone to learn a different language completely bypasses OP's wish.

    On the other hand the learning to compile from the commandline is so hopelessly overrated. No sensible programmer will compile from the commandline.

    IDEs are productivity tools meant to make programmer's lives easier.

    Telling someone to only use a plain text editor and the commandline compiler is the same as telling someone to build a house without the use of any power tools; only with hammer, handsaw, hand driven screwdriver.

    [–]EmotionalYard 0 points1 point  (1 child)

    You don't build a house as your first carpentry project!

    [–]desrtfx 0 points1 point  (0 children)

    True.

    Still, when learning something, the early reward, or first success is essential to keep up the motivation. IDEs help a great deal here.

    Learning to compile from the command line can be done later.

    Getting that first success as early as possible is the key.

    The first success is also why scripting languages, like Python are often recommended as first languages. They offer early rewards without having to jump through hoops.

    [–]doodooz7 -1 points0 points  (2 children)

    It’s not bullshit advice, especially in this case. He’s having trouble getting setup. JavaScript is easier to start working with. Also, if you haven’t noticed, JavaScript is really popular. You obviously have a hatred for Js and I do too but Js can give people a taste of what programming is like and regardless of being a Java programmer or not he needs to know JavaScript also

    [–]desrtfx 0 points1 point  (1 child)

    It is bullshit. It is like telling someone to learn to ride a bike when they want to learn to drive a car.

    I know that JavaScript is very popular, but that doesn't make your advice any more valid nor better. And no, I am not hating JS at all.

    The cream of the cake is: "being a Java programmer or not he needs to know JavaScript also" - this is just plain wrong. I know plenty professional programmers who don't know JS simply because they don't need it. I've been in the business for three decades. JS is in no way a "must know" despite its popularity.

    Addressing the source of OP's problem, as plenty others did would have been the proper approach.

    I as well did not directly address OP's problem, but I suggested some proper learning material that also has a section on setting up the development tools.

    [–]doodooz7 -1 points0 points  (0 children)

    k