Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

java compiler

Bart1972Bart1972 Member Posts: 3
Hi, I just started with Java. I got this book 'SAMS Teach Yourself' and got started. I downloaded and installed Java Development Kit but then I got stuck.
I don't see where I can compile my programs. They speak of a 'command line', but where can I find that? Is the compiler a little program of its own?
Can someone mail me how compiling Java is done?
Thanks!

Bart Baplu from Antwerp in Belgium
bartbaplu@wanadoo.be

Comments

  • kreitlerkreitler Member Posts: 218
    Hi Bart,
    If you're using a Windows, you can get to the command line via a DOS box (on '98 and Millenium) or by launching a "command window" (go to the 'start' menu, choose the 'run' option, and type in 'command' (with no quotes)).
    If you're on a Unix machine, you'll need to open a terminal window.
    In either case, you will need to make sure that the directory containing the compiler is in your path (this should automatically happen when you install Java, but sometimes it doesn't...).
    This is all sort of complicated if you're not completely comfortable with your operating system. Instead of compiling programs via the command line, I would try using a simple Integrated Development Environment (which provides GUIs for both editing and compiling your code). BlueJ is an excellent choice for beginniners.
    This site:

    www.sleepinggiantsoftware.com/FGJ

    has tutorials that will help you install Java and BlueJ and get started compiling programs with them (as well as stepping you through writing your own game).
    Good luck!

    Kreitler


    : Hi, I just started with Java. I got this book 'SAMS Teach Yourself' and got started. I downloaded and installed Java Development Kit but then I got stuck.
    : I don't see where I can compile my programs. They speak of a 'command line', but where can I find that? Is the compiler a little program of its own?
    : Can someone mail me how compiling Java is done?
    : Thanks!
    :
    : Bart Baplu from Antwerp in Belgium
    : bartbaplu@wanadoo.be
    :

  • Bart1972Bart1972 Member Posts: 3
    [b][red]This message was edited by Bart1972 at 2003-6-5 9:24:19[/red][/b][hr]
    Hi thanks for the fast reply.
    The problem isn't solved though. I tried it on a windows XP and when I tried to compile , it sais : 'Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/Main'
    and it doesn't compile.
    What I find so strange is that after I installed this development kit, I don't find any trace of it in my start menu. I hoped that DK was some sort of programme that helped you to programme and compile more easily ...


    I still have to try that 'bluej', so there is still hope.

    Bart


  • kreitlerkreitler Member Posts: 218
    Hey Bart,
    Good news--the error message you received means that successfully launched the compiler. However, you may not have had the correct arguments when you did (either that, or the code you're trying to compile isn't quite right).
    If you try BlueJ, you might get better error diagnostics (not to mention having a friendlier environment for compiling your programs). Also, if you post the command you used to compile, someone may be able to figure out your problem.
    Finally, it does seem strange that you can't find the JDK on your machine. I installed Java on my XP box and the JDK is visible from the C: drive as: c:j2sdk1.4.1.
    You may want to launch your "Add/Remove Programs" control panel and make sure that the Java 2 SDK shows up on the list of installed software.

    Good luck,

    Kreitler


    : [b][red]This message was edited by Bart1972 at 2003-6-5 9:24:19[/red][/b][hr]
    : Hi thanks for the fast reply.
    : The problem isn't solved though. I tried it on a windows XP and when I tried to compile , it sais : 'Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/Main'
    : and it doesn't compile.
    : What I find so strange is that after I installed this development kit, I don't find any trace of it in my start menu. I hoped that DK was some sort of programme that helped you to programme and compile more easily ...
    :
    :
    : I still have to try that 'bluej', so there is still hope.
    :
    : Bart
    :
    :
    :

  • Bart1972Bart1972 Member Posts: 3
    SUCCES!! BlueJ works! I compiled and interpreted and the little programm from the manual worked! Now it's a matter of training with JAVA itself but that is only a matter of time.

    I have one more question and then I'll leave you alone. This seems to work in a DOS-like environment (the "Windowssystem32command.com"-window), but what do I have to do when I want to run it in Windows itself, without having to go passed that command line first. I would like to write the programms, compile it and only have to dubbleclick it in Windows XP to make it run.
    How do I do that?

    Thanks again,
    Bart
  • kreitlerkreitler Member Posts: 218
    Hey Bart,
    Congrats! Glad to hear that you're up and running.
    As to your new question, there are two issues at work. First, how do you make programs run within windows instead of in a DOS-like environment. Second, how to make programs launch when you double click them.
    So, how do you make the programs run inside of windows instead of a DOS box? You need to write your programs using a Frame or JFrame class, or an Applet (which will execute within a web game) if you want to see them inside of windows. Otherwise, they automatically run from the command prompt, and there's nothing you can do about that. For more info on using JFrames, you can look at tutorial #2 at the "Free Gamer's Journal" site, or just look up "JFrame" in your SAM's book.
    As for being able to "double click" the program and have it just work...there are two ways, and each one is sort of nasty. First off, you can make an executable JAR file. The JAR utility comes with the SDK, and runs from the command prompt. It's a compression utility (like WinZip), into which you can compress an extra file (called a 'manifest') which tells your OS which class to launch when someone double clicks the JAR. In other words, you would compress your class files and a manifest into a JAR, and then, when someone launched the JAR, the manifest would point to the class to execute.
    Unfortunately, this method can fail on machines where people have configured special utilities to open JAR files. In particular, lots of people use WinZip to read JARs, so when you double click on the JAR, it launches WinZip instead of running the program.
    As long as you don't condfigure some other program to open JARs, this solution should work for you. If you want more details and you can't find them in your book, let me know.
    Second, you can write a small batch file to launch your program for you. If you run the program from the command prompt, all you have to do is write a small batch file that contains the same command and leave that file in the directory with your classes. Then you can double-click the batch file to launch your program.
    Finally, you can run your program directly from BlueJ. Just right-click on the tan box that contains your main class file. A pop-up menu will appear. Select the 'void main(args)' option to run your program.
    Good luck--post again if you have problems.

    Kreitler


    : SUCCES!! BlueJ works! I compiled and interpreted and the little programm from the manual worked! Now it's a matter of training with JAVA itself but that is only a matter of time.
    :
    : I have one more question and then I'll leave you alone. This seems to work in a DOS-like environment (the "Windowssystem32command.com"-window), but what do I have to do when I want to run it in Windows itself, without having to go passed that command line first. I would like to write the programms, compile it and only have to dubbleclick it in Windows XP to make it run.
    : How do I do that?
    :
    : Thanks again,
    : Bart
    :

Sign In or Register to comment.