Web Analytics Made Easy -
StatCounter How do I make a Java program? - CodingForum

Announcement

Collapse
No announcement yet.

How do I make a Java program?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I make a Java program?

    I've been interested in teaching myself Java for awhile now. My only experience is with C++ and Javascript. I've seen some of the Java code people have posted and noticed it's very similar to C++. I suppose my question is what do I need to be able to start writing little Java programs? I use cygwin for all of my C++ stuff. The way I do it is I write my code with a text editor, usually notepad2, save it in my projects directory, go to that directory with cygwin, and g++ -o program program.cpp and then ./program.exe.

    Can I use cygwin to compile Java programs in the same manner?

  • #2
    Not sure about using "cygwin" but there are many useful IDE's (Integrated development environments) that are available at your disposal...

    Many are open source and free, and very useful. I started with EditPlus2 then moved to Eclipse, now I am using NetBeans 5.0.

    here are a few links to some of the popular IDEs:

    www.eclipse.org/
    www.netbeans.org/
    www.jcreator.com/
    www.borland.com/jbuilder/

    With the tools above you can organize your project in directories, as well as compile and run projects directly through the IDE.

    Yak

    Comment


    • #3
      Don't forget the Java Development Kit: http://java.sun.com/javase/downloads/index.jsp

      I'd probably go with the JDK 5.0 Update 9 with NetBeans 5.0 download.

      Comment


      • #4
        Originally posted by Gox View Post
        Don't forget the Java Development Kit: http://java.sun.com/javase/downloads/index.jsp

        I'd probably go with the JDK 5.0 Update 9 with NetBeans 5.0 download.
        With Eclipse the JDK comes standard.

        You can continue to use cgyin if you want and continue to code through notepad2 as well. An IDE just makes life easier because it points out syntax mistakes as well as errorness code writing.

        If you want to go for an IDE I suggest Eclipse.

        If you want to continue your cgwin environment then I suggest you download the JDK (without netbeans since we aren't using an IDE). Set the path needed to the bin folder after the download is finished.

        Once you do that you can compile and run code.

        Compiling code is with the javac.exe file which goes as such:

        Code:
        C:\> javac.exe program.java
        And then to run it after you compile it:

        Code:
        C:\> java program
        Note that you don't need to include the .java when you run it. Also, there is no real executable this way, if you want to do that you have to create a jar file, but I would wait to do that until you've grasped how to code in java and what java really is.

        Hope that helps!

        -Aradon
        Last edited by Aradon; Oct 12, 2006, 03:06 AM. Reason: Because I'm cool like that
        "To iterate is human, to recurse divine." -L. Peter Deutsch

        Comment


        • #5
          All you need is JDK which was linked to above.

          Here's a hello world example:

          Code:
          public class HelloWorld
          {
            public static void main( String[] cmdArgs )
            {
              System.out.println( "Hello, world!" );
            }
          }
          You would save that as HelloWorld.java
          Then do javac HelloWorld.java
          followed by
          java HelloWorld

          Syntax is a lot like C++. No pointers, though, and there are lots and lots of useful libraries.

          Comment


          • #6
            All you have to have is the JDK and then choose what you want to write in.

            When I started Java, my class used BlueJ as an IDE(unpopular but i liked it). It is relatively small and of course its free.

            I would reccommend getting yourself a textbook from amazon.com, or just googling for java tutorials. If you have done C++ you will probably take to java fairly quickly.

            Here are a few tutorials:
            http://math.hws.edu/javanotes/
            http://echoecho.com/applets.htm
            http://www.vtc.com/products/java-introduction.htm

            Have fun

            Comment


            • #7
              Thanks everyone for all of the help. I copied the HelloWorld class and pasted it into my text editor. Then I saved it as HelloWorld.java, compiled like this:
              gjc -o HelloWorld HelloWorld.java

              I'm trying to do it with cygwin first, but if I find that to be impossible, I'm going to try one of the IDE's. I'd just like to keep things simple because I'm using a Windows laptop for most of my projects and have found cygwin (a unix emulator) is most like compiling things with the terminal on my linux box at home.

              I keep getting an error which says 'undefined reference to '[email protected]''. Anybody know what this means and how I can fix it?

              Comment


              • #8
                First of all, why use gcj over javac (which is made by Sun)?

                As to your compile error, if it were a c/c++ file I would learn towards an error in the compiler thinking it was a "window" program rather than a console program. That's only a hunch however.

                Comment


                • #9
                  Originally posted by Gox View Post
                  First of all, why use gcj over javac (which is made by Sun)?

                  As to your compile error, if it were a c/c++ file I would learn towards an error in the compiler thinking it was a "window" program rather than a console program. That's only a hunch however.
                  I don't know how to add javac to cygwin. Whenever I type man javac into the terminal, it says javac isn't there. Do you know how to add it?

                  Comment


                  • #10
                    As stated previously, you need to make sure that javac is in your path. Also, javac doesn't come with a man file.

                    I'm unsure how cgywin is set up so I can't advise you on that affair, have you tried going through windows cmd ?
                    "To iterate is human, to recurse divine." -L. Peter Deutsch

                    Comment

                    Working...
                    X