Question:

How do I run a compiled Java file?

by  |  earlier

0 LIKES UnLike

I compiled my java file and it gave me some other files, but how do I run it as a program?

 Tags:

   Report

2 ANSWERS


  1. Several ways:

    1.  Run from the CMD line:

    java <your main classfile name>

    If you compiled from the command line, it is almost exacly the same steps ( except when compiling you add the .java ):

    javac <your main classfile name>.java

    2.  I generate executable jar files for easier deployment.  Do a search on Sun's web site on executable jar files.  It's kinda weird the first time you do it.  After you figure it out it's easy peasy.

    3.  Most of us use GUI development environments to compile and run java files.  An excellent one ( and free ) was developed by Sun:  netbeans

    Good luck.  


  2. if your main class file is called MainClassfile.java (compiled as .class)

    in your command prompt/terminal browse to the directory it is in and type

    java MainClassfile

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.